yehor e02ced287b
All checks were successful
Build release image / build (push) Successful in 1m30s
Migrate more blog posts
2025-05-20 13:24:39 +03:00

2.7 KiB
Raw Blame History

slug title tags image
bed-presence-detection-with-aqara-window-and-door-sensor-and-a-cheap-car-part Bed presence detection with Aqara window and door sensor and a cheap car part
smart home
Home Assistant
home automation
DIY
Aqara
Xiaomi
/img/blog/2020/12/bed.jpeg

Bed presence detection could be very useful in home automation to control the lights and appliances you dont need at night, but want to be ready in the morning. And today we will build a bed presence sensor out of a very universal device for DIY IoT. It is an Aqara ZigBee window and door sensor. Why it is so universal? Lets take a closer look at its internals.

internals

See that little glass tube? Thats a reed switch. It operates under a magnetic field generated by the magnet inside the second part of the sensor. So, in general, it just closes the contact between two points of the electrical circuit. We can unsolder it and replace it with something else. A switch, for example. Or with a car seat pressure sensor, like this one:

Car seat sensor

It could be found on Amazon or our favorite Chinese store just for 5$. It has two wires that could be closed or opened according to pressure presence. So all we need is to solder this sensor to the Aqara sensors board instead of the reed switch.

image

Ive removed the button cup from the top of the sensor to leave a hole for wires. Just remember to pair your sensor with whatever you are using as a ZigBee hub before doing this.

image

All we need to do now is to put our new sensor under the mattress. I have a bed with wood slats that is narrower than the pressure sensor so I decided to put the sensor on a cardboard sheet

image

I made two sensors to separately detect the bed presence of me and my wife. You need to experiment with the sensor position to get the most accurate results. Also, you need to remember that the “open” state of the sensor means “the bed is not occupied” and “closed” means that “the bed is occupied”.

Bed sensors in Home Assistant UI

The third sensor on the screenshot is a Home Assistant template binary sensor that represents unconditional bed occupation. In other words, it is on when someone is in bed, and off otherwise:

binary_sensor:
  - platform: template
    sensors:
      bed_occupancy:
        friendly_name: "Bed occupancy"
        device_class: occupancy
        value_template: "{{is_state('binary_sensor.bed_occupancy_door_side', 'off') or is_state('binary_sensor.bed_occupancy_window_side', 'off')}}"