How to set date/time helper to current date?

I’ll try to take advantage of your kindness once more, do you know how to trigger an action X minutes before an input_datetime?

I’ve been searching and trying for 5 hours to no avail

For five minutes (300s), adjust as appropriate:

  - platform: template
    value_template: "{{ now()|as_timestamp - states('input_datetime.ENTITY_ID')|as_timestamp(0) < 300 }}"

Did i make any mistake? Does not seem to work

{{ now()|as_timestamp - states('input_datetime.sveglia_ora')|as_timestamp(0) < 1800 }}

What is the state of that date_time helper? Date / time or just time?

The input helper is set to time only

Try this (I also got it the wrong way around last time):

  - platform: template
    value_template: "{{ today_at(states('input_datetime.sveglia_ora'))|as_timestamp(0) - now()|as_timestamp < 1800 }}"

You can try the template out in Developer Tools / Template.

1 Like

Getting this error now

Message malformed: invalid template (TemplateAssertionError: No filter named 'as_timetamp'.) for dictionary value @ data['value_template']

Sorry, typo now fixed. You are allowed to try to fix things yourself…

I’m already trying my best :frowning:

Getting this now in the dev tools as a result

Tipo di risultato: boolean


That means it’s less than 30 minutes until the time in your helper (or past that time). Should go false at midnight, then true (triggering the automation) at 30 minutes before tomorrow’s time.

Not sure why, pasting it for the fourth time seemed to do the trick

Thank you so much, i was getting crazy over this, spent over 7 hours on it. If HA is great is thanks to people like you