Detecting bed presence using thin film pressure sensors with ESPHome

No comments
Disclosure: This post contains affiliate links. If you click through and make a purchase, I’ll earn a commission, at no additional cost to you. Read my full disclosure here.

Creating a good-night-automation was one of the first things I did using Home Assistant. Although, calling it an automation isn’t quite correct as I did have to trigger it manually using the sleep tracker on my watch. Nevertheless, it is a very useful thing to have set up. Mine made sure that the cat wouldn’t trigger any of the motion sensors and would keep the bathroom lights from blinding me during nighttime visits. It would also play some white-noise on my Google Nest Mini.

A bed with a fan
You could automatically turn on a fan using this ESPHome project…
Light coming in through a window
…or use some motors to close the curtains.

The creator of today’s featured ESPHome project took things one step further and created a DIY bed presence detector using a couple of thin film pressure sensors hooked up to an ESP32. The detector even differentiates between the two halves of the bed. This sensor isn’t as uncomplicated as others that have been featured, as it makes use of the ADC sensor. But threat not, because the creator has thoroughly documented how things work.

What you need for bed presence detection

As with the PWM LED strips, this project uses an ESP32 with good reason: they have several Analog To Digital (ADC) pins. As the pressure sensor used in this ESPHome project is analogue each one needs an ADC pin to work. As soon as you want to detect more than a single person in one bed you will need multiple pressure sensors.

ESP32 Board

  • The brains of this project. A cheap microcontroller with support for Wi-Fi and Bluetooth.
  • Seamless integration with Home Assistant thanks to ESPHome.
  • Cheaper models can be found on AliExpress, but shipping will take longer.

The easiest way of powering the ESP32 is by using the onboard USB Micro-B connector and an unused phone charger. None of the components uses enough power to warrant anything else. However, if you were to use the same ESP32 for under-bed lighting you would need a beefier power supply for the LED strips.

What makes this project interesting is the use of thin film pressure sensors. These measure the pressure between two surfaces. In this project, those surfaces are the mattress and the bed. A resistor is needed between the ground pin and the thin film pressure sensor. The creator used a 5k Ohm resistor but I guess some testing would be needed as mattresses and people don’t all weigh the same.


While the project is very well documented, the wiring, unfortunately, isn’t shown. But I did find this guide, where you will find a diagram on how to wire things up. All you have to do is replace the ESP8266 with your ESP32. Everything else should be identical. Connecting the thin film pressure sensor is slightly different compared to digital sensors, so it is handy to know how to do it correctly.

How the bed presence detection works

Each thin film pressure sensor will only need a few lines of YAML to be configured. The creator has thankfully shared the relevant parts of their code for others to use. The ESPHome code itself determines whether the bed is occupied or not. With the use of on_value_range an input_boolean in Home Assistant is turned on whenever the pressure crosses a certain value. The creator uses Node-RED for their automations and has made the whole configuration used for the bed presence detection available.

YouTube video

Leave a comment

Share to...