Convert time in minutes

Hi,

I wanna built a timer coutdown for a script that can be use to delay turn off a device. So, on my wallpanel I would like to display the minutes remaining before the device will turn off.

To do that, on my script, before calling the delay sequence I set a mqtt sensor that will hold the “stop hour”.
So by exemple if I call my script at 15h00 and use a timer of 10, I’ll have in my sensor 15h10.

Now, I’m trying to get the minutes between my “stop hour” and now.

{% set stoptime = strptime(states.sensor.stoptimertimer.state, "%H:%M") %}

{{ stoptime }}

{{ strptime( now().strftime("%H:%M"), "%H:%M") }}

{{ (stoptime - (strptime( now().strftime("%H:%M"), "%H:%M")))  }}

With that, I’m getting the difference in a result like this :

0:03:00

How can I “convert” this to always get an integer (3).

Thanks in advance

I’m not sure if your method will work when crossing midnight. This method should. Then all you need to do is adjust the timestamp_custom’s format. Or you can store that whole string and parse it like the first line.

{% set Hour, Minute = states.sensor.stoptimertimer.state.split(’:’) %}
{% set seconds = Hour | int *3600 + Minute | int * 60 %}
{{ (as_timestamp(now()) + seconds) | timestamp_custom("%H:%M:%S") }}