Air Quality Automation

I currently use the following to let me know the air quality. It has been working fine but today because of the heat 109 degrees and an inversion layer the AQI went up to 85ish and I had an asthma attack because of it.
I would like to be notified when it hits certain ranges so from 50 to 55, 56 to 60 and so on. I have been fighting with this for a few hours before posting this.
Can some one help?

- id: '1579536149087'
  alias: AQI Warning
  description: ''
  - above: '50'
    entity_id: sensor.u_s_air_quality_index
    platform: numeric_state
    condition: time
    after: '07:00:00'
    before: '21:00:00'

  - data:
      message: Airvisual AQI is getting worse! It's above 50!
    service: notify.telegram_carlton

  - service: notify.alexa_media
        - media_player.alexa_bedroom
        - media_player.alexa_garage
        - media_player.alexa_greatroom
        - media_player.alexa_office
        type: announce
      message:  "Airvisual AQI is getting worse! It's above 50!"

You could try adding multiple triggers:

  - above: '50'
    entity_id: sensor.u_s_air_quality_index
    platform: numeric_state
  - above: '55'
    entity_id: sensor.u_s_air_quality_index
    platform: numeric_state
  - above: '60'
    entity_id: sensor.u_s_air_quality_index
    platform: numeric_state

I would expect the automation to trigger each time the sensor value goes above any of the specified values.

In your action you would then need to change from a fixed message to a message template that uses the actual sensor value.

      message: "Airvisual AQI is getting worse! It's now {{ states('sensor.u_s_air_quality_index') }}!"

Thank you for the quick reply.
The information that you sent me works out well.
Was able to get it restarted in about 10 minutes.
Again thanks.

check here, I had a go to this myself earlier this week, not really sure if the template does its job though. …;-0

so be careful if your health depends on it.

You are a genius.
Why could I not find this when I searched the forums yesterday.
This is exactly what I want.
This will help me stay better informed of the air quality along with a few other pieces of data I follow.
Thank you so much.

I have been playing with this for a few hours, and need some help if you do not mind.
I have now seen a few other posts you did about this and I think that is what confused me.
What do you have as the automation, and what do you have as a sensor (using mapper?)
Also if the aqi is on a scale as displayed on the aqi page how is that related to the trigger.
Having never used mapping before that is what I think is throwing me off.
Again appreciate the information.

this is my automation (and as stressed , I am not 100% positive the mapper template in the message works as it is)

  - alias: Aqi Alert
    id: 'Aqi Alert'
      - platform: state
        entity_id: sensor.chinese_air_pollution_level
      - platform: state
        entity_id: sensor.us_air_pollution_level
    condition: []
      service: notify.notify
        title: >
         {{as_timestamp(now())|timestamp_custom('%X')}} : Aqi Alert!
        message: >
          {% set mapper = {'Good':'5','Moderate':'4','Unhealthy for Sensitive Groups':'3',
                           'Unhealthy':'2','Very unhealthy':'1','Hazardous':'0'} %}
          {{}} {{'improved'
          if mapper[trigger.to_state.state] > mapper[trigger.from_state.state]
           else 'deteriorated'}} from {{trigger.from_state.state}} to {{trigger.to_state.state}}
          {% set url = '' %}
          Check [your local Air quality station]({{url}}) for more info

the state of the sensor is 1 of the listed conditions:

which the mapper transforms to a number. In the if then else I compare the to_state to the from_state, and based on it being either smaller or larger than the from_state output the change.
At least that’s is what it is supposed to to :wink:

it triggers on each state change of both sensors.


found the reason for not triggering just now! a type in the u_s_pollution_level trigger…

as for the sensors:

configured via the UI