Laundry Sensors with NodeMCU and Home Assistant

Have you thought about doing it in EspHome? The I2C bus is simple to set up, but I haven’t used it with one of these MPU sensors, only with a pressure sensor. It doesn’t seem like it would be too difficult, the data for individual axis’ would be available straight to HA and you could automate from there.
I just bought a couple on Aliexpress, so I’ll know in about 3-4 weeks…

Drew - absolutely keep me posted. I’m using ESPHome and for what it’s worth it looks easy, hard to tell because I haven’t been able to get a response out of the 6050’s. I’m only using one for now. I did read that adding 3v to the AD0 will give a secondary address for the i2c stuff so I think one esp will work for both. If you’d shoot me a message on here and let me know when you’re heading down that path I’d appreciate it. As I’m completely new to ESPHome. It seems easy but took me a while to figure out how to add the YAML entries, I’m still uncertain if I’ve selected everything that I should.

Great idea. I might try that first. I like the idea of having the sensor data available in HA for some reason. :stuck_out_tongue:

No worries, they shouldn’t be too far off now…:crossed_fingers:

Okay, I’ve got my NodeMCU and I’m playing around with ESPHome. I was able to get an ESPHome configuration file written up so that when I program the thing through USB, I can see the MQTT messages come through from all sensors (washer and dryer x/y/z/door). I’m actually floored that I was able to get this far, I’ve spent the majority of the day on it today.

EDIT:

However, when I unplug the device from the USB port on the raspberry pi after programming it and power it externally (either through USB on my computer or via a 12V wall wart) it never comes up. I don’t get any MQTT messages on my mosquitto instance and ESPHome only ever shows the device I created as ‘Offline’. I can ping the IP and it’s alive but I can’t figure out how to tell it to ‘go start working’.

How can I make the thing come up automatically and start working when the power goes out?? I’m so close!!

I was able to solve this by not using mqtt and instead using the Native Home Assistant API. It works very well but I had to remove all the stale MQTT data that I had created. Now I’m trying to get an accurate representation of the MPU6050 temperature sensor but I’m finding that their response is non-linear! Check this out:
image
This was generated from me experimenting by putting the prototype circuit inside my oven, then fridge, then the oven again. In my house at ~70F the sensors read somewhere in the vicinity of 219C. When I stuck the boards in the fridge, the temperature reading from the MPU6050 falls to around 200C. When I put it in the oven it raises up to around 229C, then immediately jumps to 36C as the temperature (in reality) rises above ~94F.

I’ve found that the values from the accel and gyros need to be calibrated as well since they’re giving me weird results (when I’m not actually moving the boards):

