Hey, first time posting
I’m running into the following error for a while now. The following code snippet from my blueprint is from a trashcalendar reminder that triggers a telegrambot notification.
variables:
time: !input time
type: !input type
now: '{{now()}}'
trigger:
- platform: template
value_template: "{{ as_timestamp(states[type].attributes.start_time) - as_timestamp(now)/(60*60) | int <= float(time) }}"
Unfortunately it is not triggering and sequencially throwing the following error.
I’ve read through some of your posts. You mentioned that it is possible to use variables in templates outside triggers. So would a repeating timed trigger with the same template as a condition work?
exp:
variables:
time: !input time
type: !input type
now: '{{now()}}'
trigger:
- platform: time
at: '00:10'
condition:
- condition: template
value_template: "{{ as_timestamp(states[type].attributes.start_time) - as_timestamp(now)/(60*60) | int <= float(time) }}"
variables:
time: !input time
type: !input type
now: '{{now()}}'
trigger:
- platform: time
at: !input time
If that doesn’t work, try making a sensor or binary sensor using platform: template in your configuration and passing that as a selector into your blueprint
Also, i struggle with the intricacies of the syntax, but should: as_timestamp(now)/(60*60) | int <= float(time)
be as_timestamp(now) | int / (60*60) <= float(time)
It surprises me to hear that it works. as_timestamp(now()) produces a Unix timestamp which is a large value, much larger than 24. Therefore it will always be larger than the value of time (even after division by 60*60).
{{ (as_timestamp(states.calendar.papier.attributes.start_time) -
as_timestamp(now()))/(60*60) | int <= float(6) }}
gives back False. Increasing 6 to 600 gives back True.
The raw value of the attribute ist formatted like this:
2021-02-10 06:00:00
“as_timestamp()” gives out this:
1612933200.0
as_timestamp() should give back the time in seconds since our calendar (gregorian) hast started (or at least I understood it this way). Because of this assumption I divide by 3600 to get it into hours and take the difference to compare to.
Edit: I just saw that one of my code snippets only contains the second part of the equation. My bad! Since I’m subtracting the timestamps off another, the value stays in a processable range.