Trigger an Action on Specific Date & Time

I’ve created Date & Time sensor already (named sensor.date__time) and I want to try to set an automation to trigger at a specific date and time is this trigger correct? I’m still pretty new to this and feel like it might be right but wanted to make sure I’m on the right path. (in my example I’m intending to have it trigger tomorrow at 11:21)

- alias: 'Test reminder'
    platform: template
    value_template: "{% if is_state('sensor.date__time', '2017-03-11, 11:21') %}true{% endif %}"
    - service: notify.Pushetta_1
        message: "TEST"

Yeah that is pretty much it BUT this will trigger A LOT on the 11th of march on 11:21 because this automation gets checked for EVERY state change within HA. So every state change would check your template in this very minute and trigger the automation.

To do it only once I would suggest using another trigger…like this one:

But take note of the warning box “Remember that if you are using matching to include both minutes and seconds. Without seconds, your automation will trigger 60 times during the matching minute.”


so maybe something like this would work?

    platform: time
    hours: 16
    minutes: 0
    seconds: 0
    condition: template
    value_template: '{{ == "2017-03-11" }}'

I would prefer “now().date()” instead of “” but that’s just me, it should work like that just fine.


I’ve looked and looked and couldn’t find any examples of the “now().date()” you mention… so I just want to be sure something like this looks right to you (thanks again for all of your help)

    platform: time
    hours: 9
    minutes: 0
    seconds: 0
    condition: template
    value_template: '{{ now().date() == "2017-03-12" }}'

I got the “now()” from here:
You can test your templates in the Web-UI of HA btw. (the value_template). For this you go to your HA website, open the navigation tab to the left, on the bottom there are 5 icons. The 5th says “templates”. Click there and you get to a site where you can test 'em :slight_smile:


Is the code above accurate? I am trying to do this exact same thing and it is not working.

I used the “templates” section, nice to know about. And the below condition shows false? any idea what to change?

condition: template
value_template: ‘{{ now().date() == “2017-05-11” }}’

And all my spaces are correct, I am not getting any errors. Just that the value_template is false.

now().date() returns a date, “2017-05-11” a string.
Convert your date to a string and it works.

{{ now().date() | string == "2017-05-11" }}


Perfect, thanks!!!

What about this? And why not this if the previous string conversion example also works?

{{ now().strftime("%Y-%m-%d") == "2017-11-01" }}

One seems to be a filter and the other a function? I don’t know this stuff much…

1 Like

I like this idea - will hopefully allow me to do something like this:

{{ now().strftime("%m-%d") == "10-03" }}

So I can run an action on the same time, same day every year :smile:


I came across this post when looking for a solution to my requirement.

I want to setup a list of month/days on which to trigger an event, in this case it is the refuse disposal schedule for a 1 year period. The dates are NOT always previous date + 7 days, so I was thinking to use an array something like this:


Is this the best way of doing this, and if so how would I go about coding it, given that this is a ‘pseudo’ array ?

Where do you get the dates from to begin with.
Perhaps there is a way to skip the manual work completely?

But that could work, only thing I would add is an empty array at the beginning to make january [1] not [0].
Another option which will be easier to code in HA would be if the format is [“2023-01-01”, “2023-01-07”, … “2023-03-20”…]