Templating in automation not working

I’m trying to add some templating into my automation trigger and it doesn’t appear to like it. But the thing is it works with my script doing the same thing. Is there something obvious I’m doing wrong or a way to achieve what I want.

Automation that doesn’t work:

# Scene: morning
    - alias: "Scene Morning"
      initial_state: True
      hide_entity: False
      trigger:
        - platform: time
          after: '{{ states.input_slider.morning_time_hr.state | int }}:{{ states.input_slider.morning_time_min.state | int }}:00'
      condition:
        condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
      action:
        - service: scene.turn_on
          entity_id: scene.morning

Script that does work:

  run_back_sprinklers:
    alias: "Run Back 1 Sprinklers"
    sequence:
      - service: switch.turn_on
        entity_id: switch.relay1
      - delay: '00:{{ states.input_slider.slider3.state | int }}:{{ states.input_slider.slider4.state | int }}'
      - service: switch.turn_off
        entity_id: switch.relay1

Error logs:

Apr 01 19:05:14 UbuntuServer docker[28960]: 17-04-01 19:05:14 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Invalid time specified: {{ states.input_slider.morning_time_hr.state | int }}:{{ states.input_slider.morning_time_min.state | int }}:00 for dictionary value @ data['trigger'][0]['after']. Got None. (See /config/configuration.yaml, line 183). Please check the docs at https://home-assistant.io/components/automation/

I don’t believe that you can use a template for the “after” value in the time platform.

Try using a template trigger:

The alarm clock thread likely has some usable examples for you:

2 Likes