Trying to create an automation with three Motion sensors

I have three motion sensors. How would I create an automation where if all three stop detecting motion for 5 minutes the light would turn off?

All three must stop detecting motion for the light to turn off.

If any one of the three detects motion the light stays on.

Put all three into a group.

Do I toggle all entities on?

Group them as a binary senor group. Then if one is ON it acts like all are ON

No.

The “all” toggle means if any of the three stop detecting the group entity will turn off.

If you leave it turned off, then all the sensors have to be at “no motion” before the group entity will turn off.

Thank you! I’ve been trying to figure out what this means and I couldn’t grasp the concept.

Did I do this right for my other automation?

I do this

- id: tr_study ms off
  alias: tr_study ms off
  trigger:
    - platform: template
      value_template: "{{ is_state('binary_sensor.tr_motion_motion_detected','off') and is_state('binary_sensor.tr_sensor_motion_detected','off') }}"
      for: "00:01:00"
  condition:
    condition: and
    conditions:
      - "{{ is_state('binary_sensor.away_mode','off') }}"
      - "{{ states('input_boolean.lt_tr_study_control_enable') == 'on' }}"
      - "{{ is_state('light.tr_study','on') }}"

I do not quite understand how to use templates or input booleans yet.

In your code, you used a template combined two actions? Both motion sensors have to be off for one hour.

I don’t understand your conditions.

You need an Or for your Time and Sunrise conditions since both have a limit at midnight.
The Time condition will be true from 11pm to midnight, the Sunrise condition will true from midnight until sunrise… for all practical purposes there is no point in time where both will be true, so And is the wrong building block.

The for: “00:01:00” means they both need to be off for 1 minute.

I posted a working automation that I use, which parts are relevant is up you.

The conditions I have:

  1. If the house is in away mode then I do not want light automations
  2. For each light control loop I have an input_boolean to enable, so if my light automation is malfunctioning (maybe the motion sensor is flaking out) I can turn it off
  3. If the light is already off, then there is nothing to do. This commonly occurs because the light gets turned off manually. So there is no point in sending a command (in my case to a zwave switch).

I think the key thing missing is mode: restart :thinking:

alias: motion
description: “”
trigger:
  - platform: state
    entity_id:
    - binary_sensor.downstairshallwaymotion1
    from: 'off'
    to: 'on'
  - platform: state
    entity_id:
    - binary_sensor.downstairshallwaymotion2
    from: 'off'
    to: 'on'
  - platform: state
    entity_id:
    - binary_sensor.downstairshallwaymotion3
    from: 'off'
    to: 'on'
  condition:
  - condition: or
    conditions:
      - condition: time
        after: "23:00:00"
      - condition: sun
        before: sunrise action:
  - service: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.light_ downstairshallway
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.light_downstairshallway
  mode:  restart

That will turn off the lights even if one motion sensor is still detecting motion. And it will turn the light back on (for example they have been turned off manually) when the motion sensor clears.

The time stops at midnight for automations? I had no idea. I thought it ran on a 24 hour time period.

Because of this I would want to start with
Or-the building block
Confirm the time is after 11pm
Confirm the time is before sunrise

Or do I do this?
Confirm the time is after 11pm
Or-the building block
Confirm the time is before sunrise

Do the conditions run in order from top to bottom?

What happens if you have the following with no building blocks?

Condition 1
Condition 2

If you have multiple conditions you should always start with a building block? And, Not, Or?
Then you would join the conditions together?

For example,

And-the building block
Condition 1 TRUE
Condition 2 TRUE

no…if another detector is detecting motion, it will stop the current running action, and start a new one
(what i said, missing here is mode:restart)

1 Like

I’m reading this to better understand the mode Automation modes - Home Assistant

Is this the mode not available in the GUI for automations?

I find configuring automations by hand easier since I can read it line by line. I am still figuring out what all the lines of code mean

I have been using the GUI for simple automations. However, I find more advances ones easier to learn by typing out the code

yes it is, 3 dots upper right corner “change mode”

This one:

condition:
  - condition: or
    conditions:
      - condition: time
        after: "23:00:00"
      - condition: sun
        before: sunrise

They are checked in sequence from top to bottom.

The way that is evaluated (and the only logical way to do it) is the same as using an And

You never need to use an explicit And unless you are combining conditions inside an Or or Not.

The midinight limits on Time and Sunrise conditions are clearly stated in the docs:

Time:

Sunrise/Sunset:

I do not understand input booleans yet, I have been reading Input Boolean - Home Assistant to try and understand more.

Why did you use the input_boolean in your code?

Thank you!