[22:28:02][D][sensor.mpu6050:134]: Got accel={x=0.610 m/s², y=38.914 m/s², z=5.420 m/s²}, gyro={x=3992.643 °/s, y=3995.265 °/s, z=0.366 °/s}, temp=46.601°C
[22:28:11][D][sensor.mpu6050:134]: Got accel={x=38.857 m/s², y=39.166 m/s², z=9.519 m/s²}, gyro={x=3993.375 °/s, y=1.707 °/s, z=3994.106 °/s}, temp=49.754°C
[22:28:12][D][sensor.mpu6050:134]: Got accel={x=0.572 m/s², y=38.869 m/s², z=5.305 m/s²}, gyro={x=3992.399 °/s, y=3995.326 °/s, z=0.793 °/s}, temp=46.742°C
[22:28:21][D][sensor.mpu6050:134]: Got accel={x=38.891 m/s², y=0.017 m/s², z=9.705 m/s²}, gyro={x=3993.009 °/s, y=1.707 °/s, z=3994.350 °/s}, temp=49.942°C
[22:28:22][D][sensor.mpu6050:134]: Got accel={x=0.560 m/s², y=38.883 m/s², z=5.372 m/s²}, gyro={x=3992.521 °/s, y=3995.387 °/s, z=0.793 °/s}, temp=46.883°C
[22:28:31][D][sensor.mpu6050:134]: Got accel={x=38.874 m/s², y=39.197 m/s², z=9.712 m/s²}, gyro={x=3993.192 °/s, y=1.463 °/s, z=3994.228 °/s}, temp=50.036°C
[22:28:32][D][sensor.mpu6050:134]: Got accel={x=0.608 m/s², y=38.833 m/s², z=5.343 m/s²}, gyro={x=3992.338 °/s, y=3995.265 °/s, z=0.610 °/s}, temp=46.883°C
[22:28:41][D][sensor.mpu6050:134]: Got accel={x=38.819 m/s², y=39.137 m/s², z=9.600 m/s²}, gyro={x=3993.314 °/s, y=1.646 °/s, z=3994.228 °/s}, temp=50.271°C
[22:28:42][D][sensor.mpu6050:134]: Got accel={x=0.627 m/s², y=38.831 m/s², z=5.439 m/s²}, gyro={x=3992.460 °/s, y=3995.326 °/s, z=0.671 °/s}, temp=47.071°C
[22:28:51][D][sensor.mpu6050:134]: Got accel={x=38.924 m/s², y=39.142 m/s², z=9.636 m/s²}, gyro={x=3993.253 °/s, y=1.463 °/s, z=3994.228 °/s}, temp=50.412°C
[22:28:52][D][sensor.mpu6050:134]: Got accel={x=0.601 m/s², y=38.862 m/s², z=5.386 m/s²}, gyro={x=3992.460 °/s, y=3995.265 °/s, z=0.671 °/s}, temp=47.212°C
[22:29:01][D][sensor.mpu6050:134]: Got accel={x=38.862 m/s², y=39.156 m/s², z=9.600 m/s²}, gyro={x=3993.253 °/s, y=1.341 °/s, z=3994.228 °/s}, temp=50.506°C
[22:29:02][D][sensor.mpu6050:134]: Got accel={x=0.656 m/s², y=38.850 m/s², z=5.398 m/s²}, gyro={x=3992.338 °/s, y=3995.448 °/s, z=0.671 °/s}, temp=47.354°C
[22:29:11][D][sensor.mpu6050:134]: Got accel={x=38.874 m/s², y=39.173 m/s², z=9.574 m/s²}, gyro={x=3993.192 °/s, y=1.585 °/s, z=3994.106 °/s}, temp=50.648°C
[22:29:12][D][sensor.mpu6050:134]: Got accel={x=0.608 m/s², y=38.857 m/s², z=5.441 m/s²}, gyro={x=3992.521 °/s, y=3995.326 °/s, z=0.366 °/s}, temp=47.354°C
[22:29:21][D][sensor.mpu6050:134]: Got accel={x=38.862 m/s², y=0.043 m/s², z=9.610 m/s²}, gyro={x=3993.314 °/s, y=1.585 °/s, z=3994.228 °/s}, temp=50.742°C
[22:29:22][D][sensor.mpu6050:134]: Got accel={x=0.560 m/s², y=38.876 m/s², z=5.381 m/s²}, gyro={x=3992.399 °/s, y=3995.448 °/s, z=0.671 °/s}, temp=47.636°C

EDIT2:

you can see from all this data that the accel and gyro values are all over the map. I had to include (after the last update) filters in ESPHome for offset and multiplier. That brings the values closer to what I’d want but I’m still seeing a few of the values “wig out”. Like they go from min to max without me touching the device. I’m not sure if I need to debounce them or something… more debug to do here.

This was a great project. I have it working now and it works well. The mpu6050 is sensitive enough to register the motion of the washer and dryer. Here’s an example of it from a capture today, my wife did some laundry in the washer from about 2pm to 2:40pm:

For reference and anyone who’s trying to do this with ESPHome here are the important parts of my implementation.

ESPHome yaml file:

esphome:
  name: laundry
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "MySSID"
  password: "MyPASSWORD"
  domain: ".mydomain"

logger:
  # level: WARN

api:
  password: 'apiPASSWORD'

ota:
  password: 'otaPASSWORD'

i2c:
  sda: 4
  scl: 5
  scan: True

