AQI Tile (Air Quality Index)

Hey everyone,

Unfortunately for some of us in the US, the air quality is terrible due to wildfires. I created a quick tile to show the current AQI near my house. The data is coming from one of the many purpleair.com sensors.

The code is here (don’t judge me on the code quality :grimacing:): Glitch :・゚✧

Feel free to clone it and make it your own as I am still fine-tuning mine. The only line that needs to be updated is the one where we fetch the data from purpleair.com (line 204), you want to select a sensor that is near your house. Let me know if you need instructions for finding the sensor id on purpleair.com

Cheers



7 Likes

@dbaq, thanks for sharing this very cool project. I liked how simple it looks visually. :+1:

I’ve moved your post to the Community Project category where other community members usually look for in regarding to the community developed projects. A couple feedback, you may want to take a look of the stio library and allow users to provide the sensor id via the Tile Editor in the dashboard, so they don’t have to look up in the code.

And you can also take advantage of the direct Custom Tile import URL as shown below to allow users to import the source code and create the custom tile in just one simple click. (I created the the import link with the image below and feel free to include it in your original post.) :grinning:

https://sharptools.io/developer/custom-tiles/import/?url=<Encoded-URL-to-Your-Raw-Source-Code>

image

1 Like

Thanks, James.

you may want to take a look of the stio library and allow users to provide the sensor id via the Tile Editor in the dashboard, so they don’t have to look up in the code.

Yep, that’s the plan if I see any interest from the community :wink:

1 Like

Awesome work on this! I really like the clean look and how easy it is to see things at a glance with the stoplight style colors.

Per discussion with @dbaq via PM, here’s a version that works like a native custom tile where it let’s you configure the PurpleAir sensor ID in the tile configuration.

:arrow_double_down: Import PurpleAir Custom Tile

Source Code

(The import link in James’ reply above has been updated too)

2 Likes

Just click on a sensor on the map and then grab the five digit select value?

The numbers roughly match but Purple is showing an AQI of 57 (yellow) and the tile is showing 47 (green). Maybe just a minor difference in the conversions to AQI?

A few things to know:

I am getting the data from that URL: https://www.purpleair.com/json?show=95579 (replace with your sensor ID)

The response could return multiple sensors (the main one + all the child sensors). I am using the first one in that list and I am using v1 which is the pm2.5 10 min average. We could also make that configurable.

As for the conversion mismatch, you are right. I also see some differences within the +/- 10. I reimplemented the code from Spare The Air: AQI Calculator: Concentration to AQI which could be slightly different from purpleair.com. In the end, from an AQI perspective, the difference is not meaningful but I will dig into it to understand the difference between purpleair and sparetheair when I get a chance.

ps: on purpleaire.com consider using outside sensors only because inside sensors are very random.

3 Likes

I totally agree! I figured it was close enough and probably just a minor calculation difference, so I appreciate your reply. Great job! :+1:

1 Like

@dbaq Really like the new tile and just added it to my dashboard. I have been noticing a rather big difference between what the website report and what my dashboard shows with this ID 17889. This morning, the difference is more than 25 between the two. I tried the calculation manually and have use the data returned by the json (13.74) and ran the calculation on the site AQI Calculator = 44. The tile was reporting 21. Was just wondering if this difference is somewhat normal? Great work!

FYI, if you live in Europe and find lacking the data from PurpleAir,
I found a widget site for many locations here:

They have a widget and json API so lots of customization!

1 Like

Hi, is this tile still working? I imported the tile and entered a sensor near me and all I see is a blank tile with the wind icon. I have tried changing sensor IDs and even tried the https://www.purpleair.com/json?show=95579 URL to see if the JSON would show and I get an “over the limit” for the API error page.

Here is the tile I see when I add it to my dashboard:
image

Any guidance is greatly appreciated.

I’m getting the same problem. Seemed to stop working a couple of months ago. I’ve tried various options but have not found an answer.

I’m getting the same problem. Seemed to stop working a couple of months ago. I’ve tried various options but have not found an answer.

PurpleAir changed their API a while back and individual API keys are now required.

@IslandSoul thanks for the reply, that makes sense. I will look into the API keys.

The API keys are free and can be obtained emailing contact@purpleair.com with your name and email address. Right now, they’re taking a couple of days to respond.

In HE, I’ve moved to this driver for working with PurpleAir.

Many thanks Bob, I have contacted PurpleAir so hopefully will get the API key shortly.
I am using the access through Sharp tools. I’ll let you know how it goes.

I received the API key from PurpleAir - they are very responsive with their support - and have everything working through a Custom Tile in Sharp Tools.
@IslandSoul thanks for putting me on the right track.

2 Likes

Unfortunately, it’s working a bit too well. Here’s our current AQI (about 25 miles from the Mosquito Fire):scream::rage:

AQI

1 Like

Wow - that’s pretty bad. At least you know I guess.

1 Like

@brian.ratter @IslandSoul @Shawn_Pray : Does it work on your Sharptools dashboard? What I have to change in the custom tile?

My installation looks like this:
Screenshot 2024-06-11 085536

@feron - yes it is working for me on Sharp Tools. Do you have your API key and the correct Sensor Index. You can try this URL (use your own API key), which should return the results:
https://api.purpleair.com/v1/sensors/104220?api_key={YOUR_API_KEY}&fields=name%2Cmodel%2Chumidity%2Cpm2.5%2Cpm2.5_10minute
If that works but you still do not get results in Sharp Tools you will need to check your code.
Also check in the logs to see if there are any error messages.