Need help with proper lights automation

Looking for advice to make my garage lights automation better.

I have two doors with sensors and two motion sensors inside the garage.
My current automation is set to “restart” mode and simply does the following:

  1. When motion is sensed or any of the doors open the light goes ON
  2. Delay 5 minutes
  3. Turn off the lights

It works well, but the only case I am struggling with is when lights are switched off manually — when someone exits the garage. Don’t want them to stay on for another 5 minutes in such a case.
With current automation, if I turn off the light and exit, the lights will go back on obviously. Even if I open the door first, the motion sensor can still pick me up leaving.

Ideas?
Thanks.

Why not just turn off the lights after detecting there’s been no motion for a minute? (Instead of after a fixed duration of 5 minutes.)

Has to do with the sensitivity of motion sensors. E.g. if I am doing something focused in one spot of the garage, the sensors will report ‘no motion’ and the lights will go off. Thus, I’ve extended the interval to give the sensors more time to pick up motion and extend the lights being on.

The sensors, by the way, have their own setting for “time to enter no-moton state”, from 1 minute and up. Can be turned off too.

What time interval do you mean?

  • Your first post indicates the lights are turned off 5 minutes after detecting motion (a fixed delay of 5 minutes).
  • I am suggesting to turn the lights off after detecting no motion for 1 (or more) minutes. For example, my garage light is turned off after 2 minutes of no motion (to ensure they don’t turn off too quickly while I am working, relatively motionless, in the garage).

Post your automation.

Thank for the clarification. I see what you mean, I’ll break it out into two automations and give it a try.
Will also disable the built-in “no motion state timer” to rely only on HA.

It’s probably unnecessary to split the automation. If you post it I can help you modify it.

Here it is:

alias: Garage lights on when doors open or motion detected
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 01464df4541f929a6db7364fe7fbbceb
    entity_id: binary_sensor.garage_house_door_sensor_state
    domain: binary_sensor
  - type: opened
    platform: device
    device_id: 10bea943164e876688512514ba7d96c1
    entity_id: binary_sensor.garage_side_door_sensor_state
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: ef57070fd656dc4f998453f38ba5cfa1
    entity_id: binary_sensor.garage_motion_sensor_motion
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: 19422794b45e70e7fc799f71484fd288
    entity_id: binary_sensor.garage_motion_sensor_2_motion
    domain: binary_sensor
condition: []
action:
  - type: turn_on
    device_id: bc6f4afe00f79dacbc50464d6f9b730e
    entity_id: switch.garage_ceiling_lights
    domain: switch
  - delay:
      hours: 0
      minutes: 7
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: bc6f4afe00f79dacbc50464d6f9b730e
    entity_id: switch.garage_ceiling_lights
    domain: switch
mode: restart

@123 well, I did this, but I think I am missing the “AND” so that the light goes off only when both motion sensors report no motion. Any way to do that in a single automation?

alias: Garage light on when doors open or motion detected
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 01464df4541f929a6db7364fe7fbbceb
    entity_id: binary_sensor.garage_house_door_sensor_state
    domain: binary_sensor
  - type: opened
    platform: device
    device_id: 10bea943164e876688512514ba7d96c1
    entity_id: binary_sensor.garage_side_door_sensor_state
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: ef57070fd656dc4f998453f38ba5cfa1
    entity_id: binary_sensor.garage_motion_sensor_motion
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: 19422794b45e70e7fc799f71484fd288
    entity_id: binary_sensor.garage_motion_sensor_2_motion
    domain: binary_sensor
condition: []
action:
  - type: turn_on
    device_id: bc6f4afe00f79dacbc50464d6f9b730e
    entity_id: switch.garage_ceiling_lights
    domain: switch
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: ef57070fd656dc4f998453f38ba5cfa1
        entity_id: binary_sensor.garage_motion_sensor_motion
        domain: binary_sensor
      - type: no_motion
        platform: device
        device_id: 19422794b45e70e7fc799f71484fd288
        entity_id: binary_sensor.garage_motion_sensor_2_motion
        domain: binary_sensor
  - type: turn_off
    device_id: bc6f4afe00f79dacbc50464d6f9b730e
    entity_id: switch.garage_ceiling_lights
    domain: switch
