Hi everybody,
I am trying to get the earliest time value from multiple sensors, then calculate a time value from it.
{% set my_entities = [
'sensor.b1_next_scheduled_backup',
'sensor.b2_next_scheduled_backup'
] %}
{% set berechnen = my_entities|map('states')|sort|first %}
{{ berechnen }}
{% set berechnen = (as_timestamp(berechnen | replace(" ", "T"))) %}
{{ berechnen }}
{% set berechnen = berechnen | int %}
{{ berechnen }}
{% set berechnen = berechnen | timestamp_custom("%H:%M") %}
{{ berechnen }}
Output is
2024-05-07T10:35:00+00:00
1715078100.0
1715078100
12:35
This is all correct so far. But I cannot calculate anything from hereon.
This works
{{ now() }}
{{ now() - timedelta(minutes=5) }}
2024-05-07 07:50:22.396507+02:00
2024-05-07 07:45:22.396516+02:00
Why won’t this work?
{{ berechnen - timedelta(minutes=5) }}
TypeError: unsupported operand type(s) for -: 'str' and 'datetime.timedelta'
I have tried countless versions of this, none of which worked (so I won’t bother pasting all failed attempts here).
The final code should use a variable via input_number
instead of 5
for minutes. And then subtract this value from {{berechnen}}
, which, in this case, is 12:35
.
Thanks in advance for your help