#- alias : 'accendi cucina'
- alias: Accendi Cucina con PIR
mode: restart
trigger:
platform: state
entity_id: binary_sensor.sonoff_movimento_cucina
to: 'on'
action:
service: light.turn_on
entity_id: light.luci_cucina
- alias: Spegni Cucina con PIR
mode: restart
trigger:
platform: state
entity_id: binary_sensor.sonoff_movimento_cucina
to: 'off'
for:
minutes: 10
action:
service: light.turn_off
entity_id: light.luci_cucina
the idea is that it turns off the light (light.luci_cucina) after 10 min that the sensor binary_sensor.sonoff_movimento_cucina does not detects any movement. This is why Iâve set the mode: restart
The fact is that it works everything apart the ârestartâ directive. If I stay in the the area longer the 10 min, the lights are turned off anyway.
restart means that the automation will start itself again every time the trigger becomes true, which is not what you want. You just want the trigger to come true and fire the action every time, because the âtimerâ of 10 minutes is already part of the trigger.
You should only be using modes that arenât default for long running actions to decide whether that action continues, stops or restarts on a subsequent trigger, or for triggers that may trigger multiple times per second and cause undesirable results if not filtered in a certain way.
Skal as Marc says ârestartâ is not required here.
Now donât use this as an example (itâs poor coding and unreliable but itâs close to what you have) : -
Imagine that you used a delay instead of the for, you might then use restart, so every time the sensor goes âoffâ the delay restarts before turning the light off. This should then give you your ten minutes.
Iâve removed the restart part. But nothing changed. While Iâm in the room, and I moove, after some time the light turns off⌠any idea how to keep it on?
Is it being turned off by something else? That automation will only trigger when the motion sensor has reported off continuously for 10 minutes, so if youâre moving around it shouldnât be triggering.
#- alias : 'accendi cucina'
- alias: Accendi Cucina con PIR
# mode: restart ## Remove this
trigger:
platform: state
entity_id: binary_sensor.sonoff_movimento_cucina
to: 'on'
action:
service: light.turn_on
entity_id: light.luci_cucina
- alias: Spegni Cucina con PIR
# mode: restart ### remove this
trigger:
platform: state
entity_id: binary_sensor.sonoff_movimento_cucina
to: 'off'
for:
minutes: 10
action:
service: light.turn_off
entity_id: light.luci_cucina
Default mode is âsingleâ - this means only run this once, error if called to run again (may spam your logs IF you record such stuff (I donât).
This should work, thie light comes on when triggered
When motion goes off, for 10 mins the trigger should then turn it off
This IS my actual configuration, but it still doesnât work
Lights turns off after some time even if I move in the room.
Is there some way to debug it?
Please confirm that you are telling us that when you look in the logbook you can see the binary sensor going on and off, and then there is a less than a 10 minute gap between the last âoffâ and the automation firing?
A screenshot of the logbook when this happens would assist.