Awair Element air quality monitor - data charting without using a binding

Tags: #<Tag:0x00007f433d7e7278>

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.

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.

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

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.


For OH2.5 I got the data into Grafana for charting and gauges without using a binding. A binding for 2.5 and OH3 is in development but I am impatient and so I did it another way. I still would like a binding to reduce the coding. :slight_smile:

It’s fairly simple to get the data into openHAB. Here’s how…

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 caching of the page depends on which OH you use. Here is OH2 and http.cfg services version

AwairCache.url=http://192.168.1.6/air-data/latest
AwairCache.updateInterval=300000

items file

String AwairHTTPCache "Awair HTTP cache" <text> { http="<[AwairCache:300000:REGEX((.*))]" } // cache checked every 5mins.

Number AwairScore "Air quality score [%d %%]" <vacation>
Number AwairCO2 "CO2 [%d ppm]" <carbondioxide>
Number AwairVOC "Chemicals [%d ppm]" <smoke>
Number AwairPM25 "Fine dust [%d ug/m3]" <smoke>

rule file

var newval = new String

rule "Awair HTTP cache"
when
    Item AwairHTTPCache received update
then
    newval = transform("JS", "getAwairScore.js", AwairHTTPCache.state.toString)
    AwairScore.sendCommand(newval)

    newval = transform("JS", "getAwairCO2.js", AwairHTTPCache.state.toString)
    AwairCO2.sendCommand(newval)

    newval = transform("JS", "getAwairVOC.js", AwairHTTPCache.state.toString)
    AwairVOC.sendCommand(newval)

    newval = transform("JS", "getAwairPM25.js", AwairHTTPCache.state.toString)
    AwairPM25.sendCommand(newval)

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

Useful info about the Awair local API feature:

M

1 Like

Fantastic write-up! Thank you. I have added a link in the Awair Element and Awair 2nd Edition documentation. Let me know if you need anything.

Also, one suggestion would be to mention the mDNS feature as opposed to looking up the device IP address. It might be a little easier to form the URL with the .local address. For example: http://awair-elem-123abc.local/

1 Like

Hi,

Thanks for the feedback. I am guessing that you are from Awair. Nice to see some support here :slight_smile:

Regarding DNS. I never had much luck with that being reliable for me. Maybe due to my dual NAT setup and complex enviroment. For hardware on my LAN I prefer to reserve the IP address either on the hardware or in the router setup. I linked local API documentation above. This explains more if anyone wants to try another way. Must admit I did’t really read it carefully or spend too much time on this integration as it was simple to do with a bit of openHAb experience, but there are possibly better ways.

If anyone gets here and is wondering how to use Grafana… there is a tutorial and lots of posts in the community on how to do that. Please search. The easiest way I know if you have your OH running on a raspberryPi is to use the config tool to install it along with the needed Influx data base.(>sudo openhabian-config…Menu 20-24).

1 Like

Yes, I work for Awair. :slightly_smiling_face:

Really cool. I’m more of a Homebridge-r, but you’ve convinced me to start up an OpenHAB Raspberry Pi instance.

1 Like

Thank you for the very useful write-up. I just purchased an Awair and I am working through the integration with OpenHAB.

One thing I found is that the Local API feature is not enabled by default. It needs to be enabled via the Awair app. Awair Local API Feature – Awair Support