Skip to content

Instantly share code, notes, and snippets.

@jtebert
Last active October 5, 2024 00:39
Show Gist options
  • Save jtebert/c1330f9f2a2c8ef8b53bbf7baf4e46cb to your computer and use it in GitHub Desktop.
Save jtebert/c1330f9f2a2c8ef8b53bbf7baf4e46cb to your computer and use it in GitHub Desktop.
HA appliance finished template (with duration)
blueprint:
name: Appliance has finished (with duration)
description: Do something when an appliance (like a washing machine or dishwasher) has finished as detected by a power sensor. Calculates the duration and makes it available for actions.
domain: automation
input:
power_sensor:
name: Power Sensor
description: Power sensor entity (e.g. from a smart plug device).
selector:
entity:
domain: sensor
appliance_name:
name: Appliance Name
description: Name of the appliance (used in notifications and for creating a unique ID)
selector:
text:
starting_threshold:
name: Starting power threshold
description: Power threshold above which we assume the appliance has started.
default: 5
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: W
mode: slider
step: 1.0
starting_hysteresis:
name: Starting hysteresis
description: Time duration the power measurement has to stay above the starting power threshold.
default: 5
selector:
number:
min: 0.25
max: 60.0
unit_of_measurement: min
mode: slider
step: 0.25
finishing_threshold:
name: Finishing power threshold
description: Power threshold below which we assume the appliance has finished.
default: 5
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: W
mode: slider
step: 1.0
finishing_hysteresis:
name: Finishing hysteresis
description: Time duration the power measurement has to stay below the finishing power threshold.
default: 5
selector:
number:
min: 0.25
max: 60.0
unit_of_measurement: min
mode: slider
step: 0.25
notification_service:
name: Notification Service
description: The notification service to use (e.g., notify.mobile_app_your_phone)
selector:
entity:
domain: notify
notification_message:
name: Notification Message
description: The message to send when the appliance finishes. You can use {{appliance_name}} and {{duration_minutes}} in your message.
selector:
text:
multiline: true
pre_actions:
name: Start Actions
description: Actions when starting threshold is crossed (optional)
default: []
selector:
action: {}
source_url: https://gist.github.com/jtebert/c1330f9f2a2c8ef8b53bbf7baf4e46cb
variables:
appliance_name: !input appliance_name
notification_service: !input notification_service
notification_message: !input notification_message
trigger:
- platform: numeric_state
entity_id: !input power_sensor
for:
minutes: !input starting_hysteresis
above: !input starting_threshold
action:
- variables:
start_time: "{{ now().timestamp() }}"
- service: persistent_notification.create
data:
notification_id: "appliance_start_{{ appliance_name|replace(' ', '_')|lower }}"
message: "{{ appliance_name }} started at {{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
- choose:
- conditions: "{{ pre_actions|default(false) }}"
sequence: !input pre_actions
- wait_for_trigger:
- platform: numeric_state
entity_id: !input power_sensor
below: !input finishing_threshold
for:
minutes: !input finishing_hysteresis
- variables:
end_time: "{{ now().timestamp() }}"
duration_minutes: "{{ ((end_time - start_time) / 60) | round(0) }}"
- service: persistent_notification.create
data:
notification_id: "appliance_finish_{{ appliance_name|replace(' ', '_')|lower }}"
message: "{{ appliance_name }} finished at {{ now().strftime('%Y-%m-%d %H:%M:%S') }}. Duration: {{ duration_minutes }} minutes."
- service: '{{ notification_service }}'
data:
message: >
{{ notification_message | replace('{{appliance_name}}', appliance_name) | replace('{{duration_minutes}}', duration_minutes | string) }}
mode: single
max_exceeded: silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment