[HELP] - Alarm Automation Has No Errors but Isn't Working

I followed the alarm clock tutorial using the templates, and I have gotten it in my files without errors, and the sliders show up in my UI, but nothing happens when the time is hit.

I originally had this automation using the sunrise and it worked, but with Daylight savings time having hit it’s completely throwing me off so I just want to be able to set it with numbers in the UI.

sensor:
  - platform: yr
  - platform: template
    sensors:
      alarm_time:
        friendly_name: 'Time'
        value_template: '{{ states.input_slider.hour.state }}:{% if states.input_slider.minute.state|length == 1 %}0{% endif %}{{ states.input_slider.minute.state }}'
input_number:
  hour:
    name: hour
    min: 0
    max: 23
    step: 1
    mode: slider
  minute: 
    name: minute
    min: 0
    max: 60
    step: 1
    mode: slider
- id: '1540415715656'
  alias: Sunrise Lights
  trigger:
  - platform: template
    value_template: '{{ now.time().strftime("%-H") == states.input_slider.hour.state and now.time().strftime("%-M") == states.input_slider.minute.state }}'
  action:
  - service: light.turn_on
    data:
      entity_id: light.bedroom, light.lamp
      brightness_pct: 100
      color_name: floral white

To be honest, I have no idea what anything in the value_template means. Please help, I need my alarm clock to be a productive person in society

First, this template will not work during periods when the hour is between 0 and 9, or the minute is between 0 and 9. You need to use this:

      alarm_time:
        friendly_name: 'Alarm Time'
        value_template: "{{ '%02i:%02i'%(states('input_slider.hour') | int, states('input_slider.minute') | int) }}"

Even thought it looks like you are trying to account for the 0-9 situation mentioned above, you made it way over complicated. This is all you need if you add leading zeros:

- id: '1540415715656'
  alias: Sunrise Lights
  trigger:
  - platform: template
    value_template: "{{ now().strftime('%H:%M') == states('sensor.alarm_time') }}"
  action:
  - service: light.turn_on
    data:
      entity_id: light.bedroom, light.lamp
      brightness_pct: 100
      color_name: floral white

If you DONT want the leading zeros in the alarm time hour, then this is what you would need:

      alarm_time:
        friendly_name: 'Alarm Time'
        value_template: "{{ '%i:%02i'%(states('input_slider.hour') | int, states('input_slider.minute') | int) }}"
- id: '1540415715656'
  alias: Sunrise Lights
  trigger:
  - platform: template
    value_template: "{{ now().strftime('%-H:%M') == states('sensor.alarm_time') }}"
  action:
  - service: light.turn_on
    data:
      entity_id: light.bedroom, light.lamp
      brightness_pct: 100
      color_name: floral white

EDIT: So the other thing I just noticed is that this will not trigger at all. The automation will only trigger when sensor.alarm_time updates. It won’t update because now() is not something that home assistant builds triggers off of. So when that changes time, home assistant doesn’t see it. You’d need to add a entity that changes every minute to the trigger template. The unfortunate thing about this is that template triggers don’t accept the entity_id attribute, so you need to make your trigger into a sensor template or incorporate a entity into the equation. It’s just easier to make the template so here goes.

Use this template and replace your automation with this:

      alarm_trigger:
        friendly_name: 'Alarm Trigger'
        entity_id: sun.sun
        value_template: "{{ now().strftime('%-H:%M') == states('sensor.alarm_time') }}"
- id: '1540415715656'
  alias: Sunrise Lights
  trigger:
  - platform: state
    entity_id: sensor.alarm_trigger
    state: 'on'
  action:
  - service: light.turn_on
    data:
      entity_id: light.bedroom, light.lamp
      brightness_pct: 100
      color_name: floral white

Here’s what it took to get it to work:

  - platform: yr
  - platform: template
    sensors:
      alarm_time:
        friendly_name: 'Time'
        value_template: '{{ states.input_number.hour.state | int }}:{% if states.input_number.minute.state|length == 1 %}0{% endif %}{{ states.input_number.minute.state | int }}'
      alarm_trigger:
        friendly_name: 'Alarm Trigger'
        entity_id: sun.sun
        value_template: "{{ now().strftime('%-H:%M') == states('sensor.alarm_time') }}"

I had to change the name of the state in the template from input_slider to input_number, I realized this from looking in my events that they weren’t named correctly. Then I realized that there was a decimal in my time so I had to specify them as integers, with the " | int" after my state. I also had to indent my code as the example above was incorrect. My automations yaml was changed to this:

  alias: Sunrise Lights
  trigger:
  - platform: state
    entity_id: sensor.alarm_trigger
    to: 'True'
  action:
  - service: light.turn_on
    data:
      entity_id: light.bedroom, light.lamp
      brightness_pct: 100
      color_name: floral white

I had to use “True” instead of ‘on’.

Now it works!! Thank you!!