Turn lights off only if none of three motion sensors is triggered

I’ve set up a rule to turn the lights on and off based on three motion sensors. It works fine for turning it on:

  trigger:
    platform: state
    entity_id: binary_sensor.homematic_motion_sensor_motion, binary_sensor.homematic_switch_1_motion, binary_sensor.homematic_switch_2_motion
    to: 'on'

but not correctly for turning it off:

  trigger:
    platform: state
    entity_id: binary_sensor.homematic_motion_sensor_motion, binary_sensor.homematic_switch_1_motion, binary_sensor.homematic_switch_2_motion
    to: 'off'
    for:
      minutes: 2

Even if I move within the range of one sensor, the lights turn off after two minutes. I guess I created a rule where ALL sensors have to be triggered to prevent the light from turning off. How do I change this so it doesn’t matter which sensors are triggered within the given time frame?

The trigger for the second automation is telling Home Assistant to turn off the lights if ANY of those motion sensors goes to off for 2 minutes, regardless of which motion sensor actually turned the lights on.

What do you want to actually happen? We can probably help you modify your automations.

All three motion sensors are in the hallway and turn on the hallway-light. I want the light to stay on as long as a person is there. In other words, turn the light off if no motion is detected for two minutes from any of the sensors.

That’s what those automations are currently doing. If any of those motion sensors goes to off for two minutes, it will turn the light off. Similarly, if any of those motion sensors goes to on, it will turn the lights on.

Triggers are OR by default, so when you list multiple triggers or multiple entities in a trigger, the action will fire if ANY of the triggers happens.

Maybe I phrased it wrong… :slight_smile: I want the light to turn off if none of the sensors detect any motion for two minutes. So more like AND than OR.

Ah, gotcha. Try this for the turn off automation:

  trigger:
  - platform: state
    entity_id: binary_sensor.homematic_motion_sensor_motion, binary_sensor.homematic_switch_1_motion, binary_sensor.homematic_switch_2_motion
    to: 'off'
    for:
      minutes: 2
  condition:
  - platform: state
    entity_id: [motion sensor 1]
    state: 'off'
  - platform: state
    entity_id: [motion sensor 2]
    state: 'off'
  - platform: state
    entity_id: [motion sensor 3]
    state: 'off'

Change [motion sensor x] to each motion sensor entity ID.

You could also use a template trigger, but I don’t have time to type that one out, so I’ll provide the docs for it. :wink:

Create a group called group.hallway_motion containing the three binary_sensors.

  • The group’s state will be on when any of its members is on.
  • The group’s state will be off only when all of its members are off.

Change the trigger to:

  trigger:
  - platform: state
    entity_id: group.hallway_motion
    to: 'off'
    for:
      minutes: 2
3 Likes

Ah yeah, that’s a more elegant solution. I overthought it a bit :crazy_face:

Thanks guys, I will try the group-solution. Didn’t know this existed :slight_smile: Edit: Working fine!