I have created an automation to turn off the switch when the time expires. In addition, there is a motion sensor so that each time motion is detected the countdown starts again. When I turn the switch on manually and movement is not detected, the countdown does not start and the switch does not turn off. What is my mistake? Please help.
alias: Hallway New Automation
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.ikea_tradfri_motion_sensor_motion
from: "off"
to: "on"
- platform: state
entity_id:
- switch.sonoff_zbminil2_1_switch
from: "off"
to: "on"
condition: []
action:
- if:
- condition: and
conditions:
- condition: time
after: "05:00:00"
before: "23:00:00"
enabled: true
- condition: numeric_state
entity_id: sensor.lumi_motion_ac02_1_illuminance
below: 50
then:
- alias: Turn on the light
data: {}
action: switch.turn_on
target:
entity_id: switch.sonoff_zbminil2_1_switch
- alias: Wait until there is no motion
wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.ikea_tradfri_motion_sensor_motion
from: "on"
to: "off"
- alias: Time to leave the light on after last motion is detected
delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- alias: Turn off the light
data: {}
action: switch.turn_off
target:
entity_id: switch.sonoff_zbminil2_1_switch
mode: restart
max_exceeded: silent