Why won't this trigger?!

- alias: 'Coffee'
  trigger:
    platform: template
    value_template: '{{ ((now().strftime("%s") | int + 300) | timestamp_custom("%H:%M")) == states.sensor.alarm_time.state }}'

Yeah it looks ok. Try using a time trigger and using a condition for the time instead. Here’s an example of my working alarm.

  - alias: 'Monday Alarm'
    trigger:
      platform: time
      minutes: '/5'
      seconds: '0'
    condition:
      condition: and
      conditions:
        - condition: time
          weekday:
            - mon
        - condition: template
          value_template: '{{ ((now().strftime("%s") | int ) | timestamp_custom("%H:%M")) == states.sensor.alarmtime_mon.state  }}'
        - condition: state
          entity_id: input_boolean.alarm_clock_mon
          state: 'on'
        - condition: state
          entity_id: input_boolean.alarm_clock_all
          state: 'off'
    action:
      - service: scene.turn_on
        data:
          entity_id: scene.goodmorning

Thanks, I tried that and it works.

I thought the main “trigger loop” checked all conditions, but apparently not?

You would think it would work as a trigger, but I guess it doesn’t. I just ended up using conditions when I’m comparing times. Whatever works right? :slight_smile:

Yeah exactly =)

It took my some time to realize this doensn’t work as well haha. It looks like if you use this as a trigger, Hass only checks if the template output mateches “true” once (on startup).
Like @Jer78 I also use the time trigger for templates like these, works great.

I’ve never had a lot of luck with templates as triggers. So what I usually do is create a template sensor using the exact same template, then use the state of that sensor in my automation’s trigger.

So why won’t this trigger?
Or did you mean that you just moved the template to a sensor but kept the time trigger @ih8gates?

- alias: 'Turn on Coffeemaker'
  trigger:
    - platform: state
      entity_id: sensor.alarm_coffee
      state: 'True'
  action:
    - service: switch.turn_on
      entity_id: switch.speedster_switch_16_0
    alarm_coffee:
      friendly_name: 'Start KvdW Speedster'
      value_template: '{{ ((now().strftime("%s") | int + 2700) | timestamp_custom("%H:%M")) == states.sensor.alarm_time.state }}'

This should work.

Perhaps you’ll have to use “on” instead of “true”.
Edit: actually i’m pretty sure you’ll have to use “on”. Let us know if it works.

I tried that to… If I run the template it returns True or False, but if I look under sensors it never changes state.

Wat is your state in the dev-tool?

False, never change.

Looks like you did what I suggested. Does the state on that sensor ever update? I think you need an entity_id value for the sensor - that tells the sensor when to re-evaluate. I guess in your situation, you’d need to have that tied to time. Have you looked at the alarm clock thread for tying triggers to other values (sliders, etc)

Yeah it’s for my alarm clock, so I’ve been a frequent visitor of that thread :slight_smile:

I haven’t seen it change state so I’m guessing it never get’s reevaluated, I’ve solved it with time, but it would be neat if it would work with just the template as trigger.