I've been on a year-long quest to have reliable bed presence detection. Along the way, I think I've attempted all but one of the methods I've read about on the forums here, so I thought a write-up of my successes and failures might be useful to others looking to accomplish the same thing.
(The method I haven't yet attempted is placing an mmWave motion detector under / on the bottom of the bed pointing up, in hopes that it can see the people in the bed. I might test this at some point, but I worry about false positives from the cats sleeping on any bed they can get to.)
Scenario
I have three beds in the house I want to monitor -- the adults and our two kids.
I want to have detection for the kids to squelch the " is up" announcement when the kid is actually in bed and the adult who put them to bed is leaving the room. My son also has a bad habit of getting up and doing things in his room late into the night and then being tired and grumpy the next day, so I have a rule that sends my phone a notification when he's been out of bed for five minutes but not left his room.
For the adults, we have lighting that comes on if we get out of bed at night and should go off once we return to bed. (And mostly, it's because once I endeavor to solve something, I won't give up (darn it!) even if multiple attempts fail.) It would also be nice if some of the morning routines could be tied to getting out of bed, not when someone opened our door. (With small people around, those are distinct events.)
My initial criterion was that I didn't want anything on top of the mattress. Other criteria got added over time.
#1: Tuya Contact Sensors + Seat Mats
I got these cheap ZigBee contact sensors and these pressure pads. After melting a hole in the side of the contact sensor case, I soldered the pressure mat across the reed switch that the magnet trips.
This initially seemed to work, as squeezing the pressure mat would cause the contact sensor to close. However, I quickly found that the required activation pressure was a lot more than that in any one place on a bed. After some experimentation, I found that doubling the mat up on itself would reduce the required activation pressure, since the same force would be hitting more dots at once. However, then it became a tenuous game of how folded was sensitive enough, but not so sensitive it would be tripped by the weight of the mattress.
I eventually found positions that this would mostly work:
- For the adults' bed, on top of the foundation slat closest to our hips
- For my son's bed, between one of the slats holding the mattress and the bed frame, so it got pinched by the slat when he was laying in bed.
However, this solution had a number of drawbacks:
- It never successfully tripped for my daughter's tiny frame
- My son's bed slats can move, and the slat had to be in just the right spot to correctly trigger, so I was constantly readjusting his bed
- Detection was inconsistent for my wife, mostly depending on position.
- This approach appears to eat 2032 batteries every few months. Getting under mattresses to change batteries quickly became annoying.
#1.5: Tuya contact sensors + FSR Strips
I also got some of the SF15-600 force-sensitive resistor strips in hopes of detecting across a larger area. Unfortunately, I didn't realize how prone these were to damage from soldering and lost one pretty much immediately.
I cut one of the pressure sensor mats off the cord connected to the contact sensor and soldered female connectors onto the end, then plugged in the other strip. Putting one of these across the slat on my son's bed and connected to the contact sensor was generally pretty good, and no longer subject to the shifting. It also killed the contact sensor battery about a week later; that may have been conincidence, but made me get more interested in hardwired options.
#2: Strain gauges and ESP8266
After reading this article, I decided to give strain gauges a try. Tared for the weight of the bed, that should be able to differentiate me and my wife, and perhaps even separately indicate the cats, though that's not really a goal.
This solution was also appealing because of the ability to hardwire the power going to the ESP; no more batteries to change inside mattresses!
I got a kit from Amazon that included eight strain gauges and two HX711 modules to read their output back to an ESP8266. This was my first foray into the world of Arduino, and I followed the sample project to report back over MQTT. (I already have an MQTT server from Teslamate, so adding a new publishing source wasn't a big deal.)
Unfortunately, this required a lot of wire-running to get the sensors under all four legs appropriately cross-connected, and even more so to conceal the wires from my cat who likes to chew on wires. Something in that mess of wiring was preventing it from getting a good read, and I never did figure out what. It may be the HX711 board itself; I need to go back and test it. The strain gauge setup is still sitting on my workbench.
#3: DIY capacitors and ESP32 touch
For the adult bed, I experimented with this approach using homemade capacitors and the ESP Touch platform. Since the ESP8266 doesn't have the touch capability, I had to acquire an ESP32 for this one. This article used the ESPHome platform, which can be connected to Hubitat using the ESPHome drivers available on HPM).
They were actually really impressive in testing, with the touch value numbers dropping very low under pressure. The drawback for me was getting a solid connection to the aluminum foil and keeping it that way. Things kept coming loose despite continuing attempts to make a better attachment, and part of the point is not needing to get back under the mattress on a regular basis.
Maybe figuring out how to solder onto aluminum foil would have helped here?
Never attempted this on the kids' beds.
#4: ESP8266 + FSR Strips
I tried connecting the FSR strip on my son's bed slat to an ESP8266 (originally bought for the strain gauge), again using ESPHome. My initial attempt tried using the internal pullup resistor as a binary input, which worked on my son's bed but failed completely on my daughter's bed.
Realizing the difference would be very small for her, I added a voltage divider and read the FSR using the ADC. That worked amazingly for my son's bed. The difference for my daughter's bed is still quite small, but with a larger resistor, I think we're in business.
#4.1: ESP32 + FSR Strips
I expected to do the same thing for the adult bed but using the ESP32 because of its ability to read more than one ADC input at a time.
To my consternation, the ADC kept reading the max value on the ESP32. I initially thought it was my omission of attenuation: auto
, which increases the input range up to 3.3V and really ought to be the default. However, even after fixing that, they still produce no noticeable response between mattress and foundation -- apparently it's just that good at spreading out the pressure!
Eventually, I moved the FSRs between the foundation and the bed frame, where they're getting a very firm pinch. In that position, they give a clear difference between occupied and not. I do wonder whether a larger resistor would enable these to be under the mattress as well, but at this point I'm not planning to mess with what's working.
Conclusion
I've become a big fan of the ESPHome platform. Really simple to set up a sensor to your specifications, really simple to bring them into Hubitat. If someone is starting down this path, I'd say to start with a ESP dev board and an FSR.
That said, I think this is also a space ripe for someone to come in with a prepackaged produce. A sensitive pressure-sensing mat and a driver that can do some appropriate calibration in the settings would go a long way here. I would definitely rather have purchased something off the shelf.