hi,
could somebody pls help me with the timeformats in a automation template?
i had extented my notification in my automation with the triggered time duration, where i want to have just hours&minutes shown. e.g. (0:15) for 15 minutes
I had to do a lot of trial and error with timeformats until it worked at all (so im happy its working now )…
{% elif trigger.entity_id == "binary_sensor.aqara_dw_47_contact" %}
{% if is_state("binary_sensor.aqara_dw_47_contact", "on") %}
Window OPEN Office2 since {{ ((now() -
timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
({{(timedelta(seconds=(trigger.for.seconds)))}})
{% else %}
… but i can´t get rid of the seconds…
unfortunately you can´t test a trigger time in devtools/template editor, but you will need datetime objects to test convertings… but now()
seems not the same as single timedelta
from a trigger?.. anyhow…
so i tried to “convert” the result and force to H:M… but its not valid.
1st try
{% elif trigger.entity_id == "binary_sensor.aqara_dw_47_contact" %}
{% if is_state("binary_sensor.aqara_dw_47_contact", "on") %}
Window OPEN Office2 since {{ ((now() -
timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
({{(timedelta(seconds=(trigger.for.seconds)).strftime('%H:%M'))}})
{% else %}
2nd try
{% elif trigger.entity_id == "binary_sensor.aqara_dw_47_contact" %}
{% if is_state("binary_sensor.aqara_dw_47_contact", "on") %}
Window OPEN Office2 since {{ ((now() -
timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
({{(timedelta(seconds=(trigger.for.seconds))).strftime('%H:%M')}})
{% else %}
Error rendering data template: UndefinedError: 'datetime.timedelta object' has no attribute 'strftime'
how should i do it correctly? or how can i made a simple string out of my result and cut off the last 3 characters?
thank you
br
Frank
2 posts - 1 participant