Bed occupancy DIY sensor

EDIT: I no longer recommed this method. I use this instead, FSR - the best bed sensor


I’ve been trying a few things for a bed occupancy sensor.

An MS5611 pressure sensor ‘sealed’ in a waterproof flexible phone case or in a silicone tube did not work. The air leaked out of both rather quickly.

I’m now using a cheap eBay strain gauge glued to one of my bed slats. Connected to the A0 input of a Wemos D1 mini runing ESPhome. It does not give a huge voltage swing (0.6V to 1.3V) but I think it will be workable.

I tried a very thin smear of 5 minute epoxy but that did not stick well to the sensor. Cyanoacrylate (super glue) seems to be working.

Close up of sensor glued to the slat:

The housing was a re-purposed plastic box I had lying around that fit perfectly.

Just before turning the slat over and putting the mattress back:

That grey ‘non-structural’ text is certainly true. I snapped one of the slats though a knot just by leaning on it. Got some replacements from the hardware store easy enough.

There is a fairly clear delineation between being in bed and not. This will improve once I can get windowed averaging working on the ESPhome module again, to reduce noise and spikes from me moving about. This dip is me lying on the bed:

It will be interesting to see what my usual tossing and turning looks like tomorrow morning.

If this doesn’t end up working I have some Velostat on order as a backup.

19 Likes

I doing the same with these https://www.amazon.com/Ideal-Security-Pressure-Pleasant-Triggered/dp/B00GUNX7WY/ref=mp_s_a_1_4?ie=UTF8&qid=1547561036&sr=8-4&pi=AC_SX236_SY340_QL65&keywords=Pressure+Mat&dpPl=1&dpID=511vjXnKhuL&ref=plSrch

Got 2 coming

I hope that’s a resistive mat and not a switch. Otherwise the weight of your mattress is going to trigger it permanently.

1 Like

Let u know the outcome

1 Like

If it doesn’t work out under the mattress, I’m currently using one of those pressure mats under a floor mat to trigger a light when the mat is stepped on. Works quite well!

@tom_l Look forward to hearing how well the strain gauge works. I’ve been wanting to do a bed occupancy sensor for a while.

I’m using the Xiaomi vibration sensor. When it detects a vibration and there is no movement in the house for 10 minutes HA is considering me in bed. It works really good.

2 Likes

I have been using 2 off the door mat sensors for a couple of months. As long as you have it positioned perfectly under the mattress it works perfectly. Too close to the sides and it’s triggered all the time.

First night’s data with ‘in bed’ indicated by the added green line:

Unfortunately it’s a bit noisy using the raw data from the ESP every 30 seconds. Though it does work surprisingly well as a sleep monitor and clearly shows periods of light and deep sleep:

However this is not what I want. So I need to average a number of readings in the ESP (it is very fast to update) and send a 30 or 60 second average to HA. I dont want to filter in HA because that would necessitate updates from the sensor far too often, loading up the MQTT server and Pi’s CPU. Mainly because I want a fast response time from this sensor (30-60 seconds max).

Unfortunately I’m having trouble getting the ESPhome moving window average to work. That’s today’s challenge.

2 Likes

Thanks for the heads up

When I do this kind of project I have found taking the last 10 readings removing the 2 outliers (highest and lowest) and then averaging is the best result.

That would be great but I can’t even get an average working:

Interresting, finally found something usefull for this vibration sensor. Do you mind sharing how your automation works? Do you continuously get vibration data from the sensor and use the no motion as a condition?

You can find the automations and the script here: https://gist.github.com/dnuc/9816782b796c07e5139e95d39306006a

2 Likes

When I did something similar with Arduino and temperature sensor my “averaging” function was to define an integer variable, read 50 or so values adding each to the variable, then just divide by 50 and report that reading. It’s not a true sliding windows, but good enough for this application.

Add a couple of seconds pause between each report to not blow up your mqtt. And be careful to not overrun your integer variable (declare it as a long if necessary).

I finally got windowed averaging working on the ESP. I had to drop monitoring the status and wifi of my sensor though. Hopefully this will will be rectified with an ESPhome update.

So now I have this, a perfect bed occupancy sensor for less than $15 AUD that is easy to install (no messing about with load cells under bed legs).

When I first tested the filtered sensor I was surprised to see a much bigger difference in signal for in and out of bed. However when I went to bed there was a ‘clunk’ as the slat dropped into its guide correctly and the sensor value difference dropped (see chart above). I worked out that lifting the slat that has the strain gauge fitted above the other slats by 5mm using a shim gave a much better signal as it is taking more weight. This is not noticeable through the innerspring mattress.

Only problem now is that I have no use for my neat DIY Velostat pressure sensor:

I’m not too fussed about this, especially as using it with the strain gauge amplifier would have necessitated a bit of rocket surgery. The sensor operates from about 2K Ohm nominal to 1.2K Ohm when pressed. Where as the strain gauge was 360 Ohm nominal. This means I would have had to replace three 0805 360R resistors with 2K Ohm versions in the module’s Wheatstone bridge. I am set up with a stereo microscope to do this but am glad I don’t have to. I would also have had to make two of these sensors (and use an ESP32 with more than one analogue input) and fit them to either side of the bed - vs only one strain gauge sensor on the slat.

So in summary. Success!

Now I just have to fit another one to the guest bed and work out the convoluted logic for turning everything off at night depending on if I have guests and/or if I am home or not.

5 Likes

Hi, cool stuff. I am very interested in occupancy and pressure sensors.

In 2017 I have designed a simple and not expensive pressure sensor based on a capacitive principle. It was made for Fochica, a device designed to alert parents that unintentionally leave their children in a car.

The article is at: https://blog.yavilevich.com/2017/10/40-cent-diy-pressure-sensor-based-on-a-capacitive-principle/ . LMK if you have feedback or improvements.

I have two HX711 with four Load Cell each, mounted between bed-frame. It works very well so far. Also you can see if you gained weight :slight_smile: (thus some downsides regarding WAF (Woman acceptance factor) - so I converted int a Binary Occupancy Sensor)

I can add some details if someone interested

Yes, please!

UPDATE:

The cheap ebay strain gauge sensor and D1 mini solution has been working perfectly all week.

2 Likes

Using the data from your sensor you could start to calculate time in deep sleep by counting the periods in bed with less fluctuations.

1 Like