Outside Air Quality into Weather Tab

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
User avatar
LouiS22
Posts: 433
Joined: Friday 27 February 2015 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Budapest, Hungary
Contact:

Outside Air Quality into Weather Tab

Post 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).
MsbS
Posts: 35
Joined: Friday 19 May 2017 14:00
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Outside Air Quality into Weather Tab

Post 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.
User avatar
LouiS22
Posts: 433
Joined: Friday 27 February 2015 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Budapest, Hungary
Contact:

Re: Outside Air Quality into Weather Tab

Post 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 ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests