Tutorial - Automate your washing machine with a smart plug

Hello everyone,

Here I will show you how to easily smartify a washing machine with just one outlet and achieve a result like this:

Note: This tutorial will evolve, and some screenshots will change over time as bugs are fixed or features are added. The changelog will be available at the end of the tutorial

I will include many screenshots without necessarily accompanying text, but if you have any questions, remarks, or suggestions, feel free to ask :wink:

I was heavily inspired by the tutorial on Domo-Blog, which you can find here:
https://www.domo-blog.fr/comment-connecter-et-monitorer-la-machine-a-laver-sous-la-domotique-home-assistant/


Prerequisites:

  • MQTT integration
  • Zigbee2Mqtt integration
  • A Zigbee smart plug (In my case, this one)
  • Having integrated your Zigbee smart plug into the Zigbee2Mqtt integration

1. Creating the washing machine device in the MQTT integration:


2. Creating features on the MQTT washing machine device:


3. Creating the EDF device in the MQTT integration:


1. Creating the device to retrieve the last day of the month:


4. Creating the feature on the MQTT EDF device:


5. Creating the scene for EDF to indicate the cost of your subscription:
You can automate this task with the following tutorial:
https://community.gladysassistant.com/t/tuto-recuperer-le-prix-de-son-abonnement-delectricite-via-le-site-data-gouv-fr/8838

Run this scene manually once, and the next time your rate changes, if you don’t use automation :wink:


6. Creating the washing machine running scene:



7. Creating the washing machine stopped scene:


8. Creating the monthly reset scene:

9. Creating the static values refresh scene:

If you don’t run your machine for 48 hours, some values no longer appear on the Dashboard. This value is found in Settings → Gladys System:

I have therefore created a scene that updates the values with the same values every 24 hours at a time when I know my machine won’t be running :wink:


10. Creating the annual values refresh scene:

A small note on this scene, you will need to modify this date every year

11. Creating the Node-Red flow to retrieve the last day of the month:

