Why is timer.finished not triggering?

I’m setting up my first timer-based automation, and can’t figure out why what seems to be straight forward isn’t working.

I’ve got a simple automation set up that turns on a light, starts a timer, and exits. Then I’ve set up a second automation that I intend to trigger on when that timer finishes to turn the light off. Here’s the YAML for the two automations:

alias: Back light timer test
trigger:
  - type: opened
    platform: device
    device_id: 54e3095bb400961e32fa07828423fffe
    entity_id: binary_sensor.back_porch_door
    domain: binary_sensor
condition: []
action:
  - type: turn_on
    device_id: 5499ad46dcdcd9a2dcde58f4349d575b
    entity_id: switch.back_porch_lights
    domain: switch
  - service: timer.start
    data:
      duration: '00:00:30'
    target:
      entity_id: timer.back_porch_lights
mode: single
alias: Back porch lights off when timer finished
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      data:
        entity id: timer.back_porch_lights
action:
  - type: turn_off
    device_id: 5499ad46dcdcd9a2dcde58f4349d575b
    entity_id: switch.back_porch_lights
    domain: switch
mode: single

I’ve watched the first automation start the timer then as it counts down. But the second automation never triggers.

Is there some magic pixie dust I need to sprinkle about?

Or does anyone have suggestions for where to look in logs to find the system response to the timer.finished event?

Never used the timer.finished, however the automation you look at can be much simpler.

Trigger: Your trigger
Action1: Turn on
Action1: Delay 30 sec
Action1: Turn off

In GUI the delay can easily be done with the action called “wait for time to pass (delay)”

Not sure, but the example, has no data after event_data.
Try it without it.

2 Likes

Not totally the same actually. Two differences:

  1. The timer will restart if the door is opened again within those 30 seconds. Whereas yours will turn off the light 30 seconds after the door is first opened regardless of whether the door keeps being used
  2. In your approach, if HA happens to restart or if you make a change to any automation in the 30 seconds after the door is opened then the light will just never go off. A timer still has this risk but only if you happen to change an automation exactly 30 seconds after the door was opened. Less likely and also handles restarts without issue (since timers restore after restart now).

Maybe not an issue for the author but just an FYI, delay and timer aren’t quite the same thing. Particularly when it comes to restart/reload resilience.

2 Likes

Hi Mike, Your right on both.

  1. Your are right, however the intention might be different
  2. Agree, the reload of automation when any automation is changed is a problem (and on restart, even it is a much more limited problem)

Personally I do my lights with 2 automations. One for turn on, triggering on “motion on” The other automation is triggering on “motion off” for 10 minutes.

@khvej8 the code I’ve included here is test code to figure out why the timer.finished event isn’t triggering an automation. I won’t go into all of the details, but using a delay isn’t sufficient for my use case.

(I do use the delay method in simpler automatons.)

Have you looked at the automation trace for the turn off automation to see why it’s not triggering?

That triggered me:-) Nice small evening challenge.

It because the timer.finished is not a trigger. Is is a service call to finish the timer, if needed to be finished before time.

To trigger on a timer, use this.

alias: 0 A Timertest finished
description: ''
trigger:
  - platform: state
    entity_id:
      - timer.timertest
    to: idle
condition: []
action:
  - device_id: ae9972bc8535157a6b02f4e2b9354923
    domain: light
    entity_id: light.kokken_bord_1
    type: flash
mode: single

Of course you can use an event trigger. This is my egg clock automation when egg clock has expired:



  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.eieruhr

  action:
  - service: input_boolean.turn_off
    data:
      entity_id: input_boolean.eieruhr

there is a difference between the “timer.finished” event and the “timer.finish” service call.
(two letters at the end :wink:). the former can be used as a trigger but the latter can’t. the OP is using the former so it’s fine.

It is most likely the thing that vdrainer posted above (extra “data:” line).

State based triggers will not work as expected when using timers.
Don’t use that.
to: idle will happen when the timer has been cancelled also.

Finally had time to test this. Removed the extra “data:” line and the trigger works. Thanks!

Don’t know where that extra line snuck into my code, I think I copied it from some example.

You should select vdrainer’s post as the solution. Not yours. Since he was the one who actually told you how to solve it.

2 Likes

I’m seeing the same issue and I don’t have the extra data: in my trigger. Could it be the order?

id: '1625026205975'
alias: Lighting - Kitchen Strip
description: ''
trigger:
  - platform: sun
    event: sunset
    id: sunset
  - platform: event
    event_type: timer.finished
    event_data:
      event_id: timer.kitchen_strip
    id: kitchenstripoff
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: sunset
        sequence:
          - service: timer.start
            data: {}
            target:
              entity_id: timer.kitchen_strip
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.kitchen_strip_lights
      - conditions:
          - condition: trigger
            id: kitchenstripoff
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.kitchen_strip_lights
mode: single

It’s entity_id

OMG!!! How did I miss that! Thanks much!

I have the same issue just that it works on one automation and doesn’t on another
I even tried to remake the one it doesn’t work with into an oversimplified version for troubleshooting

The action from automation 1 is:

service: timer.start
data: {}
target:
  entity_id: timer.aufstehen

(this always triggers without any issue)

but automation 2 never fires. event trigger:

platform: event
event_type: timer.finished
event_data:
  entity id: timer.aufstehen

and the action is

service: timer.start
data: {}
target:
  entity_id: timer.steh_auf_2

I don’t see any warnings whatsoever, no traces

Is that a typo or is it truly missing an underscore character in your automation?

platform: event
event_type: timer.finished
event_data:
  entity id: timer.aufstehen
        ^
        |
   Requires an underscore character here

I’m having this issue too now.
Can anyone suggest why this is not triggering when the timer counts down to zero?

- alias: Auto - Test Timer Finished2
  description: ""
  trigger:
  - platform: event
    event_type: timer_finished
    event_data:
      entity_id: timer.testtimer
  condition: []
  action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.dining_room_lamp
  mode: single

Ha. I think I’ve just spotted it!
timer_finished instead of timer.finished

1 Like