Announcement

Collapse
No announcement yet.

Purple Air

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Purple Air

    Hello to all
    I have been using purpleair.exe by dzee for the last 3-4 years. Working great up until 5/26/2022, when it stopped giving me data.
    Looking at things, it looks like Purple Air changed things and now the exe give a 500 error.
    I don't know if this has happened for others, but I'd like to get back up and running somehow.
    I don't know if I just need to change a URL or what.
    Any help would be appreciated
    Thanks
    Bruce (Dbvanb) - I am running on linux with mono 6

    #2
    Yes. PurpleAir deprecated the json and data.json endpoints on 5/26/2022. You now have to request an API key in order to access sensor data. The old endpoints re-direct to a non-existent service, thus the 500 error.

    https://community.purpleair.com/t/di...-json-urls/713

    I just got around getting my API key yesterday and I'm working on a Node-RED polling implementation.

    I'll post the updated version here: https://forums.homeseer.com/forum/ho...59#post1553559
    "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

    Comment


      #3
      I had done a Purpleair integration with mcsMQTT in the past. While the specific URL data has changed with the new API key, the approach remains the same with a setup on the URL tab of mcsMQTT and then the decoded JSON available on the Association tab for mapping desired items into HS Device Features.

      Comment


        #4
        I used mcsMQTT for a while before I decided to start playing with Node-RED. One additional thing that's changed is that they ask you to request the data for multiple sensors in a single request. At least for me this definitely complicates the parsing of the JSON data.

        I'm using the 'https://api.purpleair.com/v1/sensors' endpoint with the show_only parameter with a list of sensor_index values to return. The returned JSON data contains an array of arrays with the sensor data.
        "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

        Comment


          #5
          Makes no difference to mcsMQTT with an array of arrays. This actually was the primary reason I transitions to Newtonsoft library rather than the native code parsing. The cloud providers have much more complex JSON structures than the typical microcontroller that was the genesis of mcsMQTT. The time it can become a problem is if PurpleAir changes the order of the sensors in the array. The default parsing uses the array index. The elevate key capability of mcsMQTT often is able to deal with it and keep identication in sync.

          I have not gone back to get an API key as I do not use the PurpleAir data. I just observed that the change on their end was minor with respect to being able to get the desired data.

          When I first did this, I had setup a .pub file that lists the individual URL requests. This same approach can still be used and avoid nested arrays.

          Node-Red is a fine way to handle data and build logic trees. As with many things the casual HS users is intimidated by the learning curve, even though in the end it opens capability that may not otherwise be available.

          Comment


            #6
            Thanks for the information, Kenm and Michael.
            now I have an idea what to do to get going again.
            Some work to do.
            Bruce

            Comment


              #7
              Michael McSharry .Pub lists are something they are asking us not to use anymore. Instead of making multiple single sensor requests, they are asking us to make a single request for data from multiple sensors. They return 2 arrays. The first array is called "fields" and each element is the name of the data values being returned. Think of this as the column header in a spreadsheet. The second array is 2-dimensional. Think of this as the rows of data being returned with the order defined by the fields array. They DO NOT guarantee the data will be in the same order every time, only that it will match the fields array. Makes positional parsing very fragile.
              "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

              Comment


                #8
                Just to update
                Went to purpleair api and got my key - pretty easy, they send it to an email
                I was able to see the data come in in a terminal using the curl command:
                curl -X GET https://api.purpleair.com/v1/sensors/xxxxx -H "X-API-Key:................................."

                Then went to mscMQTT URL tab and entered the data:
                URL
                https://api.purpleair.com/v1/sensors/xxxxx
                Additional Headers
                X-API-Key:................................

                Then I was unsure if I needed to go to the general tab and turn on discover of topics, but
                all the topics appeared in the association tab sorting for api.purpleair.com under T2 (topic 2)
                There were 135 topics.
                I have associated 3:
                "pm2.5" - current value
                stats "pm2.5_24hour" - 24 hour average for calculating or assigning a virtual device to the AQI from a table
                "voc" - volatile organic compounds

                These correlate well with some other sensors I have, esp a CCS811 CO2 and VOC sensor running on an ESP32
                I also compared the value in mcsMQTT to what I get at the command line using CURL and they match

                So I am happy.
                Again Thanks for the help from Michael McSharry and kenm

                Now just need to do the script to give me the AQI value, but I am happy with the raw pm2.5 data as well

                Bruce


                Comment


                  #9
                  Here's the script I used to convert PM2.5 (and now PM10) to AQI before I moved the whole thing to Node-RED.

                  The script takes 2 devref parms (devref1:devref2). The first is the device that holds the PM value and the second is where you want to store the AQI value.

                  Let me know if you have any questions.

                  Ken

                  EDIT: Updated Script to Add PM10toAQI in addition to PM25toAQI subroutine. Both take the same parameters.
                  Attached Files
                  "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

                  Comment


                    #10
                    kenm do you by any chance have a script for computing PM10 AQI (https://forum.airnowtech.org/t/the-aqi-equation/169) ?

                    Comment


                      #11
                      Originally posted by mda View Post
                      kenm do you by any chance have a script for computing PM10 AQI (https://forum.airnowtech.org/t/the-aqi-equation/169) ?
                      Not yet, but I'm happy to put something together. Let me take a look at it in the morning.
                      "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

                      Comment


                        #12
                        mda - I attached the updated script in my post above.

                        Added PM10toAQI in addition to PM25toAQI.
                        "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

                        Comment


                          #13
                          Originally posted by kenm View Post
                          mda - I attached the updated script in my post above.

                          Added PM10toAQI in addition to PM25toAQI.
                          Thanks!!!

                          Comment


                            #14
                            Kenm
                            Thanks +1

                            Comment


                              #15
                              Let me know if you find any problems or need changes. I'm just getting around to adding it to the Node-RED flow and realized that I never posted the updated NR flow that supports the API key. I'll get that done this weekend.
                              "if I have seen further [than others], it is by standing on the shoulders of giants." --Sir Isaac Newton (1675)

                              Comment

                              Working...
                              X