Bed occupancy sensor, using parts you have

Can you make more sensors? I want to add sensors to your bed project that I don’t know yet. Please help me add sensors.

What are you going on about?

I had binary_sensor in my automation
Now I want to add sensors. Can someone help me?

esphome.io is what you want.

Took a while, but last weekend, I had the chance to work on this bed sensor project. I have to say, it is just great, thanks a lot to @N-l1 for your tutorial. :+1:

My first try was “normal” tin foil and a little heavier paper. Normal copy paper is 80g/m², I used a 120g/m². As you can see in the pic, they were just a prototype and way to small to work correctly. But to get the idea and test it a bit, they were great. :slight_smile: All worked like a charme, the values are not really that big compared to other real sensors, with someone in bed they ranged around 18 to 24 and with no weight they were around 40 to 50.
Nevertheless I tested these for two days, mainly because I couldn’t get my hand on a “heavy duty” tin foil.

After I got a heavy duty tin foil (pictured) I made new stripes for my slatted frame. In the second version (call it 2.0 :smiley: ) I made the stripes with the following setup:

  • my frame is 1.00m wide, so I made the paper/carton 80cm and the tin foil 70cm, where 10cm are for folding one end to put the paper clip on.
  • I used heavy duty or extra strong tin foil
  • I used an even thicker paper/carton, this time it was 180g/m².
  • I use two stripes for each side of the bed, they are glued on the frame with a distance around 50cm to 60cm.

The values are even lower with this setup, I have no idea, if it is the thicker tin foil, or the paper or even the length of the stripes.But they are very steady and therefor can give a good basis for sensors in HA. Right now I have a value of 9 with someone in bed, 13 without anything in bed, and 11 with two piles of t-shirts. My treshold is set to 10 and everything works fine. What I had to do was adjust the values after the first night, but since then, everything works very reliable.

I’m very happy and as I said, I didn’t have one incorrect reading. :smiley: :+1:

6 Likes

I just made one of these as well. Used poster board from staples and heavy duty tinfoil. I also have a slat bed frame, with a memory foam mattress. Seems to work pretty good. My settings are 12 when off, 7 when on. 10 when the dog jumps on he is about 16 pounds.

I copied an article I read from Phil Hawthorne, “Making Home Assistant’s Presence Detection not so Binary”, and applied it to the bed sensor.

I now have states of:
- Just Laid Down
- Asleep
- Just Left Bed
- Back to Bed
- Bed Empty

I can use these to run different automatons depending on each specific state.

Pretty cool.

5 Likes

hey i know this is late reply but i did this project and got around the slate bed with kids hard covered books and double sided taped.

3 Likes

Clever!

This is a really cool idea so I had to test it out myself!
I have added cut up sponges inbetween the paper for a higher range and I am quite happy with the result so far

However, since I had many Wemos D1 Mini lying around, I wanted to incorporate an ESP8826 rather than an ESP32, so for those of you that also rather use the ESP8826, here are a few pointers:

This library makes it possible - in short, you have an output and an input connected with a resistor and your selfmade capacity and calculate the time it takes for the input to trigger. The value you get is arbitrary, but is correlated to the capacity due to the time-constant RC

You have to be aware however that not every pin works due to internal pull up and pull down resistors, and you also have to take them into account when choosing a resistor to connect to as is discussed here

Important hereby is:

Input pin impedance

The esp pins seem to have a much lower impedance than the atmega pins. With a 1MOhm resistor, my Wemos D1 mini board was not able to pull up the receiver pin. With a 470kOhm resistor, it worked.

and

There are a limited number of pins on the ESP8266 which will work, I have identified them as follows, they are the ESP8266 GPIO identification, and this assignment must be used in your code.

GPIO 4 (used as output)
GPIO 5 (tested as Input)
GPIO 12 (tested as input)
GPIO 13 (tested as input)

and a bit offtopic:
I have also hooked up a pir motion sensor to track my sleeping pattern, apparently when you move around it is easier to wake up rather than when you are completely still. I am planning to combine this with my alarm clock - has anyone tried this concept yet?

2 Likes

Can I use a raspberry-pi 4 and connected the fields to it or with help of an MCP3008?

I would have to find out how to measure a capacitor with a raspberry pi 4?
I thought the MCP3008 could help me and bought one but unfortunately I can’t get anywhere with it.
I didn’t want to use an Arduino or an ESP32 for a project. I would like to read out my “capacitors” myself as I can measure them with my multimeter.

I was thinking of a way to have Alexa constantly announcing to my kid to go to bed. This project maybe the solution.

1 Like

I am new to ESPHome and MQTT. In the code, what do I input for these settings?

# Uncomment this if you use Home Assistant
#api:
#  password: “change_this_please!”


# Over-The-Air updates
ota:
  password: “change_this_please!”

I am planning to use MQTT Broker. How do I Configure the sensor with MQTT?

You really need to read the docs at esphome.io

Hi @duceduc, you will need to change these settings

# Fill your MQTT information
# Delete this if you're using Home Assistant
mqtt:
   broker: 10.0.0.2
   username: livingroom
   password: MyMQTTPassword

Thanks for the clarification. I didn’t realize I pasted the same 2 settings above. The other one is the mqtt settings as you have pasted. I was confused by the comment.

# Delete this if you're using Home Assistant

I am using Home Assistant.

Yes, what I meant to do was to make it easier for Home Assistant users not wanting to use MQTT, since the native ESPHome API integration is much easier to use. Sorry for the confusion :sweat_smile:

I used @N-l1’s paper pressure sensor as a guide and scaled up to cover the large middle portion of my bed (roughly where my hips and torso lie). Instead of paper I used a single 36"x60" closed-cell foam sheet and covered each side with copper-coated aluminum foil. I used closed-cell foam to allow the capacitance to rebound/reset after I leave the bed. I wired one side to a capacitance pin on my ESP32 and the reverse side to ground. Works like a champ with the following config in ESPHome:

esp32_touch:
  setup_mode: True
  iir_filter: 10ms
  sleep_duration: 1ms

binary_sensor:
  - platform: esp32_touch
    name: "ESP32 Whole Bed GPIO4"
    pin: GPIO4
    threshold: 4
    filters:
      - delayed_off: 2500ms

In Home Assistant I did wrap this sensor with a second sensor to prevent flapping while I tested out threshold values:

binary_sensor:
  - platform: template
    sensors:
      esp32_bed_occupancy:
        entity_id: binary_sensor.esp32_whole_bed_pressure
        delay_on:
          seconds: 2
        delay_off:
          seconds: 2
        value_template: >-
          {{
            is_state('binary_sensor.esp32_whole_bed_pressure', 'on')
          }}

Going forward I’ll either integrate this logic into ESPHome or remove it altogether.

1 Like

@N-l1
I’ve got it setup and only used 3 pads for a kid’s size bed.

Threshold :

Top: 3
Middle: 3
Bottom: 4

Got a question:
Is it possible to disable the red LED on the ESP32?

Hi @duceduc, if you are using the ESP32 NodeMCU and referring to the red LED, it seems like it is an indicator of whether there is power and is unable to be turned off. However, the blue LED on the ESP32 is connected to the GPIO2 pin and you can turn it off (when there is no error) by setting it as a status LED in ESPHome:

status_led:
  pin: GPIO2

Hmm. I do have the ESP32 NodeMCU board. However, I have seen only the red power light on. Never the blue. Does that mean I have an error somewhere? The sensors seems to be working proper.