Help with automation and template to fire when manual datetime is input

Looking for some help getting an automation working based off of user input in an input_datetime:
I’m just looking to have user input from someone to set a time and when that time gets reached to turn on a switch. Just using it to smarten up our crockpot a little. Sometimes we’ll be at work and need to “delay” in starting it so the easiest thing to do would just to be set a time when it should come on.
I’ll let you know how far I’ve gotten and hope you can help me get it across the finish line.
I created an input_datetime component:

    name: "Start Crockpot Time"
    has_date: true
    has_time: true  

Want to be able to input the date and time because I don’t want it accidentally turning on again tomorrow.

Then added datetime sensor

  • platform: time_date
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘time_date’
    • ‘time_utc’
    • ‘beat’

Everything seems to be fine to this point. I put them both in a card and checking the sensors in the dev tools it looks fine.
I set off to make the automation and this is where I’m getting stuck. I think with the template.

Here is my automation (excuse the repurposed christmas tree plug):

  alias: crockpart_start_time
    - platform: template
      value_template: "{{ states('sensor.date_time') == states.input_datetime.crockpot_start_time.state | timestamp_custom('%Y-%m-%d, %H:%M', false) }}"
    service: switch.turn_on
      - switch.christmas_tree 

I’ve been playing around with the template builder in the tools and I have it close but I’m not sure if it’s not liking it because there isn’t a comma in there or what. I can’t seem to figure out how to get that comma to be in the string. Also not sure if it doesn’t like that the input has seconds or how to get rid of those. I’ve reached the end of my templating skills and hope someone can help.
Here is the output in the template builder.

Try this one:

value_template: "{{ states('sensor.date__time') == (states.input_datetime.crockpot_start_time.attributes.timestamp | int | timestamp_custom('%Y-%m-%d, %H:%M', True)) }}"

I use this to change my heating setting to vacation mode (I run 0.75.3 in my live environment), but it should still work)…


Perfect! This got me the right format for sure. It’s still not triggering but now that I have this thats one less variable to figure out why it’s not triggering.

Actually that was the fix. The only reason it wasn’t working was you had an extra underscore in your example and I copied and pasted it in my automations.yaml then when I was playing with it in the template I noticed it and took it out and forgot to take it out of my automatons file. Thanks a heap!

You’re welcome!
Now that you mention it, I seem to remember that this (_ vs. __) was a breaking change several versions ago.

Hello, it doesn’t work for me :disappointed_relieved:.
I want to start an automatisation at an specific time define by an input:
i use your code:

  - platform: date_time 
      - 'date'     
      - 'time'


- id: '1594723468692'
  alias: Aspirateur
  description: ''
  - platform: template
    value_template: 'value_template: "{{ states(''sensor.date_time'') == (states.input_datetime.heure_passage_aspirateur.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', True)) }}"'
  condition: []
  - data:
      message: testes
    service: notify.notify

Can please someone help?

So your template uses date_time but you haven’t set up date_time and have only set up : -

These are not the same

Not sure what’s going on here with the nested value_templates. Also, ref @Mutt’s response, you don’t need to add sensor.date_time — you only need sensor.time as your input.date_time is just time (Heure). So:

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

The “[0:5]” takes the first five characters, and is needed because sensor.time is hh:mm, whereas input_datetime is hh:mm:ss.

The template he ‘said’ he wants to use, needs it - That’s why !

If he wants a daily trigger then, yes he can forgo both the date and date_time
And can adjust the template as per your suggestion

Wasn’t a criticism — you’re of course correct that if sensor.date_time is being used, it must first be set up. I just wanted to be clear that with a time-only helper set up as per screenshot, there is actually no need for it at all.

Thank you both!!
@Troon solution was what i needed but does it still need the cod below in conf?

  - platform: date_time 
      - 'date'     
      - 'time'

@Mutt thanks for the help, but i am noob and i haven’t understand all of your explanation.

The community on this plateform is awersome, i always ad an aswer in no time!
You rock guy’s!

For this example, you still need the 'time', yes, and I’ve just noticed it should be platform: time_date, not date_time. Because the automation uses sensor.time, you need:

  - platform: time_date
      - 'time'

…and you’ll need to restart HA to load this sensor in.

This integration provides a number of different sensors (read the docs), and allows you to specify only the ones you want to keep things clean and succinct. @Mutt’s point was that the automation you were proposing used sensor.date_time but you had not set that up.

The code I suggested does not use sensor.date_time, just sensor.time, so that’s all you need to set up in this case. If you have other automations using or sensor.date_time, you need to add those lines to the display_options.