Hi everyone,
Let me share with you a little project I’have been working on: automating a washing machine with nothing but power consumption.
It all started when my wife and I realised that the clothes would stay inside the washing machine for too long because it only gives a quick beep indicating that the cycle is over. This was bad because if left for too long, clothes get smelly and we have to wash all over again. The problem is that the washing machine has no sensors at all. I could build a sensor to monitor the indications lights, but I live in a rental and, eventually I will live this place. So how could I do this in an easy way? The answer: monitoring the power consumption.
Here you can see three different runs, one after another. Because it’s a washing machine with a washing and drying cycles, you can see two distinct pattern separating the both cycles.
I’m monitoring the power consumption with a TP-Link HS 110. It can stand loads up to 3KW, enough to not catch on fire when used to monitor a washing machine.
To store the washing machine states, I have a input_select:
input_select:
dishwasher_status:
name: Dishwasher Status
options:
- Dirty
- Running
- Drying
- Clean
initial: Dirty
Because I don’t like the way Home Assistant implements automations, I had two choices: write my own app using a simple python script, or using node-red to create a workflow doing the same. As a software developer, a python script would be a no-brainer choice, but because it would use native HA calls, I would have to write an abstraction layer to decouple the code from HA and I didn’t have spare time for this.
So, I used node-red, that provides this abstraction layer and also allows me to easily expand the level of functionalities provided. Here’s the workflow:
As you can see, the flow kicks in on every new data coming from the power plug (every 30 seconds). Then it gets the current state of the machine and the average of the last 4 minutes of data. This is important because the data is a little noite and can through the logic under the bus if I use live data. The rest, is just a simple state machine that evaluates the current states and the average consumption, following the ranges: 5-399, washing. 400+, drying. Below 4, the cycle is over.
A stateless implementation like this, with no intermediate variables, allows me to achieve two important things: 1. the flow can be interrupted at any moment and it will self asses later on to see where things are. 2. I don’t have to worry with a cycle that’s only washing or only drying, as it will detect the correct states regardless.
To achieve the automation I wanted, all state changes are followed by mobile notifications. The washing and drying notifications are just simple messages, but the one that informs of a clean batch, has some actions associated with it. Here’s the ios configuration:
ios:
push:
categories:
- name: WMOptions
identifier: 'wmoptions'
actions:
- identifier: 'CLEAR'
title: 'Ok, I have cleared it!'
activationMode: 'background'
authenticationRequired: true
destructive: false
behavior: 'default'
- identifier: 'SNOOZE'
title: 'Remind me in 5 minutes'
activationMode: 'background'
authenticationRequired: true
destructive: false
behavior: 'default'
Going back to the flow, you can see on the bottom part that I capture the actions coming from iOS and process accordingly to the action requested: Snooze 5 minutes or let HA knows the machine was emptied.
There’s a lot of thing I still want to do to make this even more functional:
- Notify only people who are at home, as it pointless to inform people who are out and about. I already have a variable with this information, so it’s an easy thing to do.
- A door sensor to detect if the washing machine door was opened after the end of the cycle. This will eliminate the need of action items on the final mobile notification.
- Explore other types of notification: TTS over the sound system (or just a simple beep), on screen notifications on some platforms…
I hope this inspires you doing something similar!