The restart mode does not work

Hi all,
I have the following automation:

#- 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.

Do I miss something?

thank for the help

I think it’s because you’re using mode restart. Remove that completely from your code and it will work exactly as you require.

Then I think I didn’t understand the reason of the restart mode? :thinking:

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.

1 Like
#- 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 :frowning:
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.