---
slug: bed-presence-detection-with-aqara-window-and-door-sensor-and-a-cheap-car-part
title: "Bed presence detection with Aqara window and door sensor and a cheap car part"
tags: [smart home, Home Assistant, home automation, DIY, Aqara, Xiaomi]
image: /img/blog/2020/12/bed.jpeg
---
Bed presence detection could be very useful in home automation to control the lights and appliances you don’t 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? Let’s take a closer look at its internals.

<!-- truncate -->

![internals](internals-1.jpg)

See that little glass tube? That’s a [reed switch](https://en.wikipedia.org/wiki/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](seat_sensor.jpg)

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 sensor’s board instead of the reed switch.

![image](solder.jpg)

I’ve 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](wires.jpg)

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](cardboard.jpg)

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](bed_sensors.png)

The third sensor on the screenshot is a Home Assistant [template binary sensor](https://www.home-assistant.io/integrations/binary_sensor.template/) that represents unconditional bed occupation. In other words, it is `on` when someone is in bed, and `off` otherwise:

```yaml
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')}}"
```