Subracting Time from Time (HA Timer)

Hi I am not new to HA but I always just done simple things on it.

I am looking to get into the more advanced parts of HA.

To give a bit of background, with working from home I need to keep my time management perfect for breaks. Unfortunately there was no way to do a stopwatch so instead I’ve created a timer helper and I use this and it displays on my main lovelace, however when I need to check how much time I have used I always have to calculate this myself from the duration of the timer minus the remaining time.

I want to try use templates to do this but cannot seem to get it working.

Can anyone help?

Below is a picture of my entity in HA. I want to subract the remaining attribute from the duration attribute

Please post what you’ve tried. Also, please post actual text and not a screenshot. We can’t copy/paste from a screenshot. Please format your code as well.

I have browsed the forums here and tried the following but to no avail

{{state_attr('timer.break_timer', 'duration') | float - state_attr('timer.break_timer', 'remaining') | float }}
{{ state_attr('timer.break_timer', 'duration') | as_timedelta - state_attr('timer.break_timer', 'remaining') | as_timedelta }}

Wow you’re awesome! Thankyou so much!

@petro I have added this and added a template sensor with that in so that I can easily display it, however it doesnt update in realtime like the timer does. Is there something I’m doing wrong or is it just not possible

Add a trigger to it if you want it to update on the minute or on the second. Use a time_pattern trigger.

1 Like

Great I’m assuming it would be better to do by minute to avoid rate limit issues

I don’t think it would be an issue to have it update on the second. It’s a pretty quick calculation. You won’t get rate limited with trigger templates anyways.

1 Like