Runtime Counter for Switches, Binary Sensors or Input_Boolean

:clock3: Home Assistant Blueprint: Runtime Counter for Switches, Binary Sensors or Input_Boolean.

A simple and universal automation blueprint to track the total runtime of a device like a washing machine, pump, fan, or any other device based on a switch , binary_sensor or input_boolean.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

:package: Features

  • :white_check_mark: Counts runtime in minutes
  • :white_check_mark: Works with switches, binary_sensors or input_boolean.
  • :white_check_mark: Stores time persistently in an input_number helper
  • :white_check_mark: Fully survives restarts
  • :white_check_mark: Can start from any initial value (e.g. 243h 10m = 14,590 minutes)
  • :white_check_mark: Easily expandable / reusable for multiple devices
  • :white_check_mark: Displayable as h, min via a template sensor

:memo: Comparison: Blueprint vs. history_stats sensor

Aspect Blueprint solution history_stats sensor
Counting method Explicitly increments a counter (input_number) every 1 minute when the entity is "on" Calculates duration based on the entityโ€™s state history
Storage Operating time is permanently stored in an input_number (survives restarts) Value is recalculated after every restart from the history database
Independence from history Works independently of the history database Depends on a working and complete history database
Manual adjustability Value can be manually adjusted or reset Value comes only from history; manual adjustment is not possible
System load Low load (simple increment once per minute) Queries history database; can be slower with large data sets
Precision Accurate to the minute (or interval you define) Very precise (based on exact timestamps)
Persistence / backup Operating hours are retained even if history is deleted Data is lost if history is deleted or pruned
Configuration Needs an automation + input_number Requires only a history_stats sensor
Dependence on DB size None Yes, larger DB can affect performance

:white_check_mark: Advantages of the Blueprint solution

:one: Persistence independent of history
:arrow_right: The counted minutes remain available even if the history is deleted or after a restart (because stored in input_number).

:two: Low database usage
:arrow_right: Does not repeatedly query large history data. Just writes a small counter value.

:three: Manually adjustable
:arrow_right: The input_number can be reset or adjusted at any time through the UI (for example, when replacing a device).

:four: No loss due to history cleanup
:arrow_right: Even if the database is corrupted or history is purged, your counter value is safe.

:five: Easy to export or use elsewhere
:arrow_right: You can directly use the value in dashboards, automations, or reports without needing to query history.

:six: Fixed time base
:arrow_right: You define the interval (e.g. 1 min), whereas history_stats depends on state changes (which may miss data if events are lost).


:warning: When is history_stats the better choice?

  • When you want to analyze past activity like โ€œHow long was the switch on today?โ€
  • When you donโ€™t want to create extra helpers (input_number).
  • When you only need temporary or on-demand calculations based on existing history.

:bulb: Summary

The Blueprint solution is best if you want a persistent, history-independent, and manually adjustable counter.
The history_stats sensor is ideal for on-demand analytics based on state history.

:toolbox: Requirements

  • One switch , binary_sensor or input_boolean entity (e.g. switch.washing_machine or binary_sensor.dryer_running)
  • One input_number helper to store minutes (you can create this in Settings โ†’ Devices & Services โ†’ Helpers)

:wrench: Example Input Number Helper

Create an input number helper in Home Assistant with:

  • Name: Runtime Washing Machine
  • Min: 0
  • Max: 100000
  • Step: 1
  • Initial Value: 14590 (if you want to start from 243h 10m)

:bar_chart: Optional: Template Sensor for h , min Display

Add this to your configuration.yaml to display the time in a readable format:

template:
  - sensor:
      - name: "Betriebsstunden Waschmaschine Anzeige"
        unit_of_measurement: "h min"
        state: >
          {% set total_minutes = states('input_number.betriebszeit_waschmaschine') | int %}
          {% set hours = total_minutes // 60 %}
          {% set minutes = total_minutes % 60 %}
          {{ hours }} h {{ minutes }} min

:bulb: Use Cases

  • :basket: Washing machines
  • :dash: Ventilation fans
  • :droplet: Water pumps
  • :electric_plug: Any device that can be represented by a binary state (on/off)

Changelog


:new: Version 1.01

:spiral_calendar: Release Date: 2025-06-18

:sparkles: Whatโ€™s New

:white_check_mark: Added support for input_boolean entities
You can now select input_boolean helpers in addition to switch and binary_sensor for runtime tracking.


:hammer_and_wrench: Why this matters

This makes the blueprint more flexible, especially for virtual devices, helpers, or custom toggles like:

  • "Washer Running"
  • "Fan Override"
  • "Manual Mode Switch"

:wrench: Updated input selector:

domain:
  - switch
  - binary_sensor
  - input_boolean

:speech_balloon: Feedback

Feel free to share improvements, ideas, or use cases!
:hammer_and_wrench: This blueprint is designed to be simple, universal, and easy to modify.

1 Like

Nice. Maybe a good idea to list the differences with the History Stats sensor? I think the initial start count and being able to track longer than the recorder purge window are at least two of them.

Thanks for the hint. Exactly the two reasons you mentioned were what made me want to look into it a bit more. Iโ€™ll add it.