Thursday, August 19, 2021

Making the most of the Awair API with Node-RED, Domoticz, AWS Timestream, and Grafana


I bought an Awair Element earlier this year to keep an eye on the air quality at home, particularly in the kids room. Although the app is fantastic, I have a lot of other sensor data that I feed into Domoticz. With Domoticz I can create custom alerts or events (for example to send a Pushover notification or turn a heater/humidifier on at a given threshold). Furthermore, I have my MQTT server bridge to AWS IoT Core, and a rule that sends this data to an AWS TimeStream DB. From there I have long-term access to my data, able to visualize it with Grafana. Let’s take a quick glance at the outcome before getting started:

Timestream DB visualization with Grafana (including data from soon to be retired DarkSky)


Domoticz Notifications

Domoticz Events


  1. First create an Inject node. The payload does not matter. Check the box “Inject once after…” and configure the interval for how often you’d like to collect the data.

  2. Next create and connect an HTTP request node, and configure it to use your Awair Element HTTP API

  3. Next, add a JSON node with the default settings

  1. Now, we add our first Change node. In Domoticz, a virtual sensor (Temp+Hum) was created, and I noted down the IDX number. Here we are using JSONata to format the payload value (into a temporary store) to what is expected by Domoticz. The payload is then cleared (so as only to have the expected payload), and is repopulated with the IDX, nvalue required by Domoticz, and the svalue with the data.

  2. Here we have the PM 2.5 sensor data. In Domoticz I created a Custom Sensor “Awair PM 2.5” and set the label as ug/m3. For the Custom Sensor type it seems that I had to use a string data type to get it to register (but parses the data as a number just fine after that point)

  3. Same thing for PM 10 sensor data.

  4. CO2 (ppm measurement):

  5. VOC (ppb measurement):

  6. And last, the Awair “score” determined by mixing the sensor data:

  7. Finally, create an MQTT out node, and configure it to point to the MQTT server you’re using for Domoticz. Deploy the flow, and at this point, you should have data coming into Domoticz.

  8. Temperature tab in Domoticz

  9. On the Utility tab in Domoticz, we can see all the “Custom Sensor” data

  1. For the MQTT bridge I have the domoticz/out topic going out to AWS IoT Core and domoticz/in coming back in (for some AWS Lambda functions that I have to grab even more API data such as AirNow). I highly recommend DietPi Linux if you’re using a Raspberry Pi.

  2. In AWS IoT Core I have a rule that sends this data to a TimeStream DB (up to 200 year retention if you wanted!!!)

  3. For Grafana, I installed it as a Docker container in Elastic Container Services. I attached the AmazonTimeStreamReadOnlyAccess policy to the ecsInstanceRole so that it could read the Timestream DB.

  4. I then configured the Timestream plugin in Grafana. I named the DB similar to the “DarkSky” API which is End of Life soon

  5. I stumbled my way around PromQL for quite some time before figuring out how to make a proper graph. Dual Y axis is being used

  6. My AWS costs are minimal. My end of month bill is forecasted to be $1.04. I expect this to grow slowly over time as I add more and more data, but nothing to bat an eye at.