[
    {
        "id": "b7191a33c07d23e0",
        "type": "tab",
        "label": "Check last day of current month",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "d0e045cb.9f4ef",
        "type": "http request",
        "z": "b7191a33c07d23e0",
        "name": "WorldTime API",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "http://worldtimeapi.org/api/ip",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 260,
        "y": 200,
        "wires": [
            [
                "91df43f4.81a518"
            ]
        ]
    },
    {
        "id": "91df43f4.81a518",
        "type": "function",
        "z": "b7191a33c07d23e0",
        "name": "Extract Month",
        "func": "var current_month = msg.payload.datetime.substring(5, 7);\nmsg.current_month = parseInt(current_month);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 430,
        "y": 260,
        "wires": [
            [
                "7894f4e2.dcb4f4"
            ]
        ]
    },
    {
        "id": "7894f4e2.dcb4f4",
        "type": "function",
        "z": "b7191a33c07d23e0",
        "name": "Determine Last Day of Month",
        "func": "var months_30_days = [4, 6, 9, 11];\nvar months_31_days = [1, 3, 5, 7, 8, 10, 12];\n\nif (months_30_days.includes(msg.current_month)) {\n    msg.payload = 30;\n} else if (months_31_days.includes(msg.current_month)) {\n    msg.payload = 31;\n} else {\n    var current_year = parseInt(msg.payload.datetime.substring(0, 4));\n    if ((current_year % 4 == 0 && current_year % 100 != 0) || current_year % 400 == 0) {\n        msg.payload = 29; // Leap year\n    } else {\n        msg.payload = 28;\n    }\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 640,
        "y": 320,
        "wires": [
            [
                "b55312bdd26f4bda"
            ]
        ]
    },
    {
        "id": "fbac43b9673078da",
        "type": "mqtt out",
        "z": "b7191a33c07d23e0",
        "name": "",
        "topic": "gladys/master/device/mqtt:datetime/feature/mqtt:last-day-of-current-month/text",
        "qos": "2",
        "retain": "true",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "0ee77e0f90aa9681",
        "x": 1220,
        "y": 440,
        "wires": []
    },
    {
        "id": "b55312bdd26f4bda",
        "type": "function",
        "z": "b7191a33c07d23e0",
        "name": "Extract Day",
        "func": "const payload = msg.payload;\nmsg.payload = payload;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 860,
        "y": 380,
        "wires": [
            [
                "fbac43b9673078da"
            ]
        ]
    },
    {
        "id": "65287af29bc457b9",
        "type": "cronplus",
        "z": "b7191a33c07d23e0",
        "name": "",
        "outputField": "payload",
        "timeZone": "",
        "storeName": "",
        "commandResponseMsgOutput": "output1",
        "defaultLocation": "",
        "defaultLocationType": "default",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "topic1",
                "payloadType": "default",
                "payload": "",
                "expressionType": "cron",
                "expression": "30 00 1 * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 100,
        "y": 160,
        "wires": [
            [
                "d0e045cb.9f4ef"
            ]
        ]
    },
    {
        "id": "0ee77e0f90aa9681",
        "type": "mqtt-broker",
        "name": "Gladys",
        "broker": "mqtt://192.168.0.248",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

12. Creating the scene for the monthly cost graph if the end of the month is the 30th:

13. Creating the scene for the monthly cost graph if the end of the month is the 31st:

14. Graph on the dashboard to track month by month:


Just a small clarification for the 2-minute wait on the washing machine stopped scene, I had to do this because even at 1 minute with my washing machine, the scene was triggered as it must have been a moment when the washing machine went to 0W and after 1 minute was at 0W, in any case, I explain it like this
 ^^
I haven’t had any more problems after changing it to 2 minutes


Changelog to come:

  • None (Your comments :slight_smile: )

Edit 10/04/2024:

  • Modification of the triggering value (Power taken) to take into account the delayed start
  • Addition of the calculation for the cost over 1 month

Edit 12/04/2024:

  • Correction of several bugs

Edit 16/04/2024:

  • Addition of the link for electricity tariff recovery automation
  • Bug detected and currently attempting to resolve concerning the scene « Washing machine stopped Â» which runs several times especially at the end of the cycle :frowning:

Edit 21/04/2024:

  • Correction of the bug on the washing machine stopped scene that was running several times at the end of the cycle
  • Addition of a scene so that the values are always displayed on the Dashboard according to the parameter « Delay before state expiration Â»
  • Implementation of rounding to 2 decimal places on the cost + 3 decimal places on the last wash consumption
  • Addition of annual cost

Edit 22/04/2024:

  • Mea culpa, the bug was not corrected at all, it’s done now :slight_smile:
  • Optimization of the scene « Washing machine stopped Â»

Edit 03/05/2024:

  • Addition of a graph to track the cost month by month

Great tutorial, that’s what I already do at home (basically) but I never took the time to make a tutorial
 So a big thank you!! :grin:

Yes indeed, thanks, I just corrected it :slight_smile:

Great tutorial, thanks @prohand :slight_smile:

Small change to account for the delayed start
The power draw is 3W from time to time when the machine is waiting to start during a delayed start

I can’t be stopped anymore :sweat_smile:
I just added the calculation for the cost of the current month

You’re on fire right now :grin:

I hesitated to set the annual cost but I’ll wait to see if this part is already well worked out :slight_smile:

Shared on Twitter:

A big thank you :slight_smile:

Small mistake on the washing machine running scene regarding action 2 — it should be set to 0
I’ll fix the screenshot as soon as I can :wink:

Edit: It’s fixed

@pierre-gilles I just realized that the calculations don’t work when used in « Send an MQTT message Â»:

The value in MQTT here is not replaced by the calculation performed.

Is this normal or is it a bug?

Edit: Solution found by using buffer features (MQTT topic to listen to)

Edit 2: The tutorial is up to date :slight_smile:

I have a quick question regarding the decimal places for the currency feature.

I see that in the MQTT broker the value is:

image

But the display shows:

We can see that for the power feature we do have multiple decimal places — is there a restriction somewhere? How can I change it for the currency to display 2 decimal places?

I would also like to ask how to change the number of decimal places for the power feature to 2 or 3 decimal places, for example?

I saw this but nothing else :frowning: : Dashboard - arrondi des données affichées - #4 par Kevin

I would have liked to vote for this feature request but I’ve reached the vote limit :frowning: : Dashboard - arrondi des donnĂ©es affichĂ©es

Thanks :slight_smile:

Yes, it’s normal — it’s not meant to perform a calculation; it’s meant to concatenate the text, like in the « send a message Â» action.

For your information, I just fixed several bugs.
The tutorial is up to date :wink:

I just added a link to automate the rate via the following tutorial :

https://community.gladysassistant.com/t/tuto-recuperer-le-prix-de-son-abonnement-delectricite-via-le-site-data-gouv-fr/8838

I am trying to fix a bug where the « Washing machine stopped Â» scene is triggered multiple times in a row at the end of the cycle, I will let you know when I have updated the tutorial with the bug fixed

Tutorial update :slight_smile:
See the changelog in the first post.
Thanks :wink:

Last-minute addition regarding the annual cost :slight_smile:
If you have suggestions for new features or bug reports, please don’t hesitate.

Tutorial update :slight_smile:
See the changelog in the first post.
Thanks :wink:

Tutorial update :slight_smile:
See the changelog in the first post.
Thanks :wink: