OpenHAB Binding for AirGradient

Thanks! I will look into that when I am back.

I used double for a lot of those because it felt safer from a parsing point of view (allowing more values). The API is only documented as “Number”. O-1PP e.g. had two particle sensors and returned the average of them, which might be a reason to keep some of these as double.

Off course, parsing as double and rounding to integer is also an option. Will have to think about it. And if anybody has a “will never ever return a decimal value” for some of those values, I am eager to learn about that!

For some reason I don’t yet understand, OpenHAB shows Airgradient humidity as, e.g., 0.42. Even though the channel is declared with min=0 max=100:

Maybe it would already help if OpenHAB would report 42.0 instead of 0.42. To be frank, I am quite confused how OpenHAB processes and presents numeric values. All I know is that for other humidity sensors, like Homematic, I needed to create an extra item that presents humidity in the 0-100 range, an not in the 0-1 range, for other consumers, like Google Assistant/Google Home, to correctly process and display it.

Yes, it would be great to get a statement from Airgradient here, if the returned values will always be integers. CC @Achim_AirGradient
I think the Airgradient firmware already does exactly that, if a value is a float, e.g., because it was calculated as the average of two sensor values, then it is still represented as integer. Which, I guess, is for most values besides temperature sensible.

BTW, looking at my OpenHAB logs, I found:

 [DEBUG] [l.handler.AirGradientLocationHandler] - Channel name tvoc is null

It looks like tvoc is not correctly wired up in the local case , as it’s either tvocIndex or tvoc_raw in the JSON.

I also see humidity displayed in different ways. In the logs the percentage is shown as “42%”, other places as 0.42, could be that some places has forgotten to convert it using the unit? Just speculating.

@Jorgen_Austvik thank you for pointing these things out. We will look into it and revert back.

@Achim_AirGradient : to be clear: the different ways to show percentage are in OpenHAB, and not AirGradients fault.

If it makes sense to specific some of the measures values as integers, that would be great, though, but if they could become decimal later it is probably better not to.

@Flow: I have uploaded a new v0.8 which uses the system type for humidity and temperature. Does it work now?

Added “boot” channel in v0.9

Better autodetection (less need to scan) and lots of improvements from reviewing for inclusion are available in v 0.10.

Thanks for the updates.

I’ve updated the bundle to 0.10. I could add the device via the local API. However, it appears that I have to add two things to get OpenHAB to show the Aigradient values. Probably because an AirGradient Location still needs an Airgradient bridge, even in the local case.

Great. I have code to add single local device running here, but it has some code duplication which I want to get rid of before I push it.

Can’t wait for 0.11 then :slight_smile:

@Flow 0.11 is out!

