Creating a templateable timer trigger, want input

So, input_datetime exists, and an obvious use for it is creating some sort of alarm-clock event (say, slowly turning lights on/bluer to wake you up).

This is currently somewhat fiddly, the simplest solution is to add a time sensor:

sensor:
  - platform: time_date
    display_options:
      - time

Then add a template trigger to compare the times:

automation:
  - alias: Wake me up
    trigger:
      platform: template
      value_template: "{{ states('sensor.time') >= states('input_datetime.alarm_clock')[:5] }}"
    action:
      ...

Which works, though you also need to do something about the fact that it’ll run if you restart home-assistant after the alarm time.

I have a custom component which lets me do this instead:

automation:
  - alias: Wake me up
    trigger:
      platform: time_template
      at: "{{ states('input_datetime.alarm_clock') }}"
    action:
      ...

No time sensor, no worrying about post-start-state, less template complexity.

I’m inclined to flesh out the tests, write some docs, and submit a PR. But, there are options:

  1. Should this be a template config as part of the main time trigger, something like
    trigger:
      platform: time
      template:
        value_template: "{{ states('input_datetime.alarm_clock') }}"
        entity_id: # optional, but shown here to show why we need template as a dict
          - input_datetime.alarm_clock
  1. Should there be hour/minute/second options? (I actually have these in my custom component, but can remove for the sake of code reduction and they need a whole bunch of tests)
  2. Or, should I add something under the template trigger:
    trigger:
      platform: template
      at_template: "{{ states('input_datetime.alarm_clock') }}"

Opinions? Particularly opinions of home-assistant devs, since you’ll be reviewing it :stuck_out_tongue:

I like your thinking.
I personally would prefer your option 1. (don’t quite see the need for the entity id as you have already given a ‘presumably’ valid template address/evaluation to parse)
Though option 3 would be acceptable but a bit less ‘clean’ especially for beginners (like me)
Option 2 would be my least preferred option, though it should be easy to work around if that were done. Having said that what do we have that needs to be controlled to sub-minute intervals ? and if that is the case just use a delay or run a script ???

I say this, as the current method (setting a binary sensor to evaluate : value_template: ‘{{ (states.input_datetime.yourdttmentity.timestamp | int | timestamp_custom("%H:%M", False)) == now().strftime("%H:%M") }}’ ) and then using that in another trigger/condition template is TEDIOUS and easy to ‘malechicken’-up !

Mutt