├── README.md ├── automations.yaml ├── button.gif ├── electric.jpg ├── entity.JPG ├── powerplug.jpg └── wm.png /README.md: -------------------------------------------------------------------------------- 1 | # From Dumb to Smart Washing Machine - Home Assistant 2 | 3 | ![dumb-washing-machine](wm.png) 4 | 5 | Use a power plug with an energy consumption monitor and Home Assistant to transform your dumb washing machine into a "smart" one with a bunch of informative features. Basically, we will use the measurements of power drawn by the washing machine connected in a smart plug (WIFI) with power monitoring. Depending on power drawn we can determine with some accuracy the status of the washing machine and automate some stuff. 6 | 7 | ![eu-br-power-plug](powerplug.jpg) 8 | 9 | ## Before start 10 | 11 | What do I need? 12 | 13 | - A Washing Machine (Serious dude!?) 14 | - :electric_plug: A Smart Power Plug (WIFI) Tuya/SmartLife Compatible (photo above) 15 | - https://a.aliexpress.com/_mLoZBgY (EU Socket Compatible) :european_union: - The one I used! 16 | - https://pt.aliexpress.com/item/1005003106242894.html (Brazilian Socket)) :brazil: 17 | - [Home Assistant](https://www.home-assistant.io/) using [HACS](https://hacs.xyz/) and install: 18 | - [Local Tuya Integration](https://github.com/rospogrigio/localtuya) - yes! The offical Tuya integration still don't have the power monitoring attributes support. 19 | - [Card-mod](https://github.com/thomasloven/lovelace-card-mod) - to create our fancy button on lovelace dashboard 20 | - [Custom Button Card](https://github.com/custom-cards/button-card) - to create our fancy button on lovelace dashboard 21 | 22 | ## Initial Steps 23 | 24 | First of all, I will consider that you _already_ added your smart plug as a switch under the Local Tuya Integration. If you don't know how to do it, I recommend this [video](https://www.youtube.com/watch?v=vq2L9c5hDfQ). As I said, the official Tuya integration doesn't provide the information we need (until the day I'm writing it) and Local Tuya is awesome since it don't rely on Tuya Cloud. So, on my setup the entity id is **switch.lt_lava_roupa** - see the power monitoring entity attributes on developer tools (image below) 25 | 26 | ![lava_roupa_entity](entity.JPG) 27 | 28 | - current 29 | - current consumption 30 | - voltage 31 | 32 | Create the entities from the attributes adding this code to you **configuration.yaml** (or wherever you put it on your home assistant files) 33 | 34 | ```yaml 35 | - platform: template 36 | sensors: 37 | washingmachine_powerdraw: 38 | value_template: '{{ state_attr("switch.lt_lava_roupa", "current_consumption") }}' 39 | unit_of_measurement: 'W' 40 | washingmachine_current: 41 | value_template: '{{ state_attr("switch.lt_lava_roupa", "current") }}' 42 | unit_of_measurement: 'mA' 43 | washingmachine_voltage: 44 | value_template: '{{ state_attr("switch.lt_lava_roupa", "voltage") }}' 45 | unit_of_measurement: 'V' 46 | ``` 47 | 48 | 49 | ## Staring your washing machine and Tuya/SmartLife app 50 | 51 | Yes, now it's time to study your washing machine behaviour. (By the way, you can use this approach in order to transform other dumb devices into smart just analyzing the power consumption). Open you SmartLife/Tuya app (I use SmartLife) - select your smart plug and under **Electric** option you will see this: 52 | 53 | ![electric](electric.jpg) 54 | 55 | The important measurement is the **_Power_** in W (current consumption)! Now you will set some washing program on your machine, stare it and make notes about the consumption/action behaviour. In my case during the Washing the power value is above 1000 but during Rinse its just 500. Make note about every change to make the more accurate automations. 56 | 57 | ## Washing Machine state and automations 58 | 59 | Now we need to create an input_select entity to keep the washing machine state. You can add as many states you want in the options depending on your machine and how accurate were the power variations that define your machine's actions. So, go to your **configuration.yaml** and add the code below. 60 | 61 | ```yaml 62 | input_select: 63 | state_washingmachine: 64 | name: Washing Machine state 65 | options: 66 | - Switched Off 67 | - Powered Down 68 | - Idle 69 | - Rinse / Spin 70 | - Wash 71 | icon: mdi:washing-machine 72 | ``` 73 | So the automations code I've found on this [post](https://community.home-assistant.io/t/washing-machine-power-consumption-trigger/70938/6) from home assistant forums. Thanks user [Callifo](https://community.home-assistant.io/u/callifo) :+1:. Based on your power draw measurement the automations will set the state of your washing machine. Just edit the automations with your washing machine state id and the behaviour of your machine. 74 | 75 | Download and open the [automations.yaml](automations.yaml) file on this project to check it and past the contents into your automations.yaml file on Home Assistant. Remember to change the entity id of your power plug (on this code there is the id of mine power plug). _Repeating, you can customize_ the automations accordingly your washing machine behaviour during the power variations and set the states properly. 76 | 77 | So, right after this step you can use the _service: input_select.select_option_ to play with states changes of **input_select.state_washingmachine** entity on developer tools or start some cleaning program on your washing machine and see if it's behaviour fits the states you set on automations. 78 | 79 | :warning: You need to add your own code to send notifications when the machine finish the job on **Washing Machine - Change State Powered Down** automation. 80 | 81 | ## Washing Machine job time elapsed feature 82 | 83 | In order to make more cool features I added a counter to calculate the time elapsed from the moment the washing machine is powered on and starts washing until it's powered down. Unlike on washing machines that the time set by cleaning program will decrease (since its not possible to know what program you set on machine) - I created this time count thar starts from 00:00 and go. 84 | 85 | Create a counter entity by adding this code to your *configuration.yaml* 86 | ```yaml 87 | counter: 88 | wash_duration: 89 | initial: 0 90 | step: 1 91 | ``` 92 | Add the code below to your *automations.yaml* file. It will increment 1 second to the counter wash_duration from the moment the machine has any state that is not Powered Down or Switched Off. Also the reset automation will reset the counter to 0 when machine is powered down (no current consumption) or switched off (on smart plug). 93 | 94 | ```yaml 95 | - id: washingmachine_startcounter 96 | alias: Counter Washing Machine Start 97 | trigger: 98 | - platform: time_pattern 99 | seconds: /1 100 | condition: 101 | - condition: not 102 | conditions: 103 | - condition: state 104 | entity_id: input_select.state_washingmachine 105 | state: Powered Down 106 | - condition: or 107 | conditions: 108 | - condition: state 109 | entity_id: input_select.state_washingmachine 110 | state: Switched Off 111 | action: 112 | - service: counter.increment 113 | target: 114 | entity_id: counter.wash_duration 115 | mode: restart 116 | - id: washingmachine_resetcounter 117 | alias: Counter Washing Machine Reset 118 | trigger: 119 | - platform: state 120 | entity_id: input_select.state_washingmachine 121 | to: Powered Down 122 | - platform: state 123 | entity_id: input_select.state_washingmachine 124 | to: Switched Off 125 | condition: [] 126 | action: 127 | - service: counter.reset 128 | target: 129 | entity_id: counter.wash_duration 130 | mode: single 131 | ``` 132 | 133 | Back to *configuration.yaml* again on sensor templating add the code below. This sensor will record the time elapsed to be show on your dashboard. 134 | 135 | ```yaml 136 | - platform: template 137 | sensors: 138 | wash_running_time: 139 | value_template: > 140 | {%- set time = states('counter.wash_duration') | int -%} 141 | {%- set seconds = (time % 60) | int -%} 142 | {%- set minutes = ((time % 3600) / 60) | int -%} 143 | {%- set hours = ((time % 86400) / 3600) | int -%} 144 | {% if time == 0 %} 145 | 00:00 146 | {% else %} 147 | {{ '{:02}:{:02}'.format(hours, minutes) }} 148 | {% endif %} 149 | ``` 150 | ## Lovelace Dashboard Button 151 | 152 | Since you have card-mod and button-card lovelace frontend integrations installed you can create the button to show information about the washing machine on your dashboard. Remember that the styles like card size, position and others were made to fit my personal dashboard. As you can see in the code the background color of the button card changes according the state, the icon blinks according to some states and the counter appears on label when the machine is not switched off or powered down. You can change the label to show the current consumption (W) by using the state of _states["sensor.washingmachine_powerdraw"].state;_. Remeber to change the code accordingly yours environment and entities ids: 153 | 154 | ![button](button.gif) 155 | 156 | ```yaml 157 | type: custom:button-card 158 | color_type: auto 159 | entity: input_select.state_washingmachine 160 | name: Lava Roupas 161 | show_state: true 162 | show_label: true 163 | label: >- 164 | [[[ if (entity.state == "Powered Down" || entity.state == "Switched 165 | Off") return ""; else return 166 | states["sensor.wash_running_time"].state;]]] 167 | icon: mdi:washing-machine 168 | styles: 169 | card: 170 | - height: 100px 171 | - width: 124px 172 | - background-color: | 173 | [[[ 174 | if (entity.state == 'Wash' || entity.state == 'Idle' || entity.state == 'Rinse / Spin') return 'rgba(46, 138, 197, 0.3)'; 175 | else return ''; 176 | ]]] 177 | grid: 178 | - grid-template-areas: '"i" "n" "s" "l"' 179 | - grid-template-columns: 1fr 180 | - grid-template-rows: 1fr min-content 181 | img_cell: 182 | - align-self: start 183 | - text-align: start 184 | name: 185 | - justify-self: start 186 | - padding-left: 10px 187 | - font-size: 15px 188 | label: 189 | - justify-self: end 190 | - font-size: 15px 191 | - margin-top: '-150px' 192 | - margin-right: 10px 193 | state: 194 | - justify-self: start 195 | - padding-left: 10px 196 | - font-size: 15px 197 | - margin-bottom: 4px 198 | icon: 199 | - width: 31px 200 | - color: white 201 | - margin-left: '-80px' 202 | - margin-top: '-3px' 203 | - animation: | 204 | [[[ 205 | if (entity.state == 'Wash' || entity.state == 'Rinse / Spin') return 'blink 2s ease infinite'; 206 | ]]] 207 | ``` 208 | 209 | So, thats it! If you like it just add me here and give some ⭐ to this project. 210 | -------------------------------------------------------------------------------- /automations.yaml: -------------------------------------------------------------------------------- 1 | - id: washingmachine_switchedoff 2 | alias: Washing Machine - Change State Switched Off 3 | trigger: 4 | - platform: state 5 | entity_id: switch.lt_lava_roupa 6 | to: 'off' 7 | action: 8 | - service: input_select.select_option 9 | data: 10 | entity_id: input_select.state_washingmachine 11 | option: Switched Off 12 | - id: washingmachine_powereddown 13 | alias: Washing Machine - Change State Powered Down 14 | trigger: 15 | - platform: state 16 | entity_id: switch.lt_lava_roupa 17 | to: 'on' 18 | - platform: numeric_state 19 | entity_id: sensor.washingmachine_powerdraw 20 | below: 1 21 | for: 00:01:00 22 | condition: 23 | - condition: state 24 | entity_id: switch.lt_lava_roupa 25 | state: 'on' 26 | action: 27 | - service: input_select.select_option 28 | data: 29 | entity_id: input_select.state_washingmachine 30 | option: Powered Down 31 | - id: washingmachine_idle 32 | alias: Washing Machine - Change State Idle 33 | trigger: 34 | - platform: numeric_state 35 | entity_id: sensor.washingmachine_powerdraw 36 | above: 1 37 | below: 4 38 | for: 00:01:00 39 | condition: 40 | - condition: state 41 | entity_id: switch.lt_lava_roupa 42 | state: 'on' 43 | - condition: or 44 | conditions: 45 | - condition: state 46 | entity_id: input_select.state_washingmachine 47 | state: Powered Down 48 | - condition: state 49 | entity_id: input_select.state_washingmachine 50 | state: Rinse / Spin 51 | action: 52 | - service: input_select.select_option 53 | data: 54 | entity_id: input_select.state_washingmachine 55 | option: Idle 56 | - id: washingmachine_rinsespin 57 | alias: Washing Machine - Change State Rinse Spin 58 | trigger: 59 | - platform: numeric_state 60 | entity_id: sensor.washingmachine_powerdraw 61 | above: 10 62 | below: 550 63 | for: 00:01:00 64 | condition: 65 | - condition: state 66 | entity_id: switch.lt_lava_roupa 67 | state: 'on' 68 | - condition: or 69 | conditions: 70 | - condition: state 71 | entity_id: input_select.state_washingmachine 72 | state: Powered Down 73 | - condition: state 74 | entity_id: input_select.state_washingmachine 75 | state: Idle 76 | - condition: state 77 | entity_id: input_select.state_washingmachine 78 | state: Wash 79 | action: 80 | - service: input_select.select_option 81 | data: 82 | entity_id: input_select.state_washingmachine 83 | option: Rinse / Spin 84 | - id: washingmachine_wash 85 | alias: Washing Machine - Change State Wash 86 | trigger: 87 | - platform: numeric_state 88 | entity_id: sensor.washingmachine_powerdraw 89 | above: 1000 90 | for: 00:01:00 91 | condition: 92 | - condition: state 93 | entity_id: switch.lt_lava_roupa 94 | state: 'on' 95 | - condition: or 96 | conditions: 97 | - condition: state 98 | entity_id: input_select.state_washingmachine 99 | state: Powered Down 100 | - condition: state 101 | entity_id: input_select.state_washingmachine 102 | state: Idle 103 | - condition: state 104 | entity_id: input_select.state_washingmachine 105 | state: Rinse / Spin 106 | action: 107 | - service: input_select.select_option 108 | data: 109 | entity_id: input_select.state_washingmachine 110 | option: Wash -------------------------------------------------------------------------------- /button.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hostand/smartWashingMachine/23e3b2b0cfff61217ef4dec85c1e2c2b34f3d001/button.gif -------------------------------------------------------------------------------- /electric.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hostand/smartWashingMachine/23e3b2b0cfff61217ef4dec85c1e2c2b34f3d001/electric.jpg -------------------------------------------------------------------------------- /entity.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hostand/smartWashingMachine/23e3b2b0cfff61217ef4dec85c1e2c2b34f3d001/entity.JPG -------------------------------------------------------------------------------- /powerplug.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hostand/smartWashingMachine/23e3b2b0cfff61217ef4dec85c1e2c2b34f3d001/powerplug.jpg -------------------------------------------------------------------------------- /wm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hostand/smartWashingMachine/23e3b2b0cfff61217ef4dec85c1e2c2b34f3d001/wm.png --------------------------------------------------------------------------------