I have automations that automatically turn certain devices on and off during the day and it is important for me to know how long they have been on. This would normally be a typical stopwatch type application. Start the stopwatch when it turns on and paue it when it turns off.
I know HA doesn't have a stopwatch so I thought a very easy way around this would be setting a timer of 24:00:00 and then turning this timer on and off during the day. To see how long the item was on, simply sutract the remaining time on the timer from 24:00:00 and you can see how long the item was on. To do this, I thought I would use a script which is triggered every second to do the subtractions ... except I can't figure out how to actually do the calculation.
I was thinking something like this:
timers:
mine_max is set to 24:00:00 as duration.
mineml_on_time_today is the timer I keep turning on and off.
- service: input_datetime.set_datetime
metadata: {}
data:
time: "{{ state_attr('timer.mine_max', 'duration') } - { state_attr('timer.mineml_on_timer', 'remaining') }}"
target:
entity_id: input_datetime.mineml_on_time_today
Any suggestions?