It has gone through a lot of reviews, so I think it is getting very close to being integrated into the official distribution (unless this last minute local device addition messes that up :slight_smile:

Next step (and the last step I can think of) is to add local configurations after beta release with a configuration endpoint is out.

Good news: the binding is accepted into the official distribution, and will be part of the next official release! It should support most basic functionality for both cloud api and local sensor users.

When the next beta firmware is out, ill add corrected/raw temperature and humidity and lots of local configuration settings.

Support for local configuration an calibrated temp/humidity in the new 3.1.1 firmware is supported in the just released 1.1 version of the OpenHAB binding.

Many thanks for updating your integration!

Thanks.

I’ve installed the AirGradient Binding version 1.1 in my OpenHAB 4.1.2 instance. It appears that the Binding is not visible under “Things” → “+” → “Choose Binding”. Not sure if this is expected. However, I could use the workaround described in

to add AirGradient things.

hello,

Thank your for your work !

I’m trying to set up a bridge to the AG API, but I get this error:

2024-08-15 16:40:21.045 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while calling thing handler factory ‘org.openhab.binding.airgradient.internal.AirGradientHandlerFactory@1e45431a’: Cannot invoke “org.openhab.core.thing.binding.ThingHandlerService.setThingHandler(org.openhab.core.thing.binding.ThingHandler)” because “this.serviceInstance” is null

I’m probaly missing a step so here what I do:

  • add the addons
  • create a thing “AirGradient API”
  • Add a location
  • add the API token from AG
  • save the thing.

I get the error immediately

Note that I successfuly checked the token with AG API swagger

thanks for your help !

Hi, @junelac!
From the description it sounds like you try to run against the cloud API and not against the sensor locally. (That is a supported mode, just clarifying in case that is not what you want.)

Which version of OpenHAB are you running? (The binding is included in the latest stable 4.2.1 version)

Did you go to Administration-Bindings and installed the one with the openHAB blue checkmark?
image, or did you install from the Add-on store? (The blue checkmark is prefered)

Documentation:

I take it that you have only configured token, and not changed hostname?

The idea is that you first save the “AirGradient API” thing. And to do that you should only have to add the token. Then locations should be autodiscovered and they should show up in you “inbox”.

I think we should first debug if the “AirGradient API” thing is connecting to the cloud API.
What is the status of the AirGradient API thing?

If you in the openHAB console run:
log:set DEBUG org.openhab.binding.airgradient

and in the API things configuration (under advanced) change the refreshInterval to something like 60 to get it to try to connect every minute:

Do you see any log messages indicating that it tries to or is able to read from the cloud API?

Thanks a lot for answering !

From the description it sounds like you try to run against the cloud API and not against the sensor locally. (That is a supported mode, just clarifying in case that is not what you want.)

Indeed. i wanted to try that before connecting to my AG (I have to update it first)

Which version of OpenHAB are you running? (The binding is included in the latest stable 4.2.1 version)

I’m running 4.2.1

Did you go to Administration-Bindings and installed the one with the openHAB blue checkmark?

Yes, from the bindings, with the blue check mark

I take it that you have only configured token, and not changed hostname?

I just added the “Location” and the token from AG

You can see on the top the error. I don’t screenshot the console logs but there is nothing showing an attempt to connect to the AG cloud API. here the part that look the most informative however

22:20:20.120 [DEBUG] [y.AirGradientLocationDiscoveryService] - Start AirGradient background discovery
22:20:20.137 [ERROR] [y.AirGradientLocationDiscoveryService] - bundle org.openhab.binding.airgradient:4.2.1 (276)[org.openhab.binding.airgradient.internal.discovery.AirGradientLocationDiscoveryService(378)] : The activate method has thrown an exception

22:20:20.603 [DEBUG] [y.AirGradientLocationDiscoveryService] - bundle org.openhab.binding.airgradient:4.2.1 (276)[org.openhab.binding.airgradient.internal.discovery.AirGradientLocationDiscoveryService(378)] : DependencyManager: osgi.ds.satisfying.condition close component unbinding from org.apache.felix.scr.impl.manager.ComponentContextImpl@5afd81b3 at tracking count 1 refpairs: [[RefPair: ref: [{org.osgi.service.condition.Condition}={service.id=6, service.bundleid=0, service.scope=singleton, service.pid=0.org.osgi.service.condition.ConditionImpl, osgi.condition.id=true}] service: [null]]]
22:20:20.611 [DEBUG] [y.AirGradientLocationDiscoveryService] - bundle org.openhab.binding.airgradient:4.2.1 (276)[org.openhab.binding.airgradient.internal.discovery.AirGradientLocationDiscoveryService(378)] : Failed creating the component instance; see log for reason
22:20:20.657 [ERROR] [.core.thing.internal.ThingManagerImpl] - Exception occurred while calling thing handler factory ‘org.openhab.binding.airgradient.internal.AirGradientHandlerFactory@40668c1a’: Cannot invoke “org.openhab.core.thing.binding.ThingHandlerService.setThingHandler(org.openhab.core.thing.binding.ThingHandler)” because “this.serviceInstance” is null

22:20:20.661 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘airgradient:airgradient-api:93474c1b6b’ changed from UNINITIALIZED to UNINITIALIZED (HANDLER_REGISTERING_ERROR): Cannot invoke “org.openhab.core.thing.binding.ThingHandlerService.setThingHandler(org.openhab.core.thing.binding.ThingHandler)” because “this.serviceInstance” is null

Thank you, now I see! I was confused by the Location, which is both a concept in openHAB and in AirGradient.

This seems to be initialization going wrong, and is nothing you have configured wrong. Either something has changed, I have done something wrong implementing it or some timing is off.

Unfortunately I am away from my computer this weekend so I can’t investigate thoroughly until Sunday evening/Monday. If the AirGradient sensor is on the same network as the openHAB installation, you could also try to set up a AirGradient Local sensor manually, and configure the hostname (IP address). It is another source code, so it might work.

Anyway, I’ll try to reproduce and investigate as soon as I am back.