HomeAbout MeContact Me
Make your washing machine smarter with Home Assistant
Smart Home
Make your washing machine smarter with Home Assistant
Emanuele Papa
Emanuele Papa
June 01, 2019
2 min

Do you own an old washing machine and do you ever think about how to make your washing machine smarter? Would you have better information about the current washing cycle?

Well, you can do it today, you just need a couple of things:

  • a smart plug with energy monitoring feature
  • an Home Assistant instance running somewhere (e.g. on your Raspberry)

Smart plug integration

Each smart plug is different from another so you have to figure out how to integrate your into Home Assistant.

In my setup I used a TP-Link HS-110 and I integrated it into my Home Assistant as shown here.

After the successful integration you should have a new sensor which reports the current consumption, and this is the one you are going to use to monitor your washing machine!

Washing machine integration

The following snippet of code is an Home Assistant package, you can just copy-paste it into a whatever_you_want.yaml file into your packages directory; the only thing you need to do is to replace PUT_YOUR_ENERGY_CONSUMPTION_SENSOR_NAME_HERE with your current consumption sensor name!

homeassistant:
customize_glob:
"*washing_machine*":
icon: mdi:washing-machine
input_text:
washing_machine_enriched_status:
name: 'Washing Machine Enriched Status'
initial: "Off"
sensor:
- platform: template
sensors:
washing_machine_status:
friendly_name: 'Washing Machine Status'
value_template: >
{% if states.sensor.PUT_YOUR_ENERGY_CONSUMPTION_SENSOR_NAME_HERE .state | float > 3.0 %}
{{ "Running" }}
{% elif states.sensor.PUT_YOUR_ENERGY_CONSUMPTION_SENSOR_NAME_HERE .state | float > 1 %}
{{ "On" }}
{% else %}
{{ "Off" }}
{% endif %}
washing_machine_info:
friendly_name: 'Washing Machine Info'
entity_id: sensor.time
value_template: >
{%- macro as_formatted_elapsed_time(now, other_date_time) %}
{% set duration = as_timestamp(now) - as_timestamp(other_date_time) %}
{% set seconds = (duration % 60) | int %}
{% set minutes = ((duration / 60) | int) % 60 %}
{% set hours = (duration / 3600) | int %}
{{ [hours, "hours", minutes, "minutes", seconds, "seconds"] | join(' ') }}
{%- endmacro %}
{% if states.input_text.washing_machine_enriched_status.state == "Running" %}
Washing machine running for: {{ as_formatted_elapsed_time(now(), states.input_text.washing_machine_enriched_status.last_changed)}}
{% elif states.input_text.washing_machine_enriched_status.state == "On_After_Running" %}
Clothes left in the washing machine for: {{ as_formatted_elapsed_time(now(), states.input_text.washing_machine_enriched_status.last_changed)}}
{% elif states.input_text.washing_machine_enriched_status.state == "On_After_Off" %}
{{ "Washing machine ready to start" }}
{% else %}
{{ "Washing machine is off" }}
{% endif %}
automation:
- id: '1556314846684'
alias: Refresh Washing Machine Info
initial_state: true
trigger:
platform: state
entity_id: sensor.washing_machine_status
action:
- service: input_text.set_value
data_template:
entity_id: input_text.washing_machine_enriched_status
value: >
{% if trigger.to_state.state == "Running" %}
{{ "Running" }}
{% elif trigger.to_state.state == "On" and trigger.from_state.state == "Running" %}
{{ "On_After_Running" }}
{% elif trigger.to_state.state == "On" and trigger.from_state.state == "Off" %}
{{ "On_After_Off" }}
{% else %}
{{ "Off" }}
{% endif %}

Detailed explanation

Let me explain a bit about what this package does:

Here we are just telling Home Assistant to use a washing machine icon for all the sensors containing the string washing_machine

homeassistant:
customize_glob:
"*washing_machine*":
icon: mdi:washing-machine

