Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save napalmz/9c886fb4ae95d78c806a3052e372a9dc to your computer and use it in GitHub Desktop.

Select an option

Save napalmz/9c886fb4ae95d78c806a3052e372a9dc to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Notify or do something when an appliance like a dishwasher or washing machine start or finishes
blueprint:
name: Appliance has started/finished (with duration + energy)
description: |
# Appliance has started/finished (with duration + energy)
Do something when an appliance (like a washing machine or dishwasher) has started/finished as detected by a power sensor.
You can use some parameters in the actions:
- {{ duration_str }} (es. 1:45 o 1:11:12)
- {{ duration_s }}
- {{ energy_used }} (same unity of measure of energy sensor)
- {{ energy_uom }} (es. kWh, Wh)
- {{ energy_used_wh }} (Wh, if calcolable)
ℹ️ Version 2025.12.17
domain: automation
input:
power_sensor:
name: (Required) Power Sensor
description: Power sensor entity (W).
selector:
entity:
domain: sensor
energy_sensor:
name: (Required) Energy Sensor (cumulative)
description: >
Optional but required if you want energy_used. Use a cumulative energy sensor
(e.g. kWh total/today). Must monotonically increase during a cycle.
selector:
entity:
domain: sensor
starting_threshold:
name: (Required) Starting power threshold
default: 5
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: W
mode: slider
step: 1.0
starting_hysteresis:
name: (Required) Starting hysteresis
default: 5
selector:
number:
min: 0.25
max: 60.0
unit_of_measurement: min
mode: slider
step: 0.25
finishing_threshold:
name: (Required) Finishing power threshold
default: 5
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: W
mode: slider
step: 1.0
finishing_hysteresis:
name: (Required) Finishing hysteresis
default: 5
selector:
number:
min: 0.25
max: 60.0
unit_of_measurement: min
mode: slider
step: 0.25
pre_actions:
name: Actions when started
description: Actions when starting threshold is crossed
default: []
selector:
action: {}
actions:
name: Actions when finished
description: Actions when finishing threshold is crossed
default: []
selector:
action: {}
trigger:
- platform: numeric_state
entity_id: !input power_sensor
for:
minutes: !input starting_hysteresis
above: !input starting_threshold
condition: []
action:
# Capture "start" snapshot
- variables:
start_ts: "{{ now().timestamp() | float }}"
energy_entity: !input energy_sensor
energy_uom: "{{ state_attr(energy_entity, 'unit_of_measurement') if energy_entity else none }}"
energy_start: "{{ states(energy_entity) | float(0) if energy_entity else none }}"
# User pre-actions (can use start_ts / energy_start)
- choose: []
default: !input pre_actions
# Wait for "finished"
- wait_for_trigger:
- platform: numeric_state
entity_id: !input power_sensor
below: !input finishing_threshold
for:
minutes: !input finishing_hysteresis
# Capture "end" snapshot + computed deltas
- variables:
end_ts: "{{ now().timestamp() | float }}"
duration_s: "{{ (end_ts - start_ts) | int }}"
duration_str: >-
{% set s = (end_ts - start_ts) | int %}
{% set h = s // 3600 %}
{% set m = (s % 3600) // 60 %}
{% set sec = s % 60 %}
{% if h > 0 %}
{{ '%d:%02d:%02d'|format(h,m,sec) }}
{% elif m > 0 %}
{{ '%d:%02d'|format(m,sec) }}
{% else %}
{{ sec }}
{% endif %}
energy_end: "{{ states(energy_entity) | float(0) if energy_entity else none }}"
energy_used: >-
{% if energy_entity %}
{{ (energy_end - energy_start) | float }}
{% else %}
{{ none }}
{% endif %}
energy_used_wh: >-
{% if energy_entity and energy_uom in ['kWh','kwh'] %}
{{ ((energy_end - energy_start) * 1000) | round(1) }}
{% elif energy_entity and energy_uom in ['Wh','wh'] %}
{{ (energy_end - energy_start) | round(1) }}
{% else %}
{{ none }}
{% endif %}
# User actions (can use duration_* and energy_* variables)
- choose: []
default: !input actions
mode: single
max_exceeded: silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment