WAQI-based automation not firing as expected

Hi folks. I’ve got a light strip by my door, light.door_lights, that I’d like to turn on to a color (as specified) when AQI is between a specific range. I have tried both the native WAQI integration as well as the HACS WAQI integration - it doesn’t seem to make a difference either way. Here’s my automation:

alias: AQI Door Lights
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.air_quality_index
    above: 0
    below: 50
    id: Good
  - platform: numeric_state
    entity_id: sensor.air_quality_index
    above: 51
    below: 100
    id: Moderate
  - platform: numeric_state
    entity_id: sensor.air_quality_index
    above: 101
    below: 150
    id: Unhealthy for Sensitive Groups
  - platform: numeric_state
    entity_id: sensor.air_quality_index
    above: 151
    below: 200
    id: Unhealthy
  - platform: numeric_state
    entity_id: sensor.air_quality_index
    above: 201
    below: 300
    id: Very Unhealthy
  - platform: numeric_state
    entity_id: sensor.air_quality_index
    above: 301
    id: Hazardous
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Good
        sequence:
          - service: light.turn_on
            data:
              color_name: green
              brightness_pct: 10
            target:
              entity_id: light.door_lights
      - conditions:
          - condition: trigger
            id: Moderate
        sequence:
          - service: light.turn_on
            data:
              color_name: yellow
              brightness_pct: 10
            target:
              entity_id: light.door_lights
      - conditions:
          - condition: trigger
            id: Unhealthy for Sensitive Groups
        sequence:
          - service: light.turn_on
            data:
              color_name: orange
              brightness_pct: 10
            target:
              entity_id: light.door_lights
      - conditions:
          - condition: trigger
            id: Unhealthy
        sequence:
          - service: light.turn_on
            data:
              color_name: red
              brightness_pct: 10
            target:
              entity_id: light.door_lights
      - conditions:
          - condition: trigger
            id: Very Unhealthy
        sequence:
          - service: light.turn_on
            data:
              color_name: purple
              brightness_pct: 10
            target:
              entity_id: light.door_lights
      - conditions:
          - condition: trigger
            id: Hazardous
        sequence:
          - service: light.turn_on
            data:
              color_name: maroon
              brightness_pct: 10
            target:
              entity_id: light.door_lights
mode: single

Side note: I’ve tried this as a standalone automation, and then one that’s only turned on and triggered when motion is sensed by a nearby motion sensor. Doesn’t work either way.

Is there a smarter/better way to be doing this?

Could specify what is actually not working as expected, i.e. “with air_quality at X, the automation does B rather than A”.

The only obvious issue is that an index at, e.g. “50” or “51” won’t trigger as you use “below 50” and “above 51”, which are “extreme excluded”

Sorry, but I’m not sure how to explain what you’re looking for as it’s not doing anything. To elaborate: right now the AQI is 20, which in theory should make the lights green. They’ve not turned on, let alone turned any colors.

Here’s a trace.

Is there a better way to be trying to achieve this?

Not quite.
Automations work with triggers. Meaning if your AQI didn’t went from, e.g. “above 51” to “below 50” since last time HA was restarted, it is actually expected that nothing was triggered.

I assume your trace is from a manual triggering of the automation, as I don’t see the sensor value having changed (and thus no trigger id being set)

Rather than using trigger ids, you might want to move your numeric_state tests directly to your conditions, with your trigger being simply

trigger:
  - platform: state
    entity_id: sensor.air_quality_index
  - platform: homeassistant
    event: start

meaning the automattion will be triggered for every change of the sensor. Additionally, the automation will be triggered at HA start for the initial assessment/color.

Okay, I follow what you’re saying.

Will experiment with that and circle back to let you know if that solved my issue.

Thank you for your help thus far!

That did the trick - one additional question, because I don’t want to mess it up playing with it. :joy:

If I add a condition that the motion sensor there is detecting motion, can I then add a choice that if it’s not detecting motion, to turn off the lights?

Or would that be better as a separate automation (that makes this one the secondary) so that if motion is sensed, it enables the AQI Light automation (and triggers it?) … but if no motion, it disables that AQI Light automation?

Sorry for the (probably stupid) question.

Did what I was looking to do with a second automation. Motion triggers the AQI light automation. Absence of motion turns the lights off. :grinning:

Thank you again!!