A history graph of a switch tells you it was on. It does not survive a recorder purge, and it is a poor way to know that a filter has 300 hours on it. This blueprint adds elapsed time to an input_number. Helpers are not purged with the recorder, and they come back after a restart.
The total is in minutes, with two decimal places, so a partial minute is not thrown away. A template sensor in the pack prints that total as hours and minutes.
A filter or coil that should also be judged by whether the room actually changes temperature is HVAC health monitor. A fan that should run from a temperature, rather than only be timed, is printer enclosure fan. A page when a battery is low, which is a different kind of maintenance, is low battery alerts.
What problem it solves
You want a running total for a pump, a fan, a heater, or a filter, in a helper you can reset when you service it, including time that does not line up with the clock.
How it works
- What is running. You pick one entity and a comma-separated list of states that count (default
on). Leave the attribute blank to read the state. For a climate entity that should count only while it is actually heating, set the attribute tohvac_actionand the states toheating. Usingheatwith a blank attribute counts the whole time the mode is heat, including when the equipment is idle. - Every minute. A time pattern fires each minute. If the entity is running, the blueprint adds the minutes since the last sample. That is about one minute. The last sample is an
input_datetimethe blueprint updates. - The partial minute. When the entity leaves a running state, the blueprint adds the minutes since the last sample and then moves the sample time forward. A run that lasts 40 seconds still counts. A run that lasts 90 seconds counts the minute tick plus the leftover.
- Restarts. The
input_numberis the total, so a restart does not zero it. On Home Assistant start, if the entity is already running, the blueprint adds the gap since the last sample, up to one day. A gap longer than a day is ignored and the sample clock starts fresh, so a new helper does not dump a year into the counter. Time while Home Assistant was off and the entity was not running is not added. - Service interval. Set the hours input above 0 (a filter at 300, for example). The first time the total crosses that many hours, the blueprint calls your notify action once. Resetting the total to 0 lets it notify again the next time you cross the line. 0 disables the notification.
- Reset. The input button sets the total to 0 and refreshes the sample time. It does not turn the watched entity off.
The template sensor assumes the helper id input_number.runtime_minutes. It shows hours:minutes, for example 300:05.
Snippet
The states that count, and the add, are the parts you will change first.
variables:
watched: !input watched
on_states: !input on_states
attribute: !input attribute
counter: !input counter
triggers:
- trigger: time_pattern
minutes: "/1"
id: tick
- trigger: state
entity_id: !input watched
id: change
The minutes added on a tick, and the partial add when the entity stops, are in the pack. Both use the last-sample helper so the two paths do not double-count the same minute.
Setup outline
- Copy
helpers/runtime_hours.yamlandhelpers/runtime_hours_sensor.yamlintoconfig/packages/. Packages have to be enabled (homeassistant: packages: !include_dir_named packages). Restart, and confirminput_number.runtime_minutes,input_button.runtime_reset,input_datetime.runtime_last_sample, andsensor.runtime. - Copy
blueprints/automation/runtime_hours_counter.yamlintoconfig/blueprints/automation/edotdev/and reload blueprints. - Create the automation. Pick the entity. Leave the states at
on, or sethvac_actionandheatingfor a climate entity that is only “on” while heating. - Leave the three helper inputs on the package defaults unless you renamed them. Set the service interval to 0 until you want the notification.
- Turn the entity on for a couple of minutes, then off. The input number should move, and
sensor.runtimeshould show hours and minutes. Press the reset button. The total should return to 0.
Troubleshooting
- The total does not move. The entity’s state is not in the list. A fan that reports
onis fine. A climate entity sitting inheatwithhvac_action: idlewill not count if you asked forheating. Read the state and the attribute in Developer tools and match the inputs. - It jumped by a large number on the first run. The last-sample helper was empty or very old, and the entity was already running. The blueprint refuses a gap over one day. If the first add is still wrong, press reset. After that, each minute adds about one minute.
- A short on-off added nothing. The automation did not reload after you saved it, or the state change was an attribute that stayed inside the running list and the gap was under a tenth of a second. Turn it on, wait for one minute tick, then turn it off. You should see the tick and the partial.
- The service notification fired again after a restart. The total was already past the interval, and a new add crossed the line a second time only if the stored value was still below it. If you set the interval below the current total, the next add can notify immediately. Set the interval, then reset, if you want a clean run up to that number.
sensor.runtimeis unknown. The template package is looking forinput_number.runtime_minutes. Rename the entity id insideruntime_hours_sensor.yamlif your helper has another id.- Reset did not clear a climate runtime. The button clears the helper. It does not change the climate entity. If the entity is still heating, the next minute adds time again. That is the counter working.
Credits
A counter stored in an input number, instead of in recorder history, is the idea in Runtime counter for switches, binary sensors, or input_boolean.