Hi,
I have a Philips Hue sensor which turns on a switch (Wemo or Sonoff Matsuoka) as per below. I’ve found that when the sensor stops detecting movement it switches the switch off. In my automations.yaml file I am only triggering when the light turns on and then waiting for a timer to complete.
Why does HA turn off the light when the state changes although it is not specified???
So this is happening because as soon as the motion sensor resets back to off, which in the case of the Hue’s, its 10 seconds, it then starts the timer. If you trip the motion sensor again, the timer WON’T reset, so it will still be counting down from 5 minutes from the first time it changed back to off. There is probably a clever way to do this all in one automation, there was a thread somewhere about it if you have a search around for it. But I just did it will two automation’s,
- alias: Chandelier Motion On
trigger:
- entity_id: sensor.downstairs_motion_motion_sensor
from: 'off'
platform: state
to: 'on'
condition: []
action:
- data:
entity_id: switch.chandelier_2
service: switch.turn_on
- alias: Chandelier Motion off
trigger:
- entity_id: sensor.downstairs_motion_motion_sensor
from: 'on'
platform: state
to: 'off'
for:
seconds: 20
condition: []
action:
- data:
entity_id: switch.chandelier_2
service: switch.turn_off
The important bit there is the
to: 'off'
for:
seconds: 20
So it will only turn it off IF the motion sensor has been off for 20 seconds, so in your case, if you have
to: 'off'
for:
minutes: 5
Then after 5 minutes of no motion from the sensor, then it will switch the plug off.
As above, sure there is a better way of doing it, but this works for me.
You could try canceling & restarting the timer whenever the motion sensor is triggered. As long as the sensor is triggering, the timer is reset and the light stays on.
That’s exactly what I do in my automation. It says in the documentation that time.start is supposed to restart the timer if already running, but it doesn’t. So I preceeded it with a cancel timer.