mode: restart

Added if-then after “no motion” triggers that supports multiple AND conditions. We’ll see how this works.

Another possible approach - use a timer. Set and reset the timer based on motion. When timer expires, turn off light. Cancel timer if light is manually turned off. Could also add permutations for light manually turned on.

1 Like

Interesting way, but I am still not sure how to keep the light off when it was just switched off manually and the door is being opened to exit. Feels like there should be something that checks whether the light was turned off manually recently (rather than automatically) and that part I have no idea how to implement.

For the moment here is something that works, but doesn’t solve the issue with swithcing the light off before exiting.

alias: Garage light on when doors open or motion detected
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 01464df4541f929a6db7364fe7fbbceb
    entity_id: binary_sensor.garage_house_door_sensor_state
    domain: binary_sensor
  - type: opened
    platform: device
    device_id: 10bea943164e876688512514ba7d96c1
    entity_id: binary_sensor.garage_side_door_sensor_state
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: ef57070fd656dc4f998453f38ba5cfa1
    entity_id: binary_sensor.garage_motion_sensor_motion
    domain: binary_sensor
  - type: motion
    platform: device
    device_id: 19422794b45e70e7fc799f71484fd288
    entity_id: binary_sensor.garage_motion_sensor_2_motion
    domain: binary_sensor
condition: []
action:
  - type: turn_on
    device_id: bc6f4afe00f79dacbc50464d6f9b730e
    entity_id: switch.garage_ceiling_lights
    domain: switch
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: ef57070fd656dc4f998453f38ba5cfa1
        entity_id: binary_sensor.garage_motion_sensor_motion
        domain: binary_sensor
      - type: no_motion
        platform: device
        device_id: 19422794b45e70e7fc799f71484fd288
        entity_id: binary_sensor.garage_motion_sensor_2_motion
        domain: binary_sensor
  - if:
      - type: is_no_motion
        condition: device
        device_id: ef57070fd656dc4f998453f38ba5cfa1
        entity_id: binary_sensor.garage_motion_sensor_motion
        domain: binary_sensor
      - type: is_no_motion
        condition: device
        device_id: 19422794b45e70e7fc799f71484fd288
        entity_id: binary_sensor.garage_motion_sensor_2_motion
        domain: binary_sensor
    then:
      - type: turn_off
        device_id: bc6f4afe00f79dacbc50464d6f9b730e
        entity_id: switch.garage_ceiling_lights
        domain: switch
    else:
      - service: automation.trigger
        data: {}
        target:
          entity_id: automation.garage_light_on_when_doors_open_or_motion_detected
mode: restart

Which door is being used to exit? Is it one of the two garage doors or a third door that is not monitored by this automation?

Use an input to track manual or automated light switching (set in automations). Use conditions to check input and/or light on/off for some duration.

What technique would you use to differentiate between manual and automatic control of the switch?

Whatever automation deals with light leaves timestamped information in an input to be used by later automations to make decisions.

I see how that tells you the last time a light was controlled by an automation. How does one use it to determine when the light was controlled manually?

An additional automation triggered by any transition of the light can see if the input was (very) recently timestamped by another automation. If not, you could assume manual intervention. You can get inventive with this. Each automation can set or clear as many inputs as you want. I suspect, although I have not done it, that the logbook could be read and would tell you much about what has recently happened. You could also monitor events. Good luck.

How would it interact with tjk’s automation?

How does one read the logbook? I don’t see any sensors or service calls that provide access to its data.

Create a group of type binary sensor and add your two motion entities to that group, so you can use the group on your automation.
By default (and you can change this if you want), the group will be ON if any of the sensors are ON, so it will only be OFF when both sensors are off.

1 Like

A State Trigger, containing the two binary_sensors, achieves the same result without the need to create a group.

A group is useful in a trigger if there’s a need to know when both binary_sensors are on. For this application, it triggers when either binary_sensor is on.