Template trigger doesnt run

Hi,

Im creating a template trigger that runs when i set an alarm time on the dashboard but it doesnt run and I cant figure out why. When i test the template in the developter tools it is changing from False to True. The action itself runs aswell when i manually trigger the automation.

Can anyone explain what is happening and what im missing?

alias: Wekker2
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ states('sensor.time') ==
      states('input_datetime.time_helper_alarmclock')[0,5] }}
condition: []
action:
  - action: notify.mobile_app_samsung_van_thomas
    metadata: {}
    data:
      message: Test
mode: single

Hi tmiedema89.

Those times are probably not in the same format, so you should filter or cast them both to make sure they are the correct format.
also what is

A Time Trigger supports Input Datetime entities.

trigger:
  - platform: time
    at: input_datetime.time_helper_alarmclock

For this particular application, it’s simpler than using a Template Trigger.

If it’s an input_datetime that has the time only; you probably want this:

{{ now() >= today_at(states('input_datetime.time_helper_alarmclock')) }}

Also note that it’s not a great idea to use == when comparing times, since they can have microsecond accuracy. And any template with now() will only get rendered once per minute. So it would almost certainly never trigger.

And the trigger will fire on the transition from false to true so it makes no difference how long it remains in the true state. As long as it transitions back to false at some point before you need it to trigger again. And the code I’ve suggested will transition to false at midnight.

Edit: ninja’d by 123; his suggestion is better anyway. But I’m leaving mine here to help you understand a little more about templates and template triggers.

Then you’re not testing the template you posted. You want [0:5] not [0,5].

But you really want Taras’s solution.

True, was testing without it and copied the code but added this manually and to quick.

Ok thank you! I think I understand why this happens and im using your solution.

1 Like