Here we declare a sensor, washing_machine_status, to keep track of the status of the washing machine. There are three possible status: Running, On and Off. You would need to tune the watts value according to your washing machine to detect when it’s running or just turned on.

washing_machine_status:
friendly_name: 'Washing Machine Status'
value_template: >
{% if states.sensor.PUT_YOUR_ENERGY_CONSUMPTION_SENSOR_NAME_HERE .state | float > 3.0 %}
{{ "Running" }}
{% elif states.sensor.PUT_YOUR_ENERGY_CONSUMPTION_SENSOR_NAME_HERE .state | float > 1 %}
{{ "On" }}
{% else %}
{{ "Off" }}
{% endif %}

Here we setup an automation to store in an input_text (couldn’t find a better way) the enriched status of our washing machine: the enriched status is a status which keeps track of the previous one. So for example, if the washing machine was off and you turn it on, the status would be On, but the enriched status would be On_After_Off.

automation:
- id: '1556314846684'
alias: Refresh Washing Machine Info
initial_state: true
trigger:
platform: state
entity_id: sensor.washing_machine_status
action:
- service: input_text.set_value
data_template:
entity_id: input_text.washing_machine_enriched_status
value: >
{% if trigger.to_state.state == "Running" %}
{{ "Running" }}
{% elif trigger.to_state.state == "On" and trigger.from_state.state == "Running" %}
{{ "On_After_Running" }}
{% elif trigger.to_state.state == "On" and trigger.from_state.state == "Off" %}
{{ "On_After_Off" }}
{% else %}
{{ "Off" }}
{% endif %}

This is just the simple declaration of the variable holding the enriched status of the washing machine.

input_text:
washing_machine_enriched_status:
name: 'Washing Machine Enriched Status'
initial: "Off"

Here we declare another sensor, washing_machine_info, which will keep us informed of the washing machine’s current status and will also tell us more information (e.g. for how long the washing machine is running). The sensor will be updated every minute since it has a dependency on sensor.time: you can customize this behaviour adding another automation to refresh it faster or slower, but I think every minute is enough. as_formatted_elapsed_time is a macro used to display the elapsed time between two moments.

washing_machine_info:
friendly_name: 'Washing Machine Info'
entity_id: sensor.time
value_template: >
{%- macro as_formatted_elapsed_time(now, other_date_time) %}
{% set duration = as_timestamp(now) - as_timestamp(other_date_time) %}
{% set seconds = (duration % 60) | int %}
{% set minutes = ((duration / 60) | int) % 60 %}
{% set hours = (duration / 3600) | int %}
{{ [hours, "hours", minutes, "minutes", seconds, "seconds"] | join(' ') }}
{%- endmacro %}
{% if states.input_text.washing_machine_enriched_status.state == "Running" %}
Washing machine running for: {{ as_formatted_elapsed_time(now(), states.input_text.washing_machine_enriched_status.last_changed)}}
{% elif states.input_text.washing_machine_enriched_status.state == "On_After_Running" %}
Clothes left in the washing machine for: {{ as_formatted_elapsed_time(now(), states.input_text.washing_machine_enriched_status.last_changed)}}
{% elif states.input_text.washing_machine_enriched_status.state == "On_After_Off" %}
{{ "Washing machine ready to start" }}
{% else %}
{{ "Washing machine is off" }}
{% endif %}

Finally, you can just put your new sensor washing_machine_info into your UI and you will get very useful information about your washing machine, making it actually smarter.

Furthermore, you can use the statuses we collect here, and their time-based changes, to make other automations like send you a Telegram notification when the washing machine cycle ends, but at the moment that’s left to your imagination!


Tags

Share


Previous Article
Build your smart car’s on-board computer!
Emanuele Papa

Emanuele Papa

Android Developer

Related Posts

Block ads using DNS over TLS with AdGuard Home, Let's Encrypt, and Cloudflare for Android Devices
Block ads using DNS over TLS with AdGuard Home, Let's Encrypt, and Cloudflare for Android Devices
October 22, 2024
3 min

Quick Links

HomeAbout MeContact MeRSS Feed

Social Media