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
.
Features
Counts runtime in minutes
Works with switches, binary_sensors or input_boolean.
Stores time persistently in an
input_number
helperFully survives restarts
Can start from any initial value (e.g. 243h 10m = 14,590 minutes)
Easily expandable / reusable for multiple devices
Displayable as
h, min
via a template sensor
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 |
Advantages of the Blueprint solution
Persistence independent of history
The counted minutes remain available even if the history is deleted or after a restart (because stored in
input_number
).
Low database usage
Does not repeatedly query large history data. Just writes a small counter value.
Manually adjustable
The
input_number
can be reset or adjusted at any time through the UI (for example, when replacing a device).
No loss due to history cleanup
Even if the database is corrupted or history is purged, your counter value is safe.
Easy to export or use elsewhere
You can directly use the value in dashboards, automations, or reports without needing to query history.
Fixed time base
You define the interval (e.g. 1 min), whereas
history_stats
depends on state changes (which may miss data if events are lost).
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.
Summary
The Blueprint solution is best if you want a persistent, history-independent, and manually adjustable counter.
Thehistory_stats
sensor is ideal for on-demand analytics based on state history.
Requirements
- One
switch
,binary_sensor
orinput_boolean
entity (e.g.switch.washing_machine
orbinary_sensor.dryer_running
) - One
input_number
helper to store minutes (you can create this in Settings โ Devices & Services โ Helpers)
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)
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
Use Cases
Washing machines
Ventilation fans
Water pumps
Any device that can be represented by a binary state (on/off)
Changelog
Version 1.01
Release Date: 2025-06-18
Whatโs New
Added support for
input_boolean
entities
You can now select input_boolean
helpers in addition to switch
and binary_sensor
for runtime tracking.
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"
Updated input selector:
domain:
- switch
- binary_sensor
- input_boolean
Feedback
Feel free to share improvements, ideas, or use cases!
This blueprint is designed to be simple, universal, and easy to modify.