Problems triggering automation based on sensor data

I have been trying to automate the control of one of my air purifiers based on the detected VOC levels from my sensors.

The only automation of these three that triggers is ’ VOCs Safe’, and it triggers multiple times a day. However VOC Unhealthy never triggers.

Given that these automations trigger on crossing a threshold, how does ‘VOCs Safe’ repeatedly trigger, yet ’ VOCs Unhealthy’ never triggers? :face_with_raised_eyebrow:

alias: VOCs Safe
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.e_s_device_tvoc
      - sensor.airthings_wave_mini_079396_voc
    above: 0
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: 1499
condition: []
action:
  - service: notify.persistent_notification
    metadata: {}
    data:
      message: VOCs under 1000,  Changing Winix back to auto
      title: VOCs under 1000
  - service: fan.set_preset_mode
    target:
      entity_id: fan.winix_bedroom
    data:
      preset_mode: Auto
mode: single
alias: VOC Unhealthy
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.e_s_device_tvoc
      - sensor.airthings_wave_mini_079396_voc
    above: 1500
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition: []
action:
  - service: notify.persistent_notification
    metadata: {}
    data:
      message: " Changing Winix to medium"
      title: VOCs over 1000
  - service: fan.set_percentage
    target:
      entity_id:
        - fan.winix_bedroom
    data:
      percentage: 75
mode: single
alias: VOCs Dangerous
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.e_s_device_tvoc
      - sensor.airthings_wave_mini_079396_voc
    above: 2500
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition: []
action:
  - service: notify.persistent_notification
    metadata: {}
    data:
      message: " Changing Winix to ultra high"
      title: VOCs over 2500
  - service: fan.set_percentage
    target:
      entity_id:
        - fan.winix_bedroom
    data:
      percentage: 100
mode: single

OK well my first lesson is that it’s not even triggering by crossing the upper threshold, it’s triggering from unavailable to having a reading.

So it’s not actually working at all for thresholds even though I can clearly see from statistics graphs that it’s going over and under the threshold between my first two automations

  from_state:
    entity_id: sensor.airthings_wave_mini_079396_voc
    state: unavailable
    attributes:
      state_class: measurement
      unit_of_measurement: ppb
      device_class: volatile_organic_compounds_parts
      friendly_name: Airthings Wave Mini (079396) VOCs
    last_changed: '2024-05-02T16:29:52.288517+00:00'
    last_reported: '2024-05-02T16:29:52.288517+00:00'
    last_updated: '2024-05-02T16:29:52.288517+00:00'
    context:
      id: 01HWX28390RKBKREMMZ6SY0KRN
      parent_id: null
      user_id: null
  to_state:
    entity_id: sensor.airthings_wave_mini_079396_voc
    state: '136.0'
    attributes:
      state_class: measurement
      unit_of_measurement: ppb
      device_class: volatile_organic_compounds_parts
      friendly_name: Airthings Wave Mini (079396) VOCs

You can use a template condition to prevent the automation from running when the state changes from unavailable:

condition:
  - condition: template
    value_template: "{{ trigger.from_state.state != 'unavailable' }}"

As for the others not triggering, perhaps remove the for config and see if that helps.

1 Like

Have you tried it with two separate triggers, rather than one trigger with two entities?

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.e_s_device_tvoc
    above: 1500
  - platform: numeric_state
    entity_id:
      - sensor.airthings_wave_mini_079396_voc
    above: 1500

I’ve thought about it but I think I would rather create a template sensor that calculates the maximum of both, so that I don’t need to turn 3 automation into 6 automation.

You can have multiple triggers in the same automation. If any one fires, it will run. You can also combine your existing 3 automations into one using trigger ids and a choose action based on a trigger condition.

2 Likes