Turn off presence based on the combined trigger of two sensors?

Hi there,

i would like to turn off “input_boolean.my_presence” when two sensors are not seeing anyone for more than 1min. Basically, i need two trigger to be “AND” which i can’t do.

The trick i’m using now goes as follows: I’m triggering the automation every 20s and i’ve put both sensors into the condition field (condition: they are not seeing anybody for more than 1min). Is there any better way?

alias: Presence OFF
trigger:
  - platform: time_pattern
    seconds: /20
condition:
  - type: is_no_motion
    condition: device
    device_id: c210f5c48797ba99xxx
    entity_id: binary_sensor.room_hue_motion_motion
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - type: is_not_occupied
    condition: device
    device_id: 3bb32e75f622d07xxx
    entity_id: binary_sensor.room_aqara_fp1_2_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 1
      seconds: 0
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id:
        - input_boolean.my_presence
mode: single

The way to do this is two state triggers and two state conditions. Triggers are always OR logic, but conditions are AND logic by default (this can be changed).

So either trigger will start the automation but it won’t pass the conditions unless both entities are in the required state.

alias: Presence OFF
trigger:
  - platform: state
    entity_id: binary_sensor.room_hue_motion_motion
    to: 'off'
    for:
      minutes: 1
  - platform: state
    entity_id: binary_sensor.room_aqara_fp1_2_occupancy
    to: 'off'
    for:
      minutes: 1
condition:
  - condition: state
    entity_id: binary_sensor.room_hue_motion_motion
    state: 'off'
    for:
      minutes: 1
  - condition: state
    entity_id: binary_sensor.room_aqara_fp1_2_occupancy
    state: 'off'
    for:
      minutes: 1
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id:
        - input_boolean.my_presence
mode: single
1 Like

Ah, that was too simple! Thanks a lot @tom_l for the elegant solution.

1 Like