Input_datetime as trigger in automation

Hello, as the documentation for input_datetime states, it is possible to use it in automations.
My aim is to use it for controlling the timings in my heatingplan.
I want to use an input_datetime to start the heating on weakdays and one where the heating should stop.
But the docs don’t state, how to use it as a trigger.

Any help would be highly appreciated.

1 Like

I’d probably use the input_datetime with a time based trigger, so it only fires at a certain time, then breaking the weekday bit out into a condition. That would make the time trigger times configurable via the UI. Take a look at this doc, and the time trigger to see what it’s expecting:

Also make 2 input_datetime entity’s so you have something to work with. You’ll most likely have to use a template to pull the input_datetime state into the trigger. So if you haven’t yet, read up on template creation:

Also once the input_datetime entity’s are created, and HA is restarted, you’ll be able to use the developer tools -> template editor, which should help you in writing the templates.

Best of luck!

I have the same question. The documentation does not help me.
I simply want to use the input date time to change the time trigger (07:00) for the automation via UI.

input_datetime.zeit_sonnenaufgang is set to 07:00. But how to add as trigger?

Thats the automation.

- id: sonnenaufgang_jalousie
  alias: sonnenaufgang_jalousie
  trigger:
  - at: 07:00
    platform: time
  action:
  - data:
      entity_id: group.jalousien
    entity_id: group.jalousien
    service: switch.turn_on
  - data:
      entity_id: cover.jalousie_schiebetuer_level
    entity_id: cover.jalousie_schiebetuer_level
    service: cover.open_cover
  - data:
      entity_id: cover.jalousie_hwr_level
    entity_id: cover.jalousie_hwr_level
    service: cover.open_cover

Thx for helping

I will try something like this

  • alias: Heizung wochentags hoch
    trigger:
  • platform: template
    value_template: ‘{{ is_state(input_datetime.heating_on_weekday.state, timestamp_custom("%H:%M:%S", 0)) }}’
    condition:
  • condition: time
    weekday:
    • mon
    • tue
    • wed
    • thu
    • fri
      action:
  • service: input_select.select_option
    data:
    entity_id: input_select.heating_scene
    option: ‘Hoch’

At least it does not throw any errors in check-config :slight_smile:

I have got it working now:

- alias: Heizung wochentags hoch
  trigger:
    - platform: template
      value_template: '{{ (states.input_datetime.heating_on_weekday.attributes.timestamp | int | timestamp_custom("%H:%M", False)) == states.sensor.time.state }}'
  condition:
    - condition: time
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.heating_scene
        option: 'Hoch'
2 Likes

I have a feeling, that this triggers the automation multiple times.
Therefore I am thinking of transferring the trigger to a binary template sensor and building the trigger around that.
The sensor stays in his state and so the automation is only triggered once.

heating_on_weekday:
        friendly_name: "Heizung an in der Woche"
        value_template: "{{ (states.input_datetime.heating_on_weekday.attributes.timestamp | int | timestamp_custom("%H:%M", False)) == states.sensor.time.state }}"

Is it possible that it triggers every second ?

Yeah, I think that my initial setup triggered the automation every second, thats why I changed to using binary template sensors for all my input_datetime related triggers.
Works like a charm.

Why not using

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

instead?

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

Works fine according to some initial testing.

I also had problems with it not triggering correctly until I went with binary_sensors and used those in the automations.

binary_sensor:
  platform: template
  sensors:
    michael_status_to_wake:
      value_template: "{{ is_state('input_datetime.time_michael_wake',states.sensor.date__time.state | string | replace(', ',' ')~':00') }}"

I match it on the :00 second. I’m sure there is a better way but I tried a lot of them and this has proven to be reliable.

  - alias: Michael Daily Status Begin Morning Set
    initial_state: True
    trigger:
      - platform: state
        entity_id: binary_sensor.michael_wake_set
        from: 'off'
        to: 'on'
    condition:
      - condition: state
        entity_id: input_select.michael_daily_status
        state: "Sleep"
    action:
      - service: input_select.select_option
        data:
          entity_id: input_select.michael_daily_status
          option: "Begin Morning"

My sleep time and wake times are based on my work calendar and are updated everytime my Google calendar changes.

My solution to this was to create an additional time sensor that includes seconds (ie: 20:15:34):

- platform: command_line
  name: time_seconds
  scan_interval: 0.5
  command: date +"%T"

Then I used this value_template in the automation trigger:

- alias: Lights on in the morning
  trigger:
    - platform: template
      value_template: "{{ states('sensor.time_seconds') == (states.input_datetime.all_lights_on_morning.attributes.timestamp | int | timestamp_custom('%H:%M:%S', False)) }}"
  action:
    - service: homeassistant.turn_on
      entity_id:
        - group.all_lamps_group

This looks quite clean to me and it works just fine :slight_smile:

1 Like

Thank you Mikael! After trying various solutions for days, yours was the only one that worked. AND, you get a nice “system time” display along with it. Only too bad I found your post last.