sensor:
  - platform: mpu6050
    # update_interval: 10s
    address: 0x68
    accel_x:
      name: "Dryer Accel X"
      filters:
        - offset: -0.35
    accel_y:
      name: "Dryer Accel Y"
      filters:
        - offset: -39.17
    accel_z:
      name: "Dryer Accel Z"
      filters:
        - offset: -11.32
    gyro_x:
      name: "Dryer Gyro X"
      filters:
        - offset: -3990.15
        - multiply: 0.0025
    gyro_y:
      name: "Dryer Gyro Y"
      filters:
        - offset: -3995.86
        - multiply: 0.0025
    gyro_z:
      name: "Dryer Gyro Z"
      filters:
        - offset: -3994.43
        - multiply: 0.0025
    temperature:
      name: "Dryer Temperature"
      filters:
        - calibrate_linear:
          - 37 -> 34.7
          - 53 -> 53
          - 200 -> 4.3
          - 219 -> 21.1
          - 229 -> 33.4
  - platform: mpu6050
    # update_interval: 10s
    address: 0x69
    accel_x:
      name: "Washer Accel X"
      filters:
        - offset: -0.85
    accel_y:
      name: "Washer Accel Y"
      filters:
        - offset: -38.50
    accel_z:
      name: "Washer Accel Z"
      filters:
        - offset: -28.05
    gyro_x:
      name: "Washer Gyro X"
      filters:
        - offset: -3994.38
        - multiply: 0.0025
    gyro_y:
      name: "Washer Gyro Y"
      filters:
        - offset: -3993.51
        - multiply: 0.0025
    gyro_z:
      name: "Washer Gyro Z"
      filters:
        - offset: -3993.53
        - multiply: 0.0025
    temperature:
      name: "Washer Temperature"
      filters:
        - calibrate_linear:
          - 37 -> 34.7
          - 53 -> 53
          - 200 -> 4.3
          - 219 -> 21.1
          - 229 -> 33.4
      
binary_sensor:
  - platform: gpio
    device_class: door
    name: "Dryer Door"
    pin:
      number: D7
      inverted: True
      mode: INPUT_PULLUP
  - platform: gpio
    device_class: door
    name: "Washer Door"
    pin:
      number: D8
      inverted: True
      mode: INPUT_PULLUP

If you review the yaml, you’ll notice that I put a calibrate_linear for the temp sensors. I found that they were very disjointed but this makes them respond in a way that is more accurate to home assistant reporting. Also, I calculated offsets and multipliers for all the accel and gyro values to make them less awkward to determine (I can surround 0, see in the binary_sensor template below). So long as I don’t touch the physical devices, we’re good for a long time. :slight_smile:

I originally put those update_intervals at 10 seconds so I could see more data quicker but found that after a half day of that much recorded data the charts were slow to load. I saw that ESPHome has some pretty advanced filtering potentials that I’d like to play with, I bet I can make the usage detection pretty spot-on and quick by playing with those for a while. Currently the raw values work well and when the washer or dryer finally stops shaking for 5 minutes, the sonos speakers say:
“The washer is done washing” or “The dryer is done drying”

To do this, I made a binary_sensor template for the values:

laundry_sensors.yaml (binary_sensors directory)

- platform: template
  sensors:
    washer_washing:
      device_class: vibration
      friendly_name: Washer Washing
      value_template: "{{ states('sensor.washer_accel_x') | float > 0.5 or states('sensor.washer_accel_x') | float < -0.5 or states('sensor.washer_accel_y') | float > 0.5 or states('sensor.washer_accel_y') | float < -0.5 or states('sensor.washer_accel_z') | float > 0.5 or states('sensor.washer_accel_z') | float < -0.5 }}"
    dryer_drying:
      device_class: vibration
      friendly_name: Dryer Drying
      value_template: "{{ states('sensor.dryer_accel_x') | float < -0.5 or states('sensor.dryer_accel_x') | float > 0.5 or states('sensor.dryer_accel_z') | float > 0.5 or states('sensor.dryer_accel_z') | float < -0.5 }}"

You can see, I ignored the accel_y values on the dryer. I’ve purchased 5 of these mpu6050s and only one of them so far has had smooth X/Y/Z reporting. The one I chose for the dryer has 2/3 axes that work. Anyway, you really only need one to detect the movement.

I then created a holder for the state values:

configuration.yaml

input_select:
  washer_state:
    name: Washer
    options:
      - Idle
      - Loading
      - Washing
    initial: Idle
    icon: mdi:washing-machine
  dryer_state:
    name: Dryer
    options:
      - Idle
      - Loading
      - Drying
    initial: Idle
    icon: mdi:tumble-dryer

After that all I needed to do was enable the automation, it’s three parts for the three states (there’s probably a better way to do this, if you have one, please share):

laundry.yaml (automation directory)

# Washer no vibration for five minutes, washer is done!
- id: set_washer_to_idle
  alias: Set Washer to Idle
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.washer_washing
    to: 'off'
    for: '00:05:00'
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.washer_state
      option: Idle

