Help with input_datetime & time_stamp custom calculating incorrectly

I’m trying to set up an automation which turn off my aircon at a time set using input_datetime.
I’ve copied the automation from others found on this forum, and I can’t see any reason it wouldn’t work.
I played around in the template editor and realised that for some reason the value_template line is calculating the input_datetime timestamp into the wrong time. i.e 01:43 is showing as 12:43, 15:03 shows as 02:05. Basically converts it to 13hrs before it should be.

If anyone knows why this is happening or how to fix it, I’d really appreciate the help.

Current Time: {{ states(‘sensor.time’)}} (Correct)

Input_datetime set to: {{states.input_datetime.aircon_set_time.state}} (Correct)

Timestamp attribute: {{states.input_datetime.aircon_set_time.attributes.timestamp}} (Correct)

Timestamp custom for comparing to current time: {{(states.input_datetime.aircon_set_time.attributes.timestamp | int | timestamp_custom(’%H:%M’, True))}} (False)

input_datetime:
  aircon_set_time:
    name: Aircon Time
    has_time: true

 automation: 
  - alias: Aircon Off at Set Time
      trigger:
        - platform: template
          value_template: "{{ states('sensor.time') == (states.input_datetime.aircon_set_time.attributes.timestamp | int | timestamp_custom('%H:%M', True)) }}"
      condition:
        - condition: and
          conditions:
            - condition: state
              entity_id: input_select.aircon_timer
              state: 'Aircon Off'
            - condition: state
              entity_id: input_boolean.aircon_set_time
              state: 'on'
      action:
        - service: switch.turn_off
          entity_id: switch.aircon

Try this:

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

Input datetimes have no time zone info (naive type). Have a read of this post: Time probelms

Dont think you need the | int filter either.

1 Like

Thank you! That works.

No problem. Your template was taking the time from the input_datetime that was already a (naive) local time and adding your timezone offset to convert it to what it thinks a local time should be.

1 Like