My setup (Prerequisites for openHAB v3):
- openHAB3 installed on a RPi4 using openhabian image:
download page- Grafana and Influx installed via menu. Some familiarity with using these in openHAB will be needed!! Grafana gauges are a plugin called D3 gauge by Brian Gann. To install Influx and Grafana use a console window and open the config menu:
sudo openhabian-config … menu item 20-24- HTTP binding installed via openhab addons menu:
http://“IP of your openHAB server”:8080/settings/addons
Awair is a mid to high end (200euro) air quality monitor for the home. It monitors temperature, humidity, C02, volatile organic chemicals(VOC), particles smaller than 2.5um (PM25) and can send alerts and other info to your phone. It also calculates an overall air quality score 0-100.
The unit has a very simple LED display but you can also use an app to check the detailed data. Charting is a bit limited and I prefer to have one place for all my charts >>> Grafana. The unit has a simple web page that can be accessed from the LAN. There are cloud options too but I didn’t check these out. Of course once the data is in openHAB you can then create rules to act on it eg switch on AC, dehumidifier etc
From Awair website:
The easiest way to access and review data through the Local API feature is to find the webpage (see: Discovering your Awair device on the LAN below) and load it into your browser.
For developers and more advanced users, you can use popular technologies such as Python and JavaScript to fetch data and use it in custom programs; or platforms such as Homebridge, Home Assistant, and OpenHAB to use the data in a home automation system.
Below are the Grafana gauges and a example chart that I created for the Awair monitor. After those images there are instructions on how do it for yourself. There is more data available via HTTP eg raw data and device parameters if interested.
How it looks in Grafana
Here’s how to do it using the HTTP method to obtain the data from the Awair Element every 5mins
N.b. Below assumes some basic knowledge of: openHAB, use of openHAB textual config files, Grafana dashboards and charts setup.
I enabled the local API option for the Awair using the app and then in openHAB setup HTTP caching and regex to extract the needed data.
eg to see the webpage to cache
http://<IP address of your Awair device>
This comes up wth some links and the following information:
Local Sensors
issue a GET request / refresh this page to retrieve the latest air-data samples and the UTC timestamp (ISO8610 formatted) on the internal clock, or supply a timestamp as an optional query parameter (e.g. “?current_time=1970-09-23T17:12:19.630Z”)
Device settings:
issue a GET request to retrieve device configuration data
Click on the link and you can see the data we want to bring into openHAB
http://<IP address of your Awair device>/air-data/latest
The 5min caching of the data from the local API webpage uses the http binding. Here is the binding .thing file
Thing http:url:AWAIR "AWAIR" [baseURL="http://<IP of Awair Element on your network>/air-data/latest", refresh=300, timeout=10000] { //refresh = seconds
Channels:
Type string : cache "AWAIR cache"
}
items file
String AwairCache "Awair HTTP cache" <text> {channel="http:url:AWAIR:cache"}
Number AwairScore "Air quality score [%d %%]" <vacation>
Number AwairCO2 "CO2 [%d ppm]" <smoke>
Number AwairVOC "Chemicals [%d ppm]" <smoke>
Number AwairPM25 "Fine dust [%d ug/m3]" <smoke>
Number AwairTemperature "Temperature [%.1f °C]" <temperature>
Number AwairHumidity "Humidity [%d %%]" <humidity>
rule file
var newval = new String
rule "Awair HTTP cache"
when
Item AwairCache received update
then
if (AwairCache.state.toString.contains("NULL") || AwairCache.state.toString.contains("null") || AwairCache.state.toString == "") { //Check for problem with Awair
logError ("Awair", "Awair cache = " + AwairCache.state.toString)
return; //Exit from rule
}
else {
newval = transform("JS", "getAwairScore.js", AwairCache.state.toString)
AwairScore.sendCommand(newval)
//logInfo ("Awair", "Awair air quality score = " + newval + " %")
newval = transform("JS", "getAwairCO2.js", AwairCache.state.toString)
AwairCO2.sendCommand(newval)
//logInfo ("Awair", "Awair CO2 = " + newval + " ppm")
newval = transform("JS", "getAwairVOC.js", AwairCache.state.toString)
AwairVOC.sendCommand(newval)
//logInfo ("Awair", "Awair chemicals = " + newval + " ppm")
newval = transform("JS", "getAwairPM25.js", AwairCache.state.toString)
AwairPM25.sendCommand(newval)
//logInfo ("Awair", "Awair PM2.5 fine dust = " + newval + " ug/m3")
newval = transform("JS", "getAwairTemperature.js", AwairCache.state.toString)
AwairTemperature.sendCommand(newval)
//logInfo ("Awair", "Awair temperature = " + newval + " °C")
newval = transform("JS", "getAwairHumidity.js", AwairCache.state.toString)
AwairHumidity.sendCommand(newval)
//logInfo ("Awair", "Awair humidity = " + newval + " %RH")
}
end
Example regex for CO2 .js file
(function(i) {
var re = new RegExp(',"co2":([0-9]+),');
var out = i.match(re)[1];
return parseFloat(out);
})(input)
Site map
Default item=AwairScore
Default item=AwairCO2
Default item=AwairVOC
Default item=AwairPM25
Default item=AwairHumidity
Default item=AwairTemperature
influx persistence file
Strategies {
everyMinute : "0 * * * * ?"
every5Minutes : "0 */5 * * * ?"
every15Minutes : "0 */15 * * * ?" //openwebnet thermo items are only updated every 15mins so no point in logging faster
everyHour : "0 0 * * * ?"
everyDay : "0 0 0 * * ?"
default = everyChange
}
//Awair Element monitor
AwairCO2 : strategy = everyUpdate, everyChange, every5Minutes
AwairVOC : strategy = everyUpdate, everyChange, every5Minutes
AwairPM25 : strategy = everyUpdate, everyChange, every5Minutes
AwairScore : strategy = everyUpdate, everyChange, every5Minutes
AwairTemperature : strategy = everyUpdate, everyChange, every5Minutes
AwairHumidity : strategy = everyUpdate, everyChange, every5Minutes
Useful info about the Awair local API feature:
M