I have a Sonoff Touch Switch that I triggered by IFTTT.
I wish to automate on and off … but I’m unable to swtch off by script… from last movement detected from the motion sensor.
What I do wrong?
automation:
- alias: sonoff corr on
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_xxxxxxxxx
to: 'on'
action:
service: ifttt.trigger
data: {"event":"Sonoff_corr_on"}
script:
timed_lamp:
alias: "Turn on lamp and set timer"
sequence:
# Cancel ev. old timers
- execute_service: script.turn_off
service_data:
entity_id: script.timer_off
- execute_service: ifttt.trigger
service_data: {"event":"Sonoff_corr_on"}
# Set new timer
- execute_service: script.turn_on
service_data:
entity_id: script.timer_off
timer_off:
alias: "Turn off lamp after 5 minutes"
sequence:
- delay:
minutes: 5
- execute_service: ifttt.trigger
service_data: {"event":"Sonoff_corr_off"}