Air Quality binding for openHAB2

2017-04-22

Being a Krakow citizen, I know the struggle of breathing during the winter time.
People burning trashes in their tiled stoves in the city is one of main reasons why we have to deal with air pollution.
The first time I heard of Air quality index was when I moved to Krakow.

I was thinking about extending my home automation system with a feature that would warn me each time the air quality is bad.

Background

After some online research I found AQIcn.org service that seemed perfect to my needs.
It has an open API, is fairly well docummented and needs just my e-mail address to get me started.

Shortly after I played around with the API, I’ve submitted a tutorial on openHAB community forum showing how to utilize the AQI data in the home automation setup.

But that wasn’t enough. The API was so powerful that I planned it to serve as a separate binding for openHAB!

With some trials and errors, reading through the openHAB Coding Guidelines and an amazing support from other openHAB developers, I’ve managed to submit my first pull request to the openhab2-addons repository.
Here’s the latest AirQuality binding source coude available in the openHAB repository.

Use case

So now my home automation system contains a set of rules that utilizes the AQI value in my area.
I’m tracking the AirQuality every hour. Here you can see the Grafana chart showing the AQI from last two months in Krakow/Skawina:

For the automation I wrote a simple rule that would change my Xiaomi Gateway light color whenever AQI value changes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
rule "Air Quality to Xiaomi Gateway"
when
Item Aqi_Description changed
then
var String hsb
switch Aqi_Description.state {
case "HAZARDOUS":
hsb = "343,100,49"
case "VERY_UNHEALTHY":
hsb = "280,100,60"
case "UNHEALTHY":
hsb = "345,100,80"
case "UNHEALTHY_FOR_SENSITIVE":
hsb = "30,80,100"
case "MODERATE":
hsb = "50,80,100"
case "GOOD":
hsb = "160,100,60"
}
sendCommand(Gateway_Color, hsb)
end

Check out the documentation of AirQuality binding that’ll hopefully get you started.


Comments: