Saturday, July 16, 2022

Laundry Saver

If you buy a modern washing machine, chances are it has Wi-Fi connectivity and notifications for cycle completion to notify you when your laundry is done. There have been many times that I have forgotten to rotate the laundry, where the clothes start to smell like mildew. I do not have a modern washing machine. After having this happen to me several times last year, I decided to make my own solution. 

I remembered this post about a project called “your laundry is done” that uses a Sonoff (esp8266), a power sensor, and Node-RED for notifications. That inspired me to create something project of my own, calling it “laundry saver”. After having used M5Stack products for several months, I remembered they have an “ATOM Socket” kit. The kit consists of power monitoring and control circuitry (up to 10 amps) and the ATOM Lite which is connected to the socket. The socket could also be controlled by an external device, instead of the ATOM light. 


Description automatically generated

While I love using Node-RED and could have easily taken Xose’s JavaScript function and set it up in a Node-RED flow, I have had enough experience with Arduino programming (C++) that I was able to program the ATOM Socket to detect the cycles and send an MQTT message to Domoticz (when then notifies me via the Pushover app) 10 minutes after no significant power usage is detected (to allow for long fill times on the largest load size). I used a switch case statement to detect and step through the cycles, although ultimately, I would have just needed to send the notification 10 minutes after no significant power usage was detected. To connect the ATOM socket I found a short NEMA cable with the required power rating, and a short extension to angle the washer power cable away from blocking Wi-fi signal to the ATOM socket. For prototyping I just used a box fan to simulate cycling through the loads. 

A picture containing dirty

Description automatically generated

While creating the project I struggled to find some example code that would interface with the power control/monitoring while also being able to communicate via MQTT. I did some searching on GitHub and found this project yoggy/mqtt-m5atom-socket; however upon testing it out, I noticed that phantom button presses occur (which had the effect of randomly disabling power to the ATOM Socket). After doing some research I found that was due to a Wi-Fi sleep setting, which I tested a fix and submitted a pull request to the repository which was merged (yes that is my older Github account). With that out of the way I was ready to do some coding. I installed the M5Atom Arduino library and slapped together a sketch that included cycle completion notification and power monitoring, with all the settings in the config.h file.


Description automatically generated

In Domoticz I created 2 virtual sensors (one for watts and one for voltage), and a virtual switch as a Boolean status if laundry is running. Monitoring watts allows me to calculate the cost of energy usage, and monitoring voltage allows me to detect under/over-volt events such as brownouts or power surges (which helps to correlate electrical funkiness with sensitive equipment around the house).
Graphical user interface, application

Description automatically generated

For the Laundry virtual switch, I set descriptive notifications that I receive via the Pushover app (which I have Domoticz configured to use the Pushover API):
A screenshot of a computer

Description automatically generated

The pushover alerts come in through my phone, and the different priority levels can be used to set separate notification sounds and even bypass do not disturb mode.

I had issues with the ATOM unit staying connected to Wi-Fi until I added another access point to my home setup. I added the AP to the basement to create a better network connection for my lab environment (previously having used the unreliable powerline Ethernet), and it turns the AP not only provides a downlink for my lab environment but extended the Wi-Fi coverage. I had originally thought about modifying the M5Stack ATOM to include an external antenna, but when I added the AP that solved the connectivity issue. Additionally, the mini-extension cable I added made it so the thick power cable did not cover the Atom unit and interfere with Wi-fi connectivity. 

Experimenting with imbalanced load detection

In addition to cycle completion notifications, most modern washing machines also have imbalanced load detection which will stop the cycle (and likely send a notification), and prompt the user to re-balance the load. I attempted to add this feature to the project with an accelerometer. To gather some data I threw an Arduino sketch on the M5Stack Core2 to write the accelerometer readings to a micro SD card. I was able to gather some good data about what the peak movement of some loads look like. 

However, when reading the accelerometer values with the sensor plugged into the ATOM Lite, I was getting some wildly inconsistent values that I could not work with. I am pretty sure that this was due to electrical interference with the accelerometer being connected to the same microcontroller that is also switching and monitoring power to the washing machine (so I ended up disconnecting it and removing the code for this). 

To make this work I might have to wire up a second microcontroller to monitor the accelerometer readings. It’s possible I could just daisy chain another ATOM unit from the first one if power is stable. The switch case statement described above would have facilitated the “imbalanced load” detection by pausing and resuming cycles (with some additional code), to ensure that the “laundry done” alert is only really sent when the last load has finished. Either way, avoiding full loads helps to avoid imbalanced loads, so I don’t have the problem very often.