Baby Changing Mat Occupancy Sensor and Heat Lamp Automation with ESPHome/ESP32 (dirt cheap and basic!)

Hi!

Wanted to share my very very cheap and dirty (no pun intended!) way to turn on the heat lamp above my baby’s changing table when we lay her down for a nappy change. The basic elements are as follows:

The key is the home made capacitive pressure pad sensor which is heavily based on the instructions here: https://blog.yavilevich.com/2017/10/40-cent-diy-pressure-sensor-based-on-a-capacitive-principle/. Basically if you follow the building instructions on that page, you’ll end up with a home made pad from just tin foil and office supplies that will change its capacitance based on pressure on the mat (check it with a multimeter to be sure). I’d recommend soldering the wires to the paperclips because they slide out easily. Then you can put it under the baby changing matt - like this (apologies for picture quality):


Connect one wire from the pad to the Ground pin of an ESP32 and the other to one of the ESP32’s capacitive sensing pins (GPIO 4, GPIO 0, GPIO 2, GPIO 15, GPIO 13, GPIO 12, GPIO 14, GPIO 27, GPIO 33, GPIO 32) - I used GPIO 4. From here you can load an ESPHome image onto the ESP 32, I used the following code (see the comments for parameters that I changed):

# Setup the ESP32 board
esphome:
  name: changing_matt_esp32
  platform: ESP32
  board: esp32doit-devkit-v1
  board_flash_mode: dio

# Setup the Wi-Fi connection
wifi:
  ssid: <Wi-Fi SSID>
  password: <Wi-Fi Password>

# Enable the Home Assistant API as the communications method
api:

# Enable logging
logger:

# Enable OTA updates
ota:

#Setup the touch platform
esp32_touch:
  # Set this to True when you first setup the sensor - then in the ESPHome log you'll see the actual measured value being constantly output. This lets you find what the threshold is for occupied/not occupied
  setup_mode: False
  # Set the low voltage as high as it will go and the high as low as it will go - the smaller range improves the sensitivity so the matt makes noticeable changes
  low_voltage_reference: 0.8V
  high_voltage_reference: 2.4V
  # Set the maximum voltage attenuation to help provide a better signal 
  voltage_attenuation: 1.5V

# Setup a sensor to monitor the changing matt pressure pad on GPIO 04
binary_sensor:
  - platform: esp32_touch
    name: "Changing Matt Occupied"
    pin: GPIO4
    # This threshold should be set individually, see the note on "setup_mode" above
    threshold: 250

When you first connect this you should set setup_mode to True to get messages in the logs about the value being measured. Once you’ve done this put the pad under the changing mat and load the ESPHome logs to check what the “unoccupied” value is. Then lay something roughly baby-weight on the mat and see what the value changes to. You can then edit the ESPHome YAML to put setup_mode back to False and set threshold to be between the “occupied” and “unoccupied” values.

With that done - you can add the ESPHome device in Integrations in Home Assistant and you’ll have a new binary sensor telling you if the changing matt is occupied or not! Bonus points for customising the entity with the baby-face-outline MDI icon :wink:

That’s really the hard part complete - all that remained was to add an automation that turned on the heat lamp using the Shelly Plug S. I’m using this HACS component to have all my Shelly devices in HA: https://github.com/StyraHem/ShellyForHASS so I already have a switch for the heat lamp in HA. Then just add the automation using automations or Node Red and you have an auto-heat lamp for the changing mat!

8 Likes

very cool!

I do see this scenario playing out tho:

husband to wife: “No, I promise that the wires that go from that electrical device to a sheet of aluminum foil under the baby won’t electrocute him even if he wet’s on it.”

wife to husband: (looking at him with a sneer of contemptuous disbelief) :face_with_raised_eyebrow: :rage:

husband: :cold_sweat: Ok, never mind…

:rofl:

Yep…you predicted almost the exact conversation we had!! :joy: :joy: :rofl: I should have added that part to the instructions :wink: Luckily the 3am convenience of not having the heat lamp turn on has dampened any criticism…for now!

1 Like

Just a note for anyone that does try and build it - the instructions for the foil pad (https://blog.yavilevich.com/2017/10/40-cent-diy-pressure-sensor-based-on-a-capacitive-principle/) connection talks about resistors etc. for sensing on Arduino, you can skip all of that thanks to the ESP32 having native capacitance measurement - just build the foil pad and then connect the wires directly to the two ESP32 pins.

Now that’s too funny!! :rofl: :rofl:

Hello, I was wondering. Is there a limit to how long the wires for the pressure mat can be?

I’m considering using this approach to put pressure mats underneath each step’s carpet on the stairs and thought this would be a good way to put multiple sensors on 1 device.

I’m really new to DiY electronics, so I don’t really know the ins and outs of how it works exactly. I have worked with esp8266s before, but mainly lighting projects.

I’m guessing there needs to be some form of signal boosting, if the mat is at the bottom of a 10 step staircase and the esp32 is at the top?

If there needs to be done something specific to make the signal stronger for longer distance between sensor and board, can you explain it to me like I’m 5? Or maybe link a resource where I can read up on signal boosting this kind of sensor?

Thanks in advance!

@infors Thank you very much for this. Tried the setup and it worked first time and so far it’s been super reliable. Hard to believe how cheap it is.

@AnthonMS Have you tried the stairs sensors out? I’m considering to do similar setup, did it work out for you? any problems you ran into?

I did try it out, and it did work for some days. But I had ran the wires along the wires for the LED lights under each step, and I think there were some signal problems because of that on some of the steps sensors.

I still really want this set up in my house, so I bought a bunch of actual pressure sensor strips and was planning to use them instead.