Hilarious yet 100% reliable and precise bed (slats) occupancy sensor

Like many of HA users, I too wanted a bed occupancy sensor. I was unable to cobble together the load bearing sensor thing with ESP32 and various other solutions. What I came up is ridiculously simple yet very effective. You need

  • Aqara Vibration Sensor (bear with me! It’s not what you think! Vibration is not used at all)
  • a ruler, a long stick, whatever
  • duct tape

You need a bed with slats for this, but maybe it can be modified for other types of beds.

The principle is pretty simple - you stick the Aqara vibration sensor onto the end of the plank/stick/ruler, and you just insert this under the mattress on the other end of the ruler.

When you lie down on the bed, it will bend down, causing the tilt of the sensor to change. You just have to tune the zero point (22° in my case) and threshold (anything over 30 is probably me and not my cat). The sensor is supported in Zigbee2MQTT in such a way it automatically creates separate tilt_X/Y/Z sensors so you don’t have to worry about that. Then it’s just a matter of creating a template sensor such as this:

binary_sensor:
  - platform: template
    sensors:
      bed_occupied:
        value_template: "{{ states('sensor.vibration_sensor_angle_y')|float > 30 }}"
        friendly_name: 'Bed is occupied'

And there you go, a precise and reliable Zigbee bed occupancy sensor created in less than 10 minutes including software. When running with Zigbee2MQTT, the reaction time is almost instant, 2-3 seconds in my case. Finally some use for the otherwise pretty useless Aqara Vibration Sensor :slight_smile:

17 Likes

“It’s not stupid if it works”.

7 Likes

I like the simplicity of this idea. Yet so effective!
Nice use case for that sensor, too.

1 Like

Still working as expected?
My bed sensor has probably been broken by the kids jumping in our bed.

And since this method is below the bed it seems to be kids safe.

Do you have to recalibrate it often? Do you get a new value when you take it off and put it back in? I mean does it “set” differently enough to need a recalibration?

That’s what the threshold (in this case > 30) is for.
You will need to find your own personal point once and then you are good because the ruler is fixed mounted.

1 Like

I understand that, but how often does it need to be calibrated.
Is there a drift noticed in the value?

Yes, it does work still. No need to recalibrate yet.

1 Like

Probably the battery change will be the first moment for removing and reattaching it.

Unfortunately my integration only offers the 3 axes as attribute. Therefore I need to create a template sensor for the axes separately. Anyone an idea how to achieve that?

Zigbee2MQTT creates three separate sensors - X, Y, Z. You can probably make a template sensor to extract just one value from the combined sensor but you’ll have to ask somebody else as I suck at templates.

I’m using the orientation attributes to monitor whether someone is tampering with my open bedroom window. If you like, play around with the parameters.


        {%- set base = state_attr('binary_sensor.vibrationssensor', 'orientation') -%}
        {%- set x = base[0] |int(0) -%}
        {%- set y = base[1] |int(0) -%}
        {%- set z = base[2] |int(0) -%}
        {{ x }}
        {{ y }}
        {{ z }}

      #### Examples:
        {{ z not in [87, 88, 89, 90] }}
        {{ z > 88 }}

2 Likes

Pushing this a bit further:

How to use that vibration sensor (which is a sensor.bed) as a device_tracker.bed ?

Aiming at removing my shitty GPS based device tracker and instead use the WiFi based plus vibration sensor ones (vibration sensor during night when smartphone is in flight mode).

With ios, wifi tracking is super unreliable. GPS works great, probably like 99% reliable. Is it different on Android or whatever OS you are using?

With all my iOS devices, WiFi tracking is super reliable, using the router integration which has a 180 seconds delay for „has left the WiFi“.

GPS mostly not working (discovering especially entering home zone way too late or not at all, probably 6 to 7 out of 10 times it is not working which is very frustrating).

And some users in my home can’t use GPS (which by the way drains the battery reaaaaaally fast as HA app needs constant background sync), so WiFi plus „overnight presence detection“ sounds like a really interesting option.

Anyone?

Only device tracker entities can be mapped to a person, right? So how to achieve that…?!?

Finally found a way (not tested by myself but according to others‘ experience working quite well) to create a device_tracker entity to assign the bed sensor to a person:

1 Like

that’s amazingly creative!! :+1:t2::+1:t2::+1:t2:
kudos!
and thanks to @Didgeridrew for pointing me to this post!

Just tried. It doesn’t do anything and I used a longer ruler to ‘exaggerate’ the movement. Not sure if my mattress is too new :(. I tried changing the sensitivity of the sensor to “high” though it didn’t do anything. None of the many outputs of the sensor device change at all when I lie down. :sob:

@ncd I just implemented this in the past week. and I was in the same boat to begin with. I ended up putting the very end of the ruler between the wooden lath and the mattress (Can’t remember exactly how much of the ruler maybe 10 or 15 mm.) giving the ruler a more dramatic angle towards the floor. I also used a strip of double sided tape at the edge to cause friction so it wouldn’t slide out, when getting in and out of bed, with the mattress moving. This gave me a difference of approx 9 degrees on the z axis. and has been working perfect so far. Maybe that might work for you?

thanks to @Stooovie for the idea, the pressure sensor mats were so unreliable.
I bought one on a whim thinking it would be the most gimmicky bit of tech I introduced to Home assistant, but ended up creating a bunch of automations around it, and adding the sensors to conditions of existing automations. So I’m hoping this solution continues to be a solid replacement.

Would you be comfortable sharing a pic? What is the length of your ruler? I had the same thoughts as you that the longer the ruler , the greater the force (bigger lever :grinning:) so the movement would be more dramatic. I have a 12 inch ruler and the sensor is attached at the very end and I only slide in the tip of the other side but it just doesn’t budge. I don’t have a super fancy mattress but it is quite good and I have a feeling it’s just dampening the entire effect. I’m also only 5’7"(1.71m) so that probably isn’t helping either. Otherwise the bed frame has slats and looks very similar to the OP’s post.
I’m thinking of using the Awara FP2 I just got and carve out a space in the area where the bed is and any time it detects someone there it will assume the person is " in bed". I haven’t had a chance to play with it yet just got it…

@ncd I think I was a bit over confident with the post above the angle kept changing, most likely due to the ruler being so close to the edge, I tired it again with less of an angle towards the floor and instead turning the ruler to the side. It’s giving me a consistent difference in degrees now.


Hope that helps but as you said maybe it’s not suitable for your mattress type.

2 Likes