3 min read

Washing machine notifications

Teaching Home Assistant to speak Matrix
Washing machine notifications

To solve the problem of the forgotten laundry in the washing machine, I created an automation using Home Assistant and a Maubot plugin which can send me notifications once the washing machine is ready to be opened up. This use-case is an example for the usage of the hasswebhook Maubot plugin.

Hardware

  • Power meter (e.g. TP-Link KP115)
  • A washing machine
  • Magnetic sensor for the door (e.g. Aqara window/door sensor)

Software

Process

missing
BPMN diagram of the whole automation (Full size)

Preparations in Home Assistant

Create Notify Service in Home Assistant

In your configuration.yaml file add a notify service like below.

Replace placeholders:

  • room-id!abcde:example.com (Matrix room where the messages should be sent to)
  • instance-namehassinstance (Name of your plugin instance on your Maubot server)
notify:
  - name: HASS_MAUBOT_WOHNUNG
    platform: rest
    resource: "https://maubot.example.com/_matrix/maubot/plugin/<instance-name>/push/<room-id>"
    method: POST_JSON
    data:
      type: "{{data.type}}"
      identifier: "{{data.identifier}}"
      callback_url: "{{data.callback_url}}"
      lifetime: "{{data.lifetime}}"
      content: "{{data.content}}"
      contentType: "{{data.contentType}}"
      name: "{{data.name}}"
      thumbnailSize: 512

Create input_text helper in Home Assistant

Go to Settings → Devices & Services → Helpers → Create Helper and create a new input_text helper. Mine is named washing_machine_finished_event_id.

Automations in Home Assistant

I created three automations that use a input_text helper to store the event_id of the sent message, which is an important reference for sending the ✅ reaction.

Automation 1 - Send “Washing machine has finished” message

I am using this blueprint from Sbyx for the initial trigger using the power meter: https://community.home-assistant.io/t/notify-or-do-something-when-an-appliance-like-a-dishwasher-or-washing-machine-finishes/254841

Replace placeholders:

  • webhook-id-1234abcd_5678efgh (Some random id, which can also be generated by Home Assistant once you add a webhook trigger to your automation. See Automation 2)
alias: "Wohnung: Washing machine has finished"
description: ""
use_blueprint:
  path: >-
    sbyx/notify-or-do-something-when-an-appliance-like-a-dishwasher-or-washing-machine-finishes.yaml
  input:
    actions:
      - service: notify.hass_maubot_wohnung
        data:
          message: Wäsche ist fertig! 🧺
          data:
            type: message
            lifetime: 360
            callback_url: >-
              https://home-assistant.example.com/api/webhook/<webhook-id>
    starting_hysteresis: 2
    finishing_threshold: 3
    starting_threshold: 5
    power_sensor: sensor.steckdose1_current_consumption

Automation 2 - Receive callback with event_id

Replace placeholders:

  • webhook-id-1234abcd_5678efgh (Some random id, which can also be generated by Home Assistant once you add a webhook trigger to your automation)
alias: "Webhook: Set washing machine finished helper"
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: false
    webhook_id: "<webhook-id>"
condition: []
action:
  - service: input_text.set_value
    data:
      value: "{{trigger.json.event_id}}"
    target:
      entity_id: input_text.washing_machine_finished_event_id
mode: single

Automation 3 - Send ✅ reaction on washing machine opened

Update the code with your device- and helper-ids.

alias: "Wohnung: Washing machine opened"
description: ""
trigger:
  - type: opened
    platform: device
    device_id: 21d23c15e6f6650004719a7416953818
    entity_id: binary_sensor.magnet_bad_2_washing_machine
    domain: binary_sensor
condition:
  - condition: template
    value_template: "{{'clear' != states('input_text.washing_machine_finished_event_id')}}"
action:
  - service: notify.hass_maubot_wohnung
    data:
      message: ✅
      data:
        type: reaction
        identifier: event_id.{{states('input_text.washing_machine_finished_event_id')}}
  - service: input_text.set_value
    data:
      value: clear
    target:
      entity_id: input_text.washing_machine_finished_event_id
mode: single

The Result

missing
You washing machine has finished and the door was already opened (✅)