Simple automation: Timer does not reset

I’m using the example script for my kitchen to have the lights go on for 10 mins while there is motion. For me the expected behavior would be that it stays on while there is motion detected (eg I’m in the kitchen for 30 mins, the lights stay on until no motion for 10 mins).

My issue: The light always goes out after 10 mins and seems to ignore any motion within the 10 mins

I have:

Automation (in Automation. yaml):

  - alias: Turn on kitchen lights when there is movement
    trigger:
      - platform: state
        entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_10
        to: 'on'
    condition:
      condition: numeric_state
      entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_10
      below: 260
    action:
      service: homeassistant.turn_on
      entity_id: script.timer_kitchen

Script 1 (timer_kitchen.yaml):

  sequence:
  # Cancel ev. old timers
    - service: script.turn_off
      data:
        entity_id: script.timer_off
    - service: light.turn_on
      entity_id: light.qubino_zmnhdd1_flush_dimmer_level_11
      data:
        brightness: 140
  # Set new timer
    - service: script.turn_on
      data:
        entity_id: script.timer_kitchen_off

Script 2 (timer_kitchen_off.yaml)

  sequence:
    - delay:
        minutes: 10
    - service: light.turn_off
      data:
        entity_id: light.qubino_zmnhdd1_flush_dimmer_level_11

And in the log:

16-10-23 08:49:06 homeassistant.components.script: Script script.timer_kitchen_off already running.

The automation code you posted appears to be in line with the behaviour you’re describing:
When the motion sensor is triggered (changes its state to on), and light level is below a certain threshold, the script to turn on lights is started; this timer script first turns off any previous instance, then turns on the light, and then starts the timer to turn the lights off; this second script waits for 10 minutes, and then turns off the lights. That’s it.

I assume that your motion sensor is only triggered once when you enter the room, and while it keeps detecting motion, it’s never turning off, and hence never turns to state on again.

If you want the lights to keep on while there’s still motion, you have to build this into your timer script.

Please have a look at my previous post that includes a working motion light for inspiration.
In the timer_off script you can see an example of how to use conditions to decide whether to keep the lights on and restart the timer, or just turn off the lights.

I based some of my scripts off of that example, too. I think that it’s a bit out-of-date. I believe that you’re no longer able to turn_on a script that’s already running. That doesn’t restart it. So in your initial automation, you’ll want to turn if off, then back on again.

After reading @exxamalte post I thought that the issue was indeed that the motion sensor never goes to off while being in the kitchen. After testing some alternatives I found that that is not the case, it reports off (then goes on again). So in theory the original automation mentioned in post 1 should be working.

I think the issue is as @ih8gates mentions; you are not able to turn_on a script that is already running (hense the error in the log that the script is already running).

@ih8gates; how/where would you suggest to add this script of? As a first action eg only change the automation part and not the scripts?

  - alias: Turn on kitchen lights when there is movement
    trigger:
      - platform: state
        entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_10
        to: 'on'
    condition:
      condition: numeric_state
      entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_10
      below: 260
    action:
       - service: homeassistant.turn_off
         data:
            entity_id: script.timer_kitchen
       - service: homeassistant.turn_on
         data:
             entity_id: script.timer_kitchen

Yes - in the automation. The automation will trigger every time your motion sensor goes to “on” (and luminance is < 260).

So it’ll reset that script each time it triggers.

Driving me nuts. Below also does not work correctly. Any other suggestions?

  - alias: Turn on kitchen lights when there is movement
    trigger:
      - platform: state
        entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_10_0
        to: 'on'
    condition:
      condition: numeric_state
      entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_10_3
      below: 260
    action:
      - service: homeassistant.turn_off
        data:
          entity_id: script.timer_kitchen
      - service: homeassistant.turn_on
        data:
          entity_id: script.timer_kitchen

What if you change that last service call to:
- service: script.timer_kitchen
(no entity_id needed)

Also - are you confident that the Fibaro luminance returns a value that works with numeric_state?

I think you’re using the wrong sensor for the FGMS. I’m using the burglar sensor (sensor.fibaro_system_fgms001_motion_sensor_burglar_3_10).

When sensor.fibaro_system_fgms001_motion_sensor_burglar_3_10 moves from ‘0’ their is motion (and triggers the light_on script). When is moves to ‘0’ no motion has been detected (and triggers the light_off script).

Thanks for the suggestion but I’m sure that’s not it. You might have the newer version of the sensor (the zwave + version), maybe that reports different.

My issue is that the light needs to stay on while there is motion (so I’m in the kicthen for 30 min, light should stay on for 30 min + timer). For some reason the script does not reset and light always goes out after 10 min.

Is that luminance sensor near your kitchen? Then I suspect that when your kitchen light comes on, it makes it so that the condition is not met and thus ends. So the script will only run once if the motion sensor is near the luminance sensor.