Choose time to run automaton

Two things,

  1. Your quoting is all messed up. Put double quotes outside the template, single quotes inside (not double single quotes).
  2. Your template resolves to h:MM PM/AM. Templates need to resolve to true or false to trigger. You need to compare the input_datetime to the time.

So:

Add a time sensor if you have not already:

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

then try this:

  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == states('input_datetime.set_time')[0:5] }}"

If you put this in the developer tools template editor you will see what it does:

time now = {{ states('sensor.time') }}

input_datetime = {{ states('input_datetime.set_time') }}

formatted input_datetime = {{ states('input_datetime.set_time')[0:5] }}

template result = {{ states('sensor.time') == states('input_datetime.set_time')[0:5] }}

Hereā€™s an example using one of my input_datetimes:

1 Like

FYI, double single quotes is allowed in yaml. I too made that mistake a year or so ago. So his quoting is valid, but the trigger not resolving to True/False is the real problem.

Escaped single quotes by single quotes are an unnecessary affront to common sense. There are saner alternatives. Why do this?

Do not teach people this except where absolutely necessary.

1 Like

The above absolutely makes more scene. This was a stupid mistake on my part. I was concentrating on the action portion of the automation, not the trigger. I updated the trigger and will test it out tonight.

Hi

I suffer from similar issue. The set input is triggering at the wrong time.
Iā€™ve read this thread, but did not reached a solution. I hope I didnā€™t miss something.

My setup:

I have a time sensor

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

And an automation script (which uses the ā€˜trueā€™ in the templateā€™s time stamp comparison)

- id: '1587744513372'
 alias: 'power on on time '
 description: ''
 trigger:
   platform: template
   value_template: "{{ states('sensor.time') == (state_attr('input_datetime.amit_s_light', 'timestamp') | int | timestamp_custom('%H:%M', True)) }}"
 action:
 - device_id: bc37ba8b5a0c49e690fb1a1e11eb9c49
   domain: light
   entity_id: light.desk_lamp
   type: turn_on

I have set my local time zone and geographical location
I see the ā€œcorrectā€ UTC time on the home assistant overview page, however, the set time in the input_datetime is triggered 2 hours after the expected time (i.e. if I want to get the trigger at 11:00, I have to set it to 9:00)
Iā€™m living at UTC+2 (which might fit the 2 hours difference) however currently we are at GMT+2+DST, a 3 hours difference from GMT.
Iā€™ve checked the automation itself and the action is working when triggered manually.

Any ideas? further debug steps? Iā€™m newbie here and doesnā€™t have a debug environment on my computer.

Thanks
Ariel

@tom_l Thanks Mate ! Your simple solution works for me. I applied it verywhere now, where the WAF highly increased, since the wife can now easily change the timing of ā€œherā€ lights herself ā€¦

grtz
John

1 Like

Assuming your input_datetime has time: true and has date: false
Then you should simplify your template to work with text and bypass the utc and timestamp considerations.
Timestamp is always utc aware.

"{{ states('sensor.time') == states('input_datetime.amit_s_light') [0:5] }}"

This will always work in local time (I canā€™t think why anyone would ever want to consider dst offsets or utc in a home automation context but Iā€™m sure someone will be able to come back with one)

1 Like

Hey guys, Iā€™m trying to add multiple time boxes but for some reason only the first default ones show up Iā€™m unsure why. Could someone point me in correct direction pleaseā€¦

config/Input_datetime.yaml

WORKING ONES

both_date_and_time:
  name: Input with both date and time
  has_date: true
  has_time: true
only_date:
  name: Input with only date
  has_date: true
  has_time: false
only_time:
  name: Input with only time
  has_date: false
  has_time: true
NOT EVEN SHOWING IN DEVELOPER

boys_light_off_time:
  name: boys Light off time
  has_date: false
  has_time: true
set_time:
  name: Set Time
  has_date: false
  has_time: true


dt1:
  name: Date Time 1
  has_date: true
  has_time: true
  initial: "2019-05-01 07:30"

did you restart after adding them? FYI if you donā€™t want to restart, move to the UI

or did you move to the UI and forget? Check configuration.yaml for the include on the input_datetime.

Lol for some reason Hass was having issues reading the input_datetime.yaml file renamed and now works crazy the simple things can be allusive. Thanks for help