Thanks @TAustin !
I’m following up with you in DM.
Using vEdge Creator to create the second PurpleAir device seems to be working just fine as a workaround. Not sure if you want to document that as an official solution?
Thanks @TAustin !
I’m following up with you in DM.
Using vEdge Creator to create the second PurpleAir device seems to be working just fine as a workaround. Not sure if you want to document that as an official solution?
I observed that each PurpleAir AQI driver API call to a single outdoor PurpleAir sensor consumes 11 API points according to my PurpleAir Dev accounting report.
Here is the breakdown from the API price list:
get_sensors call: 5 points
name data: 1 point
pm2.5 data: 2 points
latitude data: 1 point
longitude data: 1 point
confidence data: 1 point
==============================
Total: 11 API points
(Price list: PurpleAir Develop)
Accounts start with 1 million free points. This gives you 2.6 years of access for a single sensor, querying every 15 min or 1.7 years, querying a single sensor every 10 min. If you query multiple sensors then you’ll run out of API points pretty quickly.
Let me know if I’m doing my math wrong. I hope that PurpleAir sensor owners will be able to get automatic credit for querying their own sensors.
@TAustin it might be worth seeing if the API calls can be further optimized to reduce API cost (get_sensor vs get_sensors) and only querying the specific data fields needed.
This was a port of an former DTH-based driver, so I didn’t do a whole lot of re-writing of the way it was doing things. I’ll take a look at the code, but the primary way to control how often the API is hit, is to adjust the Update Interval in device Settings. 3 hours is the least frequent option at the moment, but there’s probably no good reason why that couldn’t be as high as once a day.
As far as how the API is used, it’s pretty simple: it’s just one HTTP request:
@TAustin I did some experimenting with the API calls and here is what I found.
The currently used API call costs 11 API points:
https://api.purpleair.com/v1/sensors/fields=name,pm2.5_10minute,latitude,longitude,confidence&show_only=12345
get_sensors: 5 points
name: 1 point
pm2.5_10minute: 2 points
latitude: 1 point
longitude: 1 point
confidence: 1 point
The following revised API call costs only 4 API points:
https://api.purpleair.com/v1/sensors/12345?fields=name,pm2.5_10minute
get_sensor: 1 point
name: 1 point
pm2.5_10minute: 2 points
Note: 12345 represents the sensor_index
Examples (replace with your API key, your sensor index & your EdgeBridge server URL):
curl -H “x-api-key:xxxxxxxx” -X GET “https://api.purpleair.com/v1/sensors/12345?fields=name,pm2.5_10minute”
curl -H “x-api-key:xxxxxxxx” -X GET “http://192.168.1.1:8088/api/forward?url=https://api.purpleair.com/v1/sensors/12345?fields=name,pm2.5_10minute”
Have you tried configuring the PurpleAir SmartThings device for a specific sensor, rather than a search box? From what you are saying, it’s the search box coordinates that is contributing to the points usage.
In Settings, if you turn OFF the “Search for devices” option and provide a private key, doesn’t that send the URL you are indicating? Maybe I’m missing something, as I haven’t really experimented with it too much.
@TAustin I am querying for a specific sensor and I am getting the URL that I shared above.
Update Interval: 15 minutes
Averaging Period: 10 minutes
Search for devices: Disable
Private Key: provided
Sensor Index: provided
Search box center: Not used “Lat, Long (coordinates)”
Search box size - value: Not modified “5”
Search box size - units: Miles
Use weighted average: Disable
Proxy Type Edge Bridge Server
Proxy Server Address: provided
Response Timeout: 3
API Key: provided
Note that I am unable to blank out: Search box center, Search box size - value
I have done everything I can to avoid any kind of search box but the URL remains what I wrote in my previous message.
OK understood; let me look at the code again. Sounds like it’s not using a modified URL as it should.
Thanks @TAustin!
BTW you may want to add the PurpleAir driver to the list of the EdgeBridge supported drivers here:
DRIVER UPDATE NOTICE
Name: PurpleAir AQI v1.2
Version: 2023-09-26T20:00:52.409059033
Channel: Shared Projects
Driver Update: Thanks to recommendation from @WindBoarder, I’ve changed the API endpoint used for single-sensor configurations (search option disabled) to minimize API points usage. Point usage for search boxes remains the same.
Please also note that I am moving this driver to my regular shared projects channel. So everyone gets this update, I’ve updated it to both my shared projects AND my driver tests channel where it has been. I’ll remove it from the test channel in a couple weeks.
@TAustin thanks so much for implementing the API change!
I had to go enroll in your shared projects channel (I was in the test channel), then the drivers were updated and I see the new API style calls. I will monitor the API accounting for a couple of days to confirm that all is well.
@TAustin I confirmed now, after a few days of checking the PurpleAir API accounting reports, that the API points usage for single sensor queries has been successfully reduced from 11 points per call to 4 points per call.
Thanks again for making this change! This will allow users to get a lot longer use out of their free 1 million PurpleAir API points!
Terrific! Thanks for the follow-up. ![]()
I do wish I could get this working. Sadly, even after following all steps and directions the console of the edge driver app always reports 403.
Hi - this sounds like a key issue. Assuming you got your assigned key, did you also follow the steps pointed to in this post? You have to take another step to actually assign your key to a ‘project’ within the PurpleAir dashboard.
You can direct message me screenshots of your SmartThings device Settings screen in case there is something there that is causing the problem.
Thanks for the reply. I did assign the key properly but then I realized I messed up something even more basic: I had accidentally pasted that key into the bearer token field of the cfg file for the edge driver and not the samsung bearer token. Once I did that I was able to get updates. The only thing that doesn’t populate for me is the tvoc field, but that’s not as important as the general AQI number and category. (though if you know why this happens I’d appreciate the info)
Glad you got things working.
Regarding TVOC, the PurpleAir site indicated this is still some kind of pilot test field, so it may not be available from all sensor sites. Try some other sensors or use the PurpleAir map to find a site that is showing values for it.
Hi,
Question to the errors some of you guys received. Using this driver with the edgebridge running, cannot get any data displayed - only: “There was a problem connecting, try again later”
Edgebridge log:
Tue May 7 12:30:38 2024 GET request received from: ('192.168.1.xxx', 50326)
Tue May 7 12:30:38 2024 Sending GET to https://api.purpleair.com/v1/sensors?nwlng=19.405351922681&nwlat=50.719699938392&fields=name,pm2.5_60minute,latitude,longitude,confidence&max_age=3600&selng=20.306448077319&selat=49.321300061608&location_type=0
Tue May 7 12:30:38 2024 Response returned to Edge driver (bytes len=293)
LOGS from smartthings cli:
2024-05-07T10:34:50.046262207Z DEBUG PurpleAir AQI v1.2 Response:
{
“api_version” : “V1.0.13-0.0.56”,
“time_stamp” : 1715078089,
“data_time_stamp” : 1715078072,
“location_type” : 0,
“max_age” : 3600,
“firmware_default_version” : “7.02”,
“fields” : [“sensor_index”,“name”,“latitude”,“longitude”,“confidence”,“pm2.5_60minute”],
“data” : []
}
2024-05-07T10:34:50.050948707Z ERROR PurpleAir AQI v1.2 PurpleAir v1.2 thread encountered error: [string “st/dispatcher.lua”]:261: Error encountered while processing event for <Device: 1caa916b-529e-40be-9e5c-5559ec357ca3 (Air quality sensor)>:
arg1: table: 0x1189c50
“[string “st/capabilities/init.lua”]:226: Invalid value for purpleaqi.aqi value: {value=-1} error: Given -1 for value. Outside bounds: min: 0 max: 1000”
I don’t see a PurpleAir API key in your GET request. Without a valid and funded API key, PurpleAir will not return any data. Just my guess on this. Don’t share your API key online.
When I click into the the PurpleAir device on SmartThings for a single sensor call, I get 3 fields of data. The sensor sites used field seems to be misbehaving and showing raw HTML text instead of the name of the sensor. This field used to behave properly but I don’t know exactly when this bug started showing up.
AQI Value: 16 AQI
AQI Category: Good
Sensor sites used:
<!DOCTYPE html>
<HTML><HEAD>..."
Are other people seeing this behavior?
Note: I did verify with an independent curl call that the API call does work correctly and return a name field with the correct sensor name.
Cause it is probably sent via header not via QueryString.
BTW - it is working properly, turns out i don’t have any purple air sensor near me in my city. The two I see on the live map are indoor (5km distance). Once I changed radius to 200km, started to pickup data from other - this time outdoor.
No driver issues, sensor availability issue ![]()