How to activate an Automation based on BOTH (of two) sensors?

How might I set an Automation to only action when two separate numeric value sensors are both above a certain value?

If I put both sensors in under Trigger or under Condition, the Automation fires if only one sensor is activated.

TIA

Just add a condition and test if both sensors are above a value:

  trigger:
  - platform: numeric_state
    entity_id: sensor1
    above: 50
  - platform: numeric_state
    entity_id: sensor2
    above: 50
  condition:
  - condition: numeric_state
    entity_id: sensor1
    above: 50
  - condition: numeric_state
    entity_id: sensor2
    above: 50

So it will only fire if the second one gets over the value.

Or you could use a template trigger:

trigger:
  - platform: template
    value_template: "{{ (states('sensor.sensor1') | int(0) > 50) and (states('sensor.sensor2') | int(0) > 50) }}"
1 Like

Many thanks @madface & @dennis84de - tried the two methods and neither worked for me.

Focusing in on the template version, the following “works” if I run the automation, but not if both sensors are triggered, so presumably it is the triggering not the action that needs tweaking.

- id: '164538xxxxxx36'
  alias: Bed Sensor TEST
  description: ''
  trigger:
  - platform: template
    value_template: '{{ (states(''sensor.black_green'') | int(0) > 2) and (states(''sensor.blue_red'')
      | int(0) > 2) }}'
  action:
  - type: turn_on
    device_id: 8xxxxxxxxxxx0b06f10e821c3b06d
    entity_id: light.jjb
    domain: light
    brightness_pct: 100
  - device_id: 481d2fxxxxxxxx2692186198
    domain: light
    entity_id: light.cmb
    type: flash
  mode: single

This is what the sensors show when not triggered; the value goes to just over 3 when triggered, hence me using a value of 2 in the automation. The sensors update their values once every 10 seconds.

Any thoughts?

TIA

Have you tried adding the two sensors to a group:

Its a bit of a long way round but you could create a binary_sensor for each of your sensors which turns on when the original sensor is 2. Put the binary sensors in the group and set all:true. You can then use the group as the trigger for your automation.

1 Like