Home Assistant

Runtime hours counter that survives restarts

While a switch, sensor, fan, or climate entity is running, elapsed minutes accumulate in an input_number. The total survives a restart and a recorder purge. A button resets it, and a service interval can notify once.

Difficulty · BeginnerSetup · 20–40 minutesHA · 2024.10 or newer
Get the pack · from $19Have us set it up

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

  1. 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 to hvac_action and the states to heating. Using heat with a blank attribute counts the whole time the mode is heat, including when the equipment is idle.
  2. 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_datetime the blueprint updates.
  3. 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.
  4. Restarts. The input_number is 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.
  5. 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.
  6. 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

  1. Copy helpers/runtime_hours.yaml and helpers/runtime_hours_sensor.yaml into config/packages/. Packages have to be enabled (homeassistant: packages: !include_dir_named packages). Restart, and confirm input_number.runtime_minutes, input_button.runtime_reset, input_datetime.runtime_last_sample, and sensor.runtime.
  2. Copy blueprints/automation/runtime_hours_counter.yaml into config/blueprints/automation/edotdev/ and reload blueprints.
  3. Create the automation. Pick the entity. Leave the states at on, or set hvac_action and heating for a climate entity that is only “on” while heating.
  4. Leave the three helper inputs on the package defaults unless you renamed them. Set the service interval to 0 until you want the notification.
  5. Turn the entity on for a couple of minutes, then off. The input number should move, and sensor.runtime should 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 on is fine. A climate entity sitting in heat with hvac_action: idle will not count if you asked for heating. 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.runtime is unknown. The template package is looking for input_number.runtime_minutes. Rename the entity id inside runtime_hours_sensor.yaml if 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.

Changelog

v1.0 · Nov 1, 2026: First publish.