Trouble with input_datetime as automation trigger

Hello. I’ve been trying to use input_datetime to set a time that will be used as a trigger for an automation. Try as I might, I can’t seem to get the automation to recognize when this time is met and trigger correctly. I have the input configured as follows:

input_datetime:
  weekday_time:
    name: "Weekday Sunrise Time"
    has_date: false
    has_time: true
    initial: '05:00'

I have added a sensor for time_date to compare against a template in the automation:

sensor:
 - platform: time_date
   display_options:
     - 'time'

And have created a test automation to trigger when the time matches:

automation:
- alias: 'Test Time'
  trigger:
    - platform: template
      value_template: '{{ states.sensor.time.state  == states.input_datetime.weekday_time.state  }}'
  action:
    service: notify.ios_iphone
    data:
      message: 'It worked'

I’ve triggered the automation through the web UI of Home Assistant and confirmed the notification isn’t the culprit. In trying to resolve the value_template in the template editor in Home Assistant, I can see that states.sensor.time.state gives the time in %H:%M format (e.g. 05:00) and states.input_datetime.weekday_time.state results in %H:%M:%S (e.g. 05:00:00) format.

To try to resolve this, I tried the following template instead but came across the same results.
{{ now().strftime("%H:%M:%S") == states.input_datetime.weekday_time.state }}

Clearly I’m missing something, but after hours of trial and error and searching throughout the forum, I’m coming up short in finding any guidance on using time from input_datetime as a trigger. Any insight you can share would be greatly appreciated!

@boyakasha1 I was able to get your automation to work using :

value_template: '{{ states.sensor.time.state == (states.input_datetime.weekday_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'

which I found here:

1 Like

That worked! Thank you very much jivesinger!

Doesn’t seem to be working for me:

  trigger:
  - platform: template
    value_template: '{{ states.sensor.time.state == (states.input_datetime.kailey_light_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'

when I try it in the front end templates tool it properly switches to “True” for the minute I set, and then back to “False”, but the action is never triggered.

Any ideas? I’d really like to get away from hard-coded times and in to something more user-friendly so the wife can change a time without asking me to edit a yaml config file.

EDIT: Never mind, the template trigger worked fine, the light I was triggering just didn’t like the brightness value I supplied. Thanks!

Isn’t this much easier?

trigger:
    platform: template
    value_template: '{{ states.sensor.time.state == states.input_datetime.blabla.state[0:5] }}'

input_datetime

blabla:
  name: blabla
  has_date: false
  has_time: true
  initial: '05:00:00'
3 Likes

So much tidier than what I was doing before - very neat method!