# Washer vibration and door is open means washing
- id: set_washer_to_washing
  alias: Set Washer to Washing
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.washer_washing
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.washer_door
        state: 'off'
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.washer_state
      option: Washing

# Washer vibration and door is open means loading
- id: set_washer_to_loading
  alias: Set Washer to Loading
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.washer_washing
    to: 'on'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.washer_door
        state: 'on'
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.washer_state
      option: Loading

and finally, the sonos piece:

sonos_alerts.yaml (automation directory)

- id: sonos_alert_on_laundry_triggers
  alias: Sonos Alert on Laundry Triggers
  initial_state: true
  trigger:
    - platform: state
      entity_id: input_select.washer_state
      from: 'Washing'
      to: 'Idle'
    - platform: state
      entity_id: input_select.dryer_state
      from: 'Drying'
      to: 'Idle'
  action:
    - service: script.sonos_say
      data_template:
        sonos_primary: media_player.office_sonos
        volume: 0.5
        message: >
          The {{ trigger.to_state.attributes.friendly_name }} is done {{ trigger.from_state.state }}.
        delay: '00:00:05'
7 Likes

I want this kind of sensors, but I’m more inclined on trying out with an energy consumption plug.
I believe it might be easier to read and implement.

Sure, if you have a super old appliance, you will have a hard time finding a plug that will support the amperage. So this solution is still very much valid.

EDIT: Added conclusion.

1 Like

I enjoyed reading about your project.

I recently built a similar project but instead of using accelerometers I’m using some very inexpensive SW-420 vibration sensors.

Your voice feedback really takes it to the next level!

1 Like

