Need help with light automation

Hi everyone
Please help me with automation

Description :

Lights turn on manually by switch and should be turned off considering all this conditions:

  • lights turned on for 5 minutes
  • No motion detected by motion sensor for 2 minutes

So if someone turned lights on lights should be turned on at least for 5 minutes. Also if someone passed by motion sensor - it should increase turned on time for 2 minutes each time

A tried a lot of ways, I used repeat until , wait, I tried some blueprints - no luck. I get some issues and wrong behavior. Please help

Why not just turn off light after no motion for 5 minutes? That’s what I do (or longer, in other cases). Much simpler.

  1. Make a Timer (let’s call it lights_countdown_timer) → schedule it for 5 minutes.
  2. Make automation: when light’s state changes to ON → start the light_countdown_timer.
  3. Make another automation: when the timer finishes → turn off the lights.
  4. Make automation: when motion detector changes to DETECTED and if light is ON → start the timer again, with its current time plus 2 min.
1 Like

I do something similar as mentioned by @DvdNwk

As a total newbie, it took me 3 straight days of pulling my teeth to get it done. However, I am thankful for the community because searching up posts like this helped me piece together an automation.

The automation starts a timer of 2 minutes during the day or 30 seconds at night (2 timers, 1 called night one called day). 10 seconds before the timer is finished, the lights DIM to let the user know they are about to turn off and to wave at the motion sensor. Then, they turn off. If at any time motion is detected during those 2 minutes, the timer restarts.

Honestly I set this up as my first automation, when I didn’t even know anything (oh how far I’ve come in 2 months) , so I am not sure if its still the most efficient way to do it , but it seems to work for me.

alias: "Entrance Motion "
description: ""
trigger:
  - type: motion
    platform: device
    device_id: enter your devide ID here
    entity_id: entity ID here
    domain: binary_sensor
condition: []
action:
  - choose:
      - conditions:
          - condition: time
            after: "11:00:00"
            before: "21:30:00"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 70
            target:
              entity_id: light.ground_floor_hallway_main_lights
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.entrance_timer
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - binary_sensor.entrance_motion_sensor_motion
                from: "on"
                to: "off"
          - service: timer.start
            data:
              duration: "120"
            target:
              entity_id: timer.entrance_timer
          - delay:
              hours: 0
              minutes: 1
              seconds: 50
              milliseconds: 0
          - type: turn_on
            device_id: ID goes here
            entity_id: Here as well
            domain: light
            brightness_pct: 10
          - wait_for_trigger:
              - platform: event
                event_type: timer.finished
                event_data:
                  entity_id: timer.entrance_timer
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.ground_floor_hallway_main_lights
      - conditions:
          - condition: time
            after: "21:31:00"
            before: "07:00:00"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 20
            target:
              entity_id: light.ground_floor_hallway_main_lights
          - service: timer.cancel
            data: {}
            target:
              entity_id: timer.entrance_timer_night
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - binary_sensor.entrance_motion_sensor_motion
                from: null
                to: "off"
          - service: timer.start
            data: {}
            target:
              entity_id: timer.entrance_timer_night
          - delay:
              hours: 0
              minutes: 0
              seconds: 20
              milliseconds: 0
          - type: turn_on
            device_id: Again with the ID
            entity_id: Here too
            domain: light
            brightness_pct: 1
          - wait_for_trigger:
              - platform: event
                event_type: timer.finished
                event_data:
                  entity_id: timer.entrance_timer_night
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.ground_floor_hallway_main_lights
mode: restart
1 Like

@DvdNwk @BlackMamba08 thanks for ideas

Restartiing timer in one action section with additional code breaks timer.finishes trigger and i implemented automation using multi trigger appproach, here’s yaml of automation:

alias: Lights AUTO off by timer and motion
description: ""
mode: restart
trigger:
  - platform: state
    entity_id:
      - light.my_light
    from: "off"
    to: "on"
    id: 💡Turn ON lights > ⏳▶️Start timer

  - platform: state
    entity_id:
      - binary_sensor.my_motion_sensor_1
    from: "off"
    to: "on"
    id: 🏃🏻Motion detected > ⏳♻️Restart timer

  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.my_timer
    id: ⏳❌Timer finished > 💡Turn OFF ligts

condition: []

action:
  - if:
      - condition: trigger
        id:
          - 💡Turn ON lights > ⏳▶️Start timer
    then:
      - service: timer.start
        target:
          entity_id: timer.my_timer
        data: {}

  - if:
      - condition: trigger
        id:
          - 🏃🏻Motion detected > ⏳♻️Restart timer
      - condition: state
        entity_id: light.my_light
        state: "on"
    then:
      - service: timer.start
        target:
          entity_id:
            - timer.my_timer
        data:
          duration: "90"

  - if:
      - condition: trigger
        id:
          - ⏳❌Timer finished > 💡Turn OFF lights
    then:
      - service: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.my_light
1 Like

The requirements are written needlessly complex. There is no need to to remember why the light is on

if lightis been on for 5 minute and sensor reports “clear”. Turn the light off

my goal was to create automation for forgotten light, but if someome continues to stay in the room delay turning off lights