Quick bit of support with automation


I was just wondering what your guys understanding of this automation is.

My understanding is that if there stairs motion sensor detects motion between 5am and 720am then the early lights scene runs. The scene should continue to run if it detects motion upto 720am. So i thought the latest the lights should be is 820am.

However they were still on later than this.

alias: Turn on lights with motion sensor
description: Turn on lights when motion is detected between 5:00AM and 7:20AM
  - platform: state
    entity_id: binary_sensor.stairs_sensor_motion
    from: "off"
    to: "on"
  - condition: time
    after: "05:00:00"
    before: "07:20:00"
  - service: light.turn_on
    entity_id: light.early_lights
      brightness_pct: 50
  - delay:
      hours: 1
  - service: light.turn_off
    entity_id: light.early_lights
mode: restart

The lights tirned off at 08:48am

Do not wait for hours in an automation.

Create another automation that turns the lights off, either at 7:20 or after the binary sensor has been off for an hour.

  - platform: state
    entity_id: binary_sensor.stairs_sensor_motion
    from: "on"
    to: "off"
      hours: 1

Even that can be interrupted by a restart or reload. For long times like this you are better off using a timer. They can be restored after a restart.

cheers for that, i have tried setting 2 automation one off one off and a timer in my yaml code - see how it works tomorrow haha