FSR Bed Sensor

I wanted a bed sensor, I really needed to be able to tell if my partner is or is not in bed and using previous HA systems this was not possible so I had to sorta fudge together things to get as close as I wanted to what was required. I didn’t get very close in reality.

When I changed to HAs a few months ago whole new worlds opened up with a myriad of options for many things, one of which was a bed sensor.

I looked after I got everything across from the old system to HAs and found several options, one was here, sadly no longer supported:

I would have ordered one of the Elevated Sensor ones but there’s a wait, no idea for how long and my impatience got the better of me and I wondered, how hard can it be?

(NOTE: If you are one of those people like I normally am who wants a plug and play solution, the Elevated Sensor one and waiting is your option, your only option far as I can see)

I ordered a couple of 600mm FSR sensors from Aliexpress, a whole £5 each, I had a spare ESP32 and a bunch of other stuff knocking about so I thought I’d try to bodge something together.

To be clear, I am no electronic expert; I haven’t much of a clue about it and, I’m no expert in programming, YAML or anything else. I just cobbled this together off the back of other people’s work and am only posting it in the hope that it helps other people, I can’t really support this as such, I can answer what I can but, don’t expect electronics or programming support.

Anyway, I got onto YouTube, watched a bunch of stuff about using pads, Aqara sensors retested and all that, decided that wasn’t the way to go because of accuracy and durability issues but, all I really needed was a simple binary sensor to know if someone was in bed or not.

Attempt one was just the FSRs connected to the ESP and, well, that failed. I got occupancy detected all the time because the mattress (a chunky memory foam thing) puts enough weight on the sensor to trigger it. So, that was a bust.

It did work though and initially I thought it’d be okay but once the mattress settled it was too heavy and activated the sensors.

Next up was to mess with resistors, and when we get to electronic components, normally I’m out, not my bag, but since I couldn’t get a ready-made one anytime soon, I decided to have a crack at it.

To my huge surprise, never mind my partner’s, it worked and it was actually very simple to do.

To get there I followed the info on the guide above and this one:

I had an ESP32 kicking about with a breakout board and, luckily for me, I could just take a couple of 10K resistors from the 3.3V pin to each GPIO (34 & 35) and just link them, no soldering or mucking about with breadboard.

Two GND feeds, one for each FSR to the GND pin and, sorted. I can get photos if anyone’s interested.

I cannot overstate the dubiety I had that this would work but, it did.

Then got some double sided semi-permanent sticky stuff I used to keep stuff in place in the car, slapped that on the back of the breakout board and stuck it to the underside of the bed slats.

Then used the code from here:

https://www.reddit.com/r/Esphome/comments/11p24vk/bed_occupancy_detection_using_pressure_strips/

To get to this in ESPHome to program the board:

esphome:
  name: bed-sensor
  friendly_name: Bed Sensor

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "You get your own="

ota:
  - platform: esphome
    password: "no password here"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Bed-Sensor Fallback Hotspot"
    password: "no password here either"

captive_portal:
web_server:

sensor:
  - platform: adc
    pin: GPIO34 # Use ADC pin on ESP32
    attenuation: 12db
    name: "Left Bed Sensor"
    id: "Left_bed_sensor"
    icon: mdi:bed
    update_interval: 0.5s
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 1
      - or:
          - throttle: 180s
          - delta: 0.02
  - platform: adc
    pin: GPIO35 #Use ADC pin on ESP32
    attenuation: 12db
    name: "Right Bed Sensor"
    id: "Right_bed_sensor"
    icon: mdi:bed
    update_interval: 0.5s
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 1
      - or:
          - throttle: 180s
          - delta: 0.02
  
  - platform: homeassistant
    name: "Left Bed Trigger Level"
    id: "Left_bed_trigger_level"
    entity_id: input_number.Left_bed_trigger_level
  - platform: homeassistant
    name: "Right Bed Trigger Level"
    id: "Right_bed_trigger_level"
    entity_id: input_number.Right_bed_trigger_level

binary_sensor:
  - platform: template
    name: "Left Bed Occupied"
    device_class: occupancy
    id: leftoccupancy
    # Checks to see if voltage is lower than the trigger level set via input number, if so it sets left bed side to occupied
    lambda: |-
      if (id(Left_bed_sensor).state < id(Left_bed_trigger_level).state) {
        return true;
      } else {
        return false;
      }
  - platform: template
    name: "Right Bed Occupied"
    id: rightoccupancy
    # Checks to see if voltage is lower than the trigger level set via input number, if so it sets right bed side to occupied
    device_class: occupancy
    lambda: |-
      if (id(Right_bed_sensor).state < id(Right_bed_trigger_level).state) {
        return true;
      } else {
        return false;
      }

Once that’s done, In HAs you get this as an ESP device:

You can see that you get the two sensors as intended and, that’s what I wanted but you also get sliders to alter the trigger point of those binary sensors being activated or not, this allows you a great deal of flexibility on setting it all up for your use.

And, you get the voltage based on the pressure that’s being read almost in real time which is fantastic for both testing and setting the trigger point but also can be used for other purposes, for example, a dog on the bed that’s not heavy enough to trigger an “in-bed_ state but you want to know about it.

I’ve only had a few days with this but, so far so good. It’s proven to be very reliable and gives repeatable results time after time.

Hopefully this will help anyone looking to make up a simple bed sensor based on these FSR strips as I searched for days to get this info all together and I am really grateful for the people that posted all the stuff that allowed me to do it, I just thought I’d bring it all together for others in what I hope is an easy to follow post.

And unlike me, with all the bits you need for this that are:

ESP32
FSR sensor/s
10K resistor/s
some bits of wire

It will take about an hour or less to cobble this together rather than the two or three weeks it took me to do.

There’s probably better ways, certainly neater (“proper”) ones I expect and you could probably add other sensors etc to the ESP but, for me at least, this works.

1 Like