I’d like to mention that with the new ESPHome release (1.13.6) there’s very little need to calibrate the sensors. Apparently, there was a data-type mismatch (https://github.com/esphome/esphome/pull/532) which was causing the poor correlation from X/Y/Z and Temp sensors and now the data looks pretty darn good:

I set my input_selects using all accel and gyro values and it’s is really representative of the actual washer/dryer state.

1 Like

@SpikeyGG can you share your config i tried to do the same with esphome but the sensors work for a minute or two and stop updating and i get error that i2c: is disconnected or did not communicate with the sensor
thank you

Sure thing, here’s the latest one I’m using I corrected it for the small offset seen in the washer plots above (I’m anal):

esphome:
  name: laundry
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "MySSID"
  password: "MyPASSWORD"
  domain: ".mydomain"

logger:
  level: DEBUG

api:
  password: 'apiPASSWORD'

ota:
  password: 'otaPASSWORD'

i2c:
  sda: 4
  scl: 5
  scan: True

sensor:
  - platform: mpu6050
    update_interval: 15s
    address: 0x68
    accel_x:
      name: "Dryer Accel X"
      filters:
        - offset: -0.55
        - or:
          - throttle: 60s
          - delta: 1.0
    accel_y:
      name: "Dryer Accel Y"
      filters:
        - offset: -9.62
        - or:
          - throttle: 60s
          - delta: 1.0
    accel_z:
      name: "Dryer Accel Z"
      filters:
        - offset: 0.38
        - or:
          - throttle: 60s
          - delta: 1.0
    gyro_x:
      name: "Dryer Gyro X"
      filters:
        - offset: 1.77
        - or:
          - throttle: 60s
          - delta: 1.0
    gyro_y:
      name: "Dryer Gyro Y"
      filters:
        - offset: -1.83
        - or:
          - throttle: 60s
          - delta: 1.0
    gyro_z:
      name: "Dryer Gyro Z"
      filters:
        - offset: 2.10
        - or:
          - throttle: 60s
          - delta: 1.0
    temperature:
      name: "Dryer Temperature"
      filters:
        - throttle: 60s
  - platform: mpu6050
    update_interval: 15s
    address: 0x69
    accel_x:
      name: "Washer Accel X"
      filters:
        - offset: -0.96
        - or:
          - throttle: 60s
          - delta: 1.0
    accel_y:
      name: "Washer Accel Y"
      filters:
        - offset: -1.04
        - or:
          - throttle: 60s
          - delta: 1.0
    accel_z:
      name: "Washer Accel Z"
      filters:
        - offset: -8.81
        - or:
          - throttle: 60s
          - delta: 1.0
    gyro_x:
      name: "Washer Gyro X"
      filters:
        - offset: 2.21
        - or:
          - throttle: 60s
          - delta: 1.0
    gyro_y:
      name: "Washer Gyro Y"
      filters:
        - offset: 2.75
        - or:
          - throttle: 60s
          - delta: 1.0
    gyro_z:
      name: "Washer Gyro Z"
      filters:
        - offset: 2.37
        - or:
          - throttle: 60s
          - delta: 1.0
    temperature:
      name: "Washer Temperature"
      filters:
        - throttle: 60s
      
binary_sensor:
  - platform: gpio
    device_class: door
    name: "Dryer Door"
    pin:
      number: D7
      inverted: True
      mode: INPUT_PULLUP
  - platform: gpio
    device_class: door
    name: "Washer Door"
    pin:
      number: D8
      inverted: True
      mode: INPUT_PULLUP

One thing I might do differently if I was doing this from scratch is not use the D8 pin. I’ve found that my device can be a bit finicky to power up sometimes and I think it’s because of the use of D8. According to “TheHookUp”: https://www.youtube.com/watch?v=7h2bE2vNoaY if you use D8 and it’s pulled high during boot, the ESP8266 will fail to boot. I think I’m experiencing this with the washer door. D6 or D5 would be better choices for that according to the video. Anyway, beside that, the device works FANTASTICALLY.

1 Like

I’ve built a sensor myself and stuck it to my washer and dryer, which are stacked on top of each other. I don’t care to differentiate them, just know that one is running. However, my values seem to drift over time. So after calibrating, the offset would have to be changed. I assumed that this could be related to temperature, but in that case I would also assume that it would return to normal after cooling off. Seen anything similar? Here’s a simple graph:

All sensors were aligned nicely around zero a couple hours prior.

Depending on how sensitive your accelerometer is, the vibrations from a washing/drying can cause the position of the appliance to change enough to change the readings. Additionally, accelerometers are not perfect.

Instead of focusing on calibration to exactly ZERO and getting it to stay there, I’d focus on getting close to zero and using BIGGER changes in X,Y,Z to suggest movement/vibration. The only time you’d need to know the actual X,Y,Z is if you were using this to detect a door opening or something.

Base your sensor on the idea that the X,Y,Z have changed since your last reading, as opposed to what they have changed to.

Yes, makes sense. So maybe it’s better to just look at the delta between current and previous reading, and use that as a value instead? In that case, calibrating to zero is more or less not needed too.

1 Like

thank you for you help im sorry i did not replay before i was out of the state for work
i have the sensor working thanks again
2 questions do you place the sensor on top of the dryer or on the side ?
do you use a template sensor to process the data that comes out on the mpu6050 sensor to know if it is on or off ?
if you dont mind posting the sensor config thanks again
i dont know anything about templates any help is greatly appreciated

Hi Kem, I have posted all the required config files onto this thread: Laundry Sensors with NodeMCU and Home Assistant. I did use template sensors to set the state of the washer/dryer, it’s also in the list of config files, called laundry_sensors.yaml.

I put both sensors on the back of the washer and dryer toward the top so I could easily reach the doors between the two units for the reed switches. I used caulking to adhere a piece of fridge magnet I cut to the bottom of the PCB. It wasn’t nearly strong enough to hold the device to the washer/dryer so I used more caulk to glue four neodymium magnets to the corners of that. They stick pretty good now.

Here are some photos I just snapped of my setup.


1 Like

awesome thank you again

SpikeyGG seriously thank you you made this really easy :slight_smile: i copy and pasted your esphome code and just changed D8 to something, as well as adjusted the offsets and it works great. i ended up using the gyro as the accel sensors weren’t working too well.

i used your templates too for the sensors and they worked great as well.

i did up a simple automation in node-red for the actual laundry stuff and it works fantastic. it basically waits for washer to turn on…once on it waits for 1 minute. if laundry sensor stays “on” for that entire minute it sets input boolean “stage1” to on. once laundry turns off (end of first rinse cycle), it waits again and when back on it sets stage2. once that turns off (if stage1 and 2 are on) it sends the notification and resets the booleans :smiley:

I can finally get rid of the last piece of my old smartthings setup!

1 Like

Thank you for sharing your project! Would you please answer the following questions?
Why is that you need to connect 3V from the MCU to the ADO of the second MPU-6050? Could you connect the 5V instead of the 3V?

Thank you in advance

If the mpu-6050 supports 5v then sure, you should be able to