Notify or do something when an appliance like a dishwasher or washing machine finishes

Github Gist: https://gist.github.com/sbyx/6d8344d3575c9865657ac51915684696

Explanation

This one is pretty simple. It triggers a set of user defined actions when some appliance like a dishwasher or washing machine has finished after running. It uses a power sensor to detect finishing. First we check that the thing has been started, i.e. crossing a certain power threshold for a given time. This is necessary so the action is not triggered at startup or after reloading automations. Then we detect that the appliance has finished by waiting until it crosses below a certain power level for some time. The actions to perform e.g. push notification or TTS announcement via Google Home can be freely chosen.

Blueprint Code

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

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

Or import this Blueprint by using the forum topic / Gist URL:

blueprint:
  name: Appliance has finished
  description: Do something when an appliance (like a washing machine or dishwasher)
    has finished as detected by a power sensor.
  domain: automation
  input:
    power_sensor:
      name: Power Sensor
      description: Power sensor entity (e.g. from a smart plug device).
      selector:
        entity:
          domain: sensor
    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
    actions:
      name: Actions
      description: Actions (e.g. pushing a notification, TTS announcement, ...)
      selector:
        action: {}
    pre_actions:
      name: Actions
      description: Actions when starting threshhold is crossed
      selector:
        action: {}
  source_url: https://gist.github.com/sbyx/6d8344d3575c9865657ac51915684696
trigger:
- platform: numeric_state
  entity_id: !input 'power_sensor'
  for:
    minutes: !input 'starting_hysteresis'
  above: !input 'starting_threshold'
condition: []
action:
- choose: []
  default: !input 'pre_actions'
- wait_for_trigger:
  - platform: numeric_state
    entity_id: !input 'power_sensor'
    below: !input 'finishing_threshold'
    for:
      minutes: !input 'finishing_hysteresis'
- choose: []
  default: !input 'actions'
mode: single
max_exceeded: silent

Changelog

  • 2022-03-04: Add additional action block at startup
  • 2020-12-30: Increase hysteresis resolution to 1/4 minutes
  • 2020-12-27: Relax selector since HA has very inconsistent device_classes.
  • 2020-12-13: Initial version

My blueprints

74 Likes

Thanks! FYI I had to add the following into my customize.yaml as my TP Link HS110 wasn’t detected as device_class power by default.

sensor.my_tp_switch_watts:
  device_class: power
1 Like

Can you explain why the action uses choose that offers only one condition and that condition always evaluates to true. Seems like a lot of code for nothing.

1 Like

Yeah that solution with choose is not very elegant. The underlying problem I had was I tried first with this:

action:
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: !input power_sensor
        below: !input finishing_threshold
        for:
          minutes: !input finishing_hysteresis
action: !input actions

however that way wait_for_trigger wasn’t executed and the notification was fired instantly. I tried several other varaints but they all resulted in some sort of syntax error. So next best thing that came to my mind was a choose with an always-true condition and that somehow worked. If anyone has a proper solution I would appreciate it.

1 Like

I think the question was , why do you have such condition, as it should work without it anyway… Even it is not a condition, its just a declaration :slight_smile:

RIght, okay was probably just too lazy to test if it works without the condition :wink:

If nothing else, it would be a good submission to a code-obfuscation contest.

4 Likes

I changed it now to:

  - choose: []
    default: !input actions

If you prefer using Github Gist over the forum posts I will now track this Blueprint here: https://gist.github.com/sbyx/6d8344d3575c9865657ac51915684696

Link has been added to the original post as well.

With the notify is there a way to only send the notification to people who are actually at home? Like if the washing is finished and I am at work I don’t want the notification.

Sure, I am not predefining any actual notification here you can freely define that in the actions section if you want to notify via the app based on the device being in the WiFi for example or if you have person tracking in HA you can do something like this (taken from one of my automations):

You would need one such choose-block for every person.

Thanks for the blueprint, works great! The hysteresis in minutes is a bit coarse, but it works. Easily changeable to seconds (or both a minutes and seconds slider) if I really wanted.

For the conditions you could also add a condition action before your notification. I have an input_boolean for “quiet mode” which I use to turn off announcements when it is on (condition is state, input_boolean.quiet_mode ‘off’)

I’ve also adapted a version of this to an acceleration/vibration sensor using a SmartThings multipurpose sensor (class: moving) rather than power sensor for my dryer and dishwasher which can’t use a power sensor (dryer is 240V, dishwasher is hard wired).

