Binary sensor template combining two motion sensors

  - platform: template
    sensors:
      bathroom_light:
        value_template: "{{ is_state('binary_sensor.motion_sensor_158d0001e552f3', 'on') or is_state('binary_sensor.motion_sensor_158d0001e542bc', 'on') }}"

Should this = on in all these situations

  sensor A = on and sensor B= on
  sensor A = on and sensor B= off
  sensor A = off and sensor B= on

and off in just this situation

  sensor A = off and sensor B= off
``

i created a timer for how long my light should stay on after motion is detected.
then created an automation for each sensors.
automation 1 when motion is detected sensor A:

  • cancel timer
  • start timer
    automation 2 when motion is detected sensor B:
  • cancel timer
  • start timer
    automation 3 when no motion is detected by both sensor A and B:
  • timer.finished as trigger
  • sensor A and sensor B are off as conditions

it’s not perfect but works for me. i’m hoping someone could improve it.

Any one know the answer

I need a template that is true when A or B OR A & B are triggered by motion. Does the above template match that?

still no one, guessing it this is not possible.

The simple logical “or” should handle those cases. Or means “if at least 1 of the specified conditions are true, then it’s true”

The logic you’re applying sounds correct.

2 Likes

but does it mean true for when both sensors are on?

Yes. Or means “one or more” of the specified conditions.

Both on is still one or more of them on.

A real world comparison, if it’s cold or rainy, you wear a jacket. If it’s cold you wear a jacket, if it’s rainy you wear a jacket, if it’s both you wear a jacket.

The same thing applies with this on/off “or” statement.

1 Like