I have an automation to turn on a light via script when motion detected. What I want to do is add a timer to turn the light off after there has been no motion for 2 minutes.
I’ve never used timers before so I’m confused as to whether to put it in the script or automation and the correct syntax. If someone more capable than me is able to help out I’d be grateful.
Automation:
- alias: Turn on off stairs light when there is movement at night
trigger:
- platform: state
entity_id: binary_sensor.staircase_sensor_occupancy
to: 'on'
condition:
- condition: time
after: '22:00:00'
before: '08:00:00'
action:
- service: script.stairs_early
No need to use a timer. Just turn off the light if motion has been off for 2 minutes straight.
- alias: Turn on off stairs light when there is movement at night
trigger:
- platform: state
entity_id: binary_sensor.staircase_sensor_occupancy
to: 'off'
for:
minutes: 2
condition:
- condition: time
after: '22:00:00'
before: '08:00:00'
action:
- service: light.turn_off
entity_id: light.stairs_spot
- alias: Turn on off stairs light when there is movement at night
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.staircase_sensor_occupancy
to: 'on'
condition:
- condition: time
after: '22:00:00'
before: '08:00:00'
action:
- service: script.stairs_early
- delay: "00:02:00"
- service: light.turn_off
entity_id: light.stairs_spot