blueprint:
  name: Appliance has finished shaking
  description: Do something when an appliance (like a washing machine or dishwasher)
    has finished as detected by a vibration sensor.
  domain: automation
  input:
    vibration_sensor:
      name: Vibration Sensor
      description: 'Vibration sensor entity (e.g. from a multipurpose sensor). Needs to have device_class:
        moving'
      selector:
        entity:
          domain: binary_sensor
          device_class: moving
    starting_hysteresis:
      name: Starting hysteresis
      description: Time duration the sensor has to stay on.
      default: 5
      selector:
        number:
          min: 1.0
          max: 60.0
          unit_of_measurement: min
          mode: slider
          step: 1.0
    finishing_hysteresis:
      name: Finishing hysteresis
      description: Time duration the sensor has to stay off.
      default: 5
      selector:
        number:
          min: 1.0
          max: 60.0
          unit_of_measurement: min
          mode: slider
          step: 1.0
    actions:
      name: Actions
      description: Actions (e.g. pushing a notification, TTS announcement, ...)
      selector:
        action: {}
trigger:
- platform: state
  entity_id: !input 'vibration_sensor'
  to: 'on'
  for:
    minutes: !input 'starting_hysteresis'
condition: []
action:
- wait_for_trigger:
  - platform: state
    entity_id: !input 'vibration_sensor'
    to: 'off'
    for:
      minutes: !input 'finishing_hysteresis'
- choose: []
  default: !input 'actions'
mode: single
max_exceeded: silent
11 Likes

I have an entity pulled in from my Fibaro HC2 which I am trying to customise to include the device class of power. No matter what I do, I can’t seem to get this blueprint to use the entity I need.

I’ve added customize.yaml to configuration. customize.yaml shows this for the device…

switch.garage_tumble_dryer_29:
  device_class: power

What am I doing wrong?

Usually the switch itself will not give the power measurement but only has a state ‘on’ or ‘off’ related to if it switched off or on. However there should be a separate sensor entity (maybe with a similar name) that provides it. I don’t own any Z-Wave gear so not particularly sure how it works with those in practice.

If I use the entity in an automation it shows me some of the other attributes like the power measurements. I wonder if it’s because I’m pulling it in via Fibaro.

Screenshot 2020-12-21 at 15.30.07

Also shows here that the device class is power?

Screenshot 2020-12-21 at 15.33.40

The device is a switch, the power is an attribute of the switch (current_power_w).
You will need to make a template sensor to use this with the blueprint as-is, or change the blueprint to use the current_power_w attribute of this switch entity.

To add the attribute as a power sensor and keep the blueprint the same, add this to configuration.yaml:

  - platform: template
    sensors:
      garage_tumble_dryer_29_watts:
        friendly_name_template: "{{ states.garage_tumble_dryer_29.name}} power"
        value_template: '{{ states.switch.garage_tumble_dryer_29.attributes["current_power_w"] |float }}'
        unit_of_measurement: 'W'

Also note that this doesn’t make it a power sensor, so you will need to manually type the entity “sensor.garage_tumble_dryer_29_watts” into the sensor entity.

I havn’t checked on whether you can specify an attribute in blueprints, so don’t have code for that. This does work though - my power sensor (TP-Link Kasa) is an attribute using this code.

1 Like

Instead of creating a template sensor in the above post, you could instead modify the blueprint to use the current_power_w attribute of your switch.
To do this, change the following:
Change:

      name: Power Sensor
      description: "Power sensor entity (e.g. from a smart plug). Needs to have device_class: power"
      selector:
        entity:
          domain: sensor
          device_class: power

to

      name: Power Sensor
      description: "Power sensor entity (e.g. from a smart plug). Needs to be a switch with a current_power_w attribute"
      selector:
        entity:
          domain: switch
#          device_class: power

and

trigger:
- platform: numeric_state
  entity_id: !input 'power_sensor'
  for:
    minutes: !input 'starting_hysteresis'
  above: !input 'starting_threshold'
condition: []
action:
- wait_for_trigger:
  - platform: numeric_state
    entity_id: !input 'power_sensor'
    below: !input 'finishing_threshold'
    for:
      minutes: !input 'finishing_hysteresis'
- choose: []
  default: !input 'actions'

to

trigger:
- platform: numeric_state
  entity_id: !input 'power_sensor'
  attribute: current_power_w
  for:
    minutes: !input 'starting_hysteresis'
  above: !input 'starting_threshold'
condition: []
action:
- wait_for_trigger:
  - platform: numeric_state
    entity_id: !input 'power_sensor'
    attribute: current_power_w
    below: !input 'finishing_threshold'
    for:
      minutes: !input 'finishing_hysteresis'
- choose: []
  default: !input 'actions'
4 Likes

Absolute magic :slight_smile:

Went with the second option as I have a few of these devices so it seemed to be the simplest way to cater for all of them.

Thank you for your help.

Thanks for this automation but is there a way to get the amount of time that the dish washer/washing machine has been above the threshold so that the energy usage can be worked out?