Help: remaining time in minutes

Hi there,
I am struggling calculating the remaining time of a sensor (timestamp information). The idea is, the calculate the remaing time in minutes until the timestamp given by the sensor.
I am fine calculation the remaining time compared to a fixed time unable to change it to the timestamp.

states(‘sensor’) → 2023-08-26T11:59:43+00:00
following approach works, but I am unable to replace time by the timestamp of the sensor.
{% set time = “14:45” %}
{{ (((as_timestamp(strptime(time, “%H:%M”))) - as_timestamp( strptime( now().strftime("%H:%M"), “%H:%M”) )) /60) | int}}

Any help would be apprecaited - thanks
JJ

Copy-paste the following template into the Template Editor, change sensor.example to your sensor’s entity_id and then confirm it reports the correct remaining time in minutes.

{{ (states('sensor.example') | as_datetime - now()).total_seconds() // 60 }}

Thank you so much - that works! Great!

1 Like