I don’t kjnow of an “easy” way to do it but I would do it by having an automation that triggers every second (time_pattern) and make the condition be the entity being ‘on’. the action would be to increment a counter every time the automation runs the actions (ie. every second while the entity is on).
then you can take the value of the counter and convert that to H:M:S using a template.
Perhaps you can use two entities for this.
The history stats to keep track during the day, then just before midnight you have an automation that takes the value and adds it to a helper.
If you use the yesterday example in history stats, at midnight it will update the total for the last 24 hours. Then create an automation that adds to a counter when the sensor updates.
Use the today example for the time during the current day. Finally use a template sensor to add the counter and today sensor if you want a current running total.
So to test I created this using the history stats. It is updating as my light remains on.
Then you guys seem to be saying at end of day, add this number, lets say its 0.8 hours, to a counter. But a counter only counts in seconds, right? I see you specify duration is 24 hours, but I don’t know how to integrate that into a counter.
alias: Half Bath Timer Activation
description: Activate the timer for the half bath
trigger:
- platform: device
type: turned_on
device_id: 80fc931335816d62657bd1e191872c9a
entity_id: switch.half_bath_light
domain: switch
condition: []
action:
- service: timer.start
data:
duration: '180'
target:
entity_id: timer.halfbath_timer
mode: single
This turns on fan for 90 seconds
alias: Half Bath Fan Run
description: Turn on Half bath fan if light was turned after after being on for
at least 3 minutes
trigger:
- platform: device
type: turned_off
device_id: 80fc931335816d62657bd1e191872c9a
entity_id: switch.half_bath_light
domain: switch
condition:
- condition: state
entity_id: timer.halfbath_timer
state: idle
action:
- type: turn_on
device_id: 4984c7129c2427afae9c21906c566402
entity_id: switch.half_bath_fan
domain: switch
- delay:
seconds: '{{ states(''input_number.fan_runtime'')| int }}'
- type: turn_off
device_id: 4984c7129c2427afae9c21906c566402
entity_id: switch.half_bath_fan
domain: switch
mode: single
There is a service call counter.configure that let’s you set the counter’s current value. On sensor update you could add to the current count then set that value.
So I did a node-red solution that integrates with a input_number helper. (@Hellis81 thats the other post you have been responding too)
I do everything else in node red, so I wanted to keep this in there too. I didnt think it was possible, which is why I originally made the post. But then found there is a way.
FWIW, I use a History Stats sensor to compute daily run time (for heating, cooling, etc) combined with the Utility Meter integration to keep a running tally of daily/weekly/monthly/yearly data.
The Utility Meter integration records its data in long-term storage (statistics table) and is unaffected by the recorder’s purge cycles.
Hi, please could you tell me how to create a status counter when an entity is in the “on” state and that is not cut by the recorder? I haven’t found a solution yet.