Perform a calculation on time off-sets in a template

I have a new smart washing machine and am setting up an automation to have it start during off-peak electricity (overnight). I have a helper already which contains the schedule for off-peak and one of the attributes of that is the end time in the morning.

The washing machine has a sensor which calculates the time needed for the programmed cycle to complete, as a string.

What I want to do is come up with a calculated start time which is “cycle time” before “end time”.

So, my end time is

{{ state_attr('binary_sensor.off_peak_electricity','before') }}

which gives 2024-01-25T07:30:00+00:00

Whereas the cycle time is

{{ strptime(states('sensor.front_load_washer_remaining_time'),"%H:%M:%S") }}

which gives 1900-01-01 00:00:00

So, I’ve managed to get far enough such that they’re both times, but obviously the cycle time has the wrong year and it’s not at all clear how to take one from the other (timedelta?). Am I wrong in using strptime, perhaps?

If someone could offer some advice, I’d be most grateful.

Thank you,

{{ state_attr('binary_sensor.off_peak_electricity','before')|as_datetime - 
   states('sensor.front_load_washer_remaining_time')|as_timedelta }}

That’s fantastic. Thank you so much!

The more I learn, the more I realise I have to learn.

1 Like