Page 1 of 1

Outside Air Quality into Weather Tab

Posted: Saturday 04 November 2017 22:26
by LouiS22
Bumped into a nice website: waqi.info.

It provides real time air quality data such as PM10, SO2, NO2, O3 from many cities around the world. They have a well documented API so in theory it shouldn't be a problem to incorporate them into Domoticz (API token is free - similar to Weather Underground).

Re: Outside Air Quality into Weather Tab

Posted: Saturday 04 November 2017 22:51
by MsbS
I did exactly this a few days ago. Here's how.

1. Get API key
2. Find out the ID of a station next to you, by opening the following in the browser:
https://api.waqi.info/search/?token=[Insert Token Here]&keyword=Budapest
You need the 'uid' field.
3. Create a Dummy Sensor in Domoticz (Custom Sensor). Note the IDX number.
4. I created a short script that downloads the air quality rating once and uploads it to Domoticz:

Code: Select all

#!/bin/bash

LOCATION=@[the uid goes here, after the '@' character]
APITOKEN=[enter the API token here]
IDX=[enter the IDX number here]

#Get the data
data=$(curl -s "http://api.waqi.info/feed/$LOCATION/?token=$APITOKEN" |json_pp|grep -A 1 "pm25"|grep "v"| sed -e s/[^0-9.]//g)
curl -s "http://[domoticz IP]:8080/json.htm?type=command&param=udevice&idx=$IDX&svalue=${data}"
5. I then added a line in cron that runs the script every hour (my station is updated every hour).

NOTE: I was only interested in pm25, to compare it to my inhouse PM2.5 sensor in Air Purifier, this is why I used the 'grep pm25' fragment. You can check what your station outputs by running:
http://api.waqi.info/feed/@[location uid]/?token=[api token]
NOTE2: I am a noob in Domoticz and unix bash scripting - this could probably be done much better.

Re: Outside Air Quality into Weather Tab

Posted: Sunday 05 November 2017 8:09
by LouiS22
MsbS wrote: Saturday 04 November 2017 22:51 I did exactly this a few days ago. Here's how.

1. Get API key
2. Find out the ID of a station next to you, by opening the following in the browser:
https://api.waqi.info/search/?token=[Insert Token Here]&keyword=Budapest
You need the 'uid' field.
3. Create a Dummy Sensor in Domoticz (Custom Sensor). Note the IDX number.
4. I created a short script that downloads the air quality rating once and uploads it to Domoticz:

Code: Select all

#!/bin/bash

LOCATION=@[the uid goes here, after the '@' character]
APITOKEN=[enter the API token here]
IDX=[enter the IDX number here]

#Get the data
data=$(curl -s "http://api.waqi.info/feed/$LOCATION/?token=$APITOKEN" |json_pp|grep -A 1 "pm25"|grep "v"| sed -e s/[^0-9.]//g)
curl -s "http://[domoticz IP]:8080/json.htm?type=command&param=udevice&idx=$IDX&svalue=${data}"
5. I then added a line in cron that runs the script every hour (my station is updated every hour).

NOTE: I was only interested in pm25, to compare it to my inhouse PM2.5 sensor in Air Purifier, this is why I used the 'grep pm25' fragment. You can check what your station outputs by running:
http://api.waqi.info/feed/@[location uid]/?token=[api token]
NOTE2: I am a noob in Domoticz and unix bash scripting - this could probably be done much better.
Nice ;)