Jump to content

Programming Assistance For Purple Air


dbuss

Recommended Posts

Posted

I have the program below to alert me when the EPA AQUI is over 100. It works fine. Right now I get continuous updates as long as the AQUI is over 100. I would like to change the program so I get notified once when AQUI goes over 100 and then again when the AQUI goes under 100. . Here's my current program.

EPA AQUI Greater Than 100 - [ID 0088][Parent 0001]

If
        'Polyglot / Purple Air AQI / Outside' EPA AQI > 100
 
Then
        Send Notification to 'Email' content 'EPA AQUI Greater Than 100'
 
Else
   - No Actions - (To add one, press 'Action')

Thank you!

Posted

Someone else may be able to provide a better solution, but I believe you need to set a flag (variable) and use that to trigger the notification.  Something like:

if AQI > 100  then high_aqi = 1
else high_aqi = 0

and a second program

if high_aqi = 1 then send notification

The problem you're having is that every time the AQI changes, it triggers the if condition to re-evaluate.  By using a variable, the variable only changes when the AQI goes over 100 or under 100.  

  • Like 1
Posted

I'll suggest a couple of improvements to the programs:

First it should be noted that when the variable is created it should be a State Variable.  Using an Integer Variable would not trigger the second program

I don't know how fast the AQI is updated but to prevent repeated notifications I would break the first program above into two

if AQI > 100  then high_aqi = 1

and

if AQI < 97  then high_aqi = 0

then for the second program:

if high_aqi = 1 
  then send high_notification
  else send low_notification
Posted

This may be overkill for you, but I decided I wanted to know if the AQI was increasing or decreasing.  I have two thresholds, T1=50, T2=100.  I am notified whenever the AQI goes above or below a T.  My notification might be, for example, "the AQI in [city] increased above 50 to 62."

So, to do this, I needed variables to store the current/new AQI and the previous AQI.  By comparing the two, I can tell whether it is increasing or decreasing, and by comparing it to the threshold, which is also a variable, i can tell whether it went above or below the T.

I used state variables, except for the previous AQI. To set the previous AQI, I simply evaluated the current AQI, waited 15 seconds, during which my comparison programs would run and my notifications would trigger, and then set the previous AQI to equal the current. The previous AQI is then available for the next evaluation.

I did this for sensors in three different cities. I needed four network resources for notifications in each city (increasing T1, increasing T2, decreasing T1, decreasing T2).

 

Posted
39 minutes ago, maxnorth said:

This may be overkill for you, but I decided I wanted to know if the AQI was increasing or decreasing.  I have two thresholds, T1=50, T2=100.  I am notified whenever the AQI goes above or below a T.  My notification might be, for example, "the AQI in [city] increased above 50 to 62."

So, to do this, I needed variables to store the current/new AQI and the previous AQI.  By comparing the two, I can tell whether it is increasing or decreasing, and by comparing it to the threshold, which is also a variable, i can tell whether it went above or below the T.

I used state variables, except for the previous AQI. To set the previous AQI, I simply evaluated the current AQI, waited 15 seconds, during which my comparison programs would run and my notifications would trigger, and then set the previous AQI to equal the current. The previous AQI is then available for the next evaluation.

I did this for sensors in three different cities. I needed four network resources for notifications in each city (increasing T1, increasing T2, decreasing T1, decreasing T2).

 

That's very interesting, @maxnorth. Thank you!

  • 3 weeks later...
Posted (edited)

@bpwwer, @MrBill, @maxnorth Using the information you all provided, I have grouped the AQI  readings in 25 point ranges from 0 to 175. Whenever it changes from one range to another I am notified. It's working as intended. Thanks again for your insight.

Here is an example of my programs.

Program 1

EPA AQUI 100-125 - [ID 008E][Parent 0001]

If
        'Polyglot / Purple Air AQI / Outside' EPA AQI > 100
    And 'Polyglot / Purple Air AQI / Outside' EPA AQI < 126
 
Then
        $Aqui_100_125  = 1
 
Else
        $Aqui_100_125  = 0

Program 2

AQI 100-125 Notification - [ID 0094][Parent 0001]

If
        $Aqui_100_125 is 1
 
Then
        Send Notification to 'Email' content 'EPA_Aqui_100_125'
 
Else
   - No Actions - (To add one, press 'Action')
 

 

Edited by dbuss
  • Like 2
Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...