Air Quality Binding - looking for testers

Tags: #<Tag:0x00007f0148275fd8> #<Tag:0x00007f0148275da8> #<Tag:0x00007f0148275c40>

(Kuba Wolanin) #1

Hi everyone,

In one of my recent tutorials I’ve showed you how to use API in order to get Air Quality data.

Today I’ve submitted a pull request to openhab2-addons repo with my first binding attempt :slight_smile:
The README file explains all the basics needed to get it work in your environment. If not, please let me know!

Zip file is included to the first pull request comment. You just need to change the extension to jar


Measuring Air Quality with
Air quality addon not showing data
( ) #2

That’s great @kubawolanin Congrats on your first (of many?) bindings :wink:

I did not get around to follow the tutorial but using the binding will be a piece of cake :smiley: That is by the way a very professional and informative README. If the binding works as good as the readme indicates, this will be a nice addition to everyone’s home! :thumbsup:

Best Regards

(Łukasz Dywicki) #3

Hey @kubawolanin!
Great to see this happening. :slight_smile: Since air quality is nowadays hot topic in Poland tracking it with ease inside openhab is great idea!

I reviewed your code and found that JSON response handling could be improved. I removed synchronized block and instance field for keeping response. This value can be kept in local stack of refresh task. I also removed reflection calls in favor of direct method invocations. You can find sources in my fork of your widelec (fork in polish): splatch/openhab2-addons/feature/airquality.
I didn’t compile nor complete these changes because I don’t have up-to-date sources with all dependencies. Feel free to do whathever you want with this proposal. If you will have any questions about gson feel free to post questions or contact me in any way you prefer.

You are very likely first pole supplying OH2 compatible binding. Congratulations!


(Kuba Wolanin) #4

Wow, thank you so much for your expertise, Łukasz!
My “first language” is JavaScript, so it was an interesting experience for me to make this binding :slight_smile:
I merged your widelec into my branch and added attribution to the classes you’ve improved.
Then I’ve squashed our commits into one.

Awesome stuff, I’m sure there’s much more for me to explore!

I’ll remember that :slight_smile:


(Robert) #5

Not sure where to raise any issues currently, so posting it here for now. If you give me the repo link I will move it there.

I used your example and everything is working as expected, apart from the CO channel:

2017-01-22 06:05:16.502 [WARN ] [airquality.handler.AirQualityHandler] - Update channel co: Can't get value: null

I am pulling data from station ID 5772 (Rotterdam).

To be of more help I have switched logging to DEBUG already.

Update: the README explains that this might be due to CO not being measured at his station. If so, I would expect the binding to handle this more gracefully, for example through a more descriptive message in the log like ‘station XXX doesn’t provide XXX measurement’.

(Robert) #6

Another issue (why I was looking at the logs in the first place).

The air quality for station 5772 is updated once an hour. But now, at 7:00 the observation time shows 6:00. Perhaps this is correct, but maybe the binding is not respecting time zones. I live in CET and like to know if observation time is correct or in UTC time zone (which would explain the 1 hour difference).

Update: This is the debug message:

2017-01-22 07:05:27.667 [DEBUG] [airquality.handler.AirQualityHandler] - aqiData = {"status":"ok","data":{"idx":5772,"aqi":103,"ti
me":{"v":1485064800,"s":"2017-01-22 06:00:00","tz":"+01:00"},"city":{"name":"Rotterdam","url":"http:\/\/\/city\/rotterdam
\/","geo":["51.9xxxx","4.4xxxx"]},"attributions":[{"name":"RIVM - Rijksinstituut voor Volksgezondheid en Milieum, Landelijk Meet
net Luchtkwaliteit","url":"http:\/\/\/"},{"name":"World Air Quality Index Project","url":"http:\/\/\/"

The observation time is in local time and the time zone is provided separately.

In my sitemap it is shown as 6:00 so the +1:00 is ignored.

And yes, the air quality is at 103 so I am not using the binding for nothing.

(Kuba Wolanin) #7

Hi Robert, many thanks for the testing! Much appreciated.
I will add the message you proposed to the logs. Great idea!
As for the timezones, it’s certainly a bug and I will handle that too :slight_smile:

As for the furher issues, I’d suggest to use my github fork of openhab2-addons. I’ve just enabled that option :slight_smile:

(Robert) #8

Will do that. If your PR gets merged quickly, we might be able to use the regular tracker. :wink:

(Kuba Wolanin) #9

Everything’s in @Kai’s power - given that there are 70 PR’s to be merged (and we’re expecting 2.0 release soon), I think it’ll last for a couple months before it appears on the branch :slight_smile: This gives us some time to test it heavily and find as many bugs as possible before it lands as official binding.
I’ll make updates of the JAR accordingly.

(Robert) #10

If the jar has a fixed path and filename then I would be able to easily update with a small bash script and wget.

(Kai Kreuzer) #11

I hope it will be quicker! I have it on the radar and once 2.0 is out, I can again focus more on binding PRs. As quite some others are already eagerly helping on reviewing and testing, this will be much quicker! But so far, I haven’t seen an approval from any of the reviewers, so I will wait for that :slight_smile:

(Robert) #12

Copy of my update script


#without extension

# stop openhab
sudo systemctl stop openhab2.service

# download
wget -N $1

# backup old jar(s)
cd $OH2PATH/addons
for f in *airquality*.jar; do sudo mv "$f" "$f.$(date +%s)"; done

sudo mv $DOWNPATH/$ ./$ADDON.jar
sudo chown openhab:openhab ./$ADDON.jar

# start openhab
sudo systemctl start openhab2.service

(Andrew) #13

I’ve noticed that there is no formatting like [%.1f °C] in the item configuration example provided, but everything is displayed as it should. Is this some sort of default behavior specific for this binding?
Many thanks to the Author!

(Kuba Wolanin) #14

I was thinking about it actually but couldn’t find time lately to research all possible units for values like PM2.5, NO,O2 etc. Would you be interested in providing these? I’d appreciate your help :slight_smile:

(Robert) #15

You could probably try and remove the <temperature> icon from the item definition to see what changes.

@kai Do temperature items have a default display formatting for degrees Celsius?

(Robert) #16

It depends on what the actual value means. Is it “ppm” or just an index?
I am more interested in the meaning of the values, for example in a scale from HEALTHY to HAZARDOUS.

(Andrew) #17

Removing <temperature> and/or <humidity> removes only icon, no change to formatting.

(Nathan Wilcox) #18



I’ve installed the binding by changing from .zip to .jar. Placed inside of addons and rebooted. Binding has shown up in PaperUI but I’ve encountered the following error in PaperUI

Status: OFFLINE - COMMUNICATION_ERROR java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 27 path $.data

Any ideas?


(Kuba Wolanin) #19

Hmm, that means I need to implement better error handling! :slight_smile:
Make sure you’ve entered a proper API key and geo coordinates.

(Nathan Wilcox) #20

Re-entered API key, generated a second lot of geo coordinates from different supplier But still returning duplicate error from above.

I’d be more than happy to send my API key and coordinates privately for you to replicate the results?