Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding air quality display #188

Open
jon0x0 opened this issue Oct 1, 2020 · 0 comments
Open

Adding air quality display #188

jon0x0 opened this issue Oct 1, 2020 · 0 comments

Comments

@jon0x0
Copy link

jon0x0 commented Oct 1, 2020

With all the wildfires here in the west I added an air quality index (AQI) display to my PiClock + weather interface.

IQAir has a free or paid API (free key good for a year at a time):

API docs at
https://api-docs.iqair.com/

Once registered get your API key from
https://www.iqair.com/us/dashboard/api

I used a call like this:
http://api.airvisual.com/v2/nearest_city?lat=your_lat&lon=your_lon&key=your_key
I recommend picking the appropriate station manually from their map interface and using the lat/lon which will cause that one to be selected.

You get up to 10,000 calls/month free (10 min+random period similar to temperature should work ok).

I duplicated the gettemp() and tempfinished() sections as getaqi() and aquifinished(), modified and added a very simple QUrl / QNetworkRequest string (not JSON) read and parse of the data, and searched for the tag '"aqius":' to pull out the data and display it in a text label where the other labels are created

aqistr = str(aqireply.readAll())
idxaqi=aqistr.find('"aqius":')
saq=aqistr[idxaqi:len(aqistr)]
saqi=saq[8:saq.find(',')]
s='AQI '+saqi
print s
aqi.setText(s)

[UI section, duplicated/modified]
aqi = QtGui.QLabel(foreGround)
aqi.setObjectName("aqi")
aqi.setStyleSheet("#aqi { font-family:sans-serif; color: " +
Config.textcolor +
"; background-color: transparent; font-size: " +
str(int(60 * xscale)) +
"px; " +
Config.fontattr +
"}")
aqi.setAlignment(Qt.AlignHCenter | Qt.AlignTop)
aqi.setGeometry(0, height - 200, width, 100)

Publishing a production ready merge isn't really for me but just wanted to share what I found, maybe somebody can make use of it or run with it. Maybe the smoke coverage map could somehow be overlayed from fire.airnow.gov or somewhere.
Air quality index color codes and warning text from https://www.airnow.gov/aqi/aqi-basics/ could be used.
I will probably end up adding a few different local air stations since none of them are perfect for me and they can give quite different results depending on the situation.
For now I am finding AQI data alone quite nice to have.
Hope someone finds it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants