FSR - the best bed occupancy sensor

My local electronics store stocks them in a range of sizes. I believe they are this one if you want to search for an online supplier: CBRS02VGY - Room sensor enclosure, Size 2, Vented, Grey, 74x74x25.5mm | CamdenBoss

I have all my parts and got to thinking… the only thing I don’t see is the sketch for the D1-mini… Unless there isn’t one.

Thanks again, great project.

The whole device file isn’t there but the sensors you need to define are in the first post.

@tom_l Using a similar FSR that appears to have different properties. It might also be that the FSR is used between a memory foam mattress and a box spring with less force on the FSR.

What would you recommend for R1 when the in-bed resistance is 25k to 70k and out-of-bed is OL (approx 5m)?

Using the following formula from Overview | Force Sensitive Resistor (FSR) | Adafruit Learning System, it appears a very large value for R1 would be necessary.

Vo = Vcc ( R / (R + FSR) )

Would you recommend a R1 value somewhere around 1m or is there a different approach that would work better?

Edit:
So far a 1mΩ resistor and 0.5v trigger appears to be working well. Will test for a few days before implementing any automations. Thanks for the great tutorial!

2 Likes

What about a bed sensor for a waterbed? Anyone thought of rhat type of bed occupancy sensor ?

One mili-Ohm? (capital M for meg-Ohm)!

Try 560k Ohm, as calculated by the formula in my post. That should give a wider range.

1 Like

This will not work for a waterbed. Start a new topic asking for suggestions as it is off topic here.

1 Like

Haha, thanks for the clarification! Should have been M.

Using R1 of 1M produced an in-bed of 1.6v to 3.1v and a very consistent out-of-bed of ~0.2v last night. Looks like it dropped to about 1.6v when tossing and turning. Maybe the resistor tolerance isn’t the best but it produced a large enough in/out difference that the occupancy was accurate when using the following code. Also attempting to make everything more fault tolerant by moving the trigger requirements to the ESP. Plus I have no need for HA to display/record the voltage.

binary_sensor:
# Bed Sensor - Occupancy
  - platform: template
    name: $friendly_name Bed Occupied
    id: bed_sensor_o
    device_class: occupancy
    lambda: |-
      if (id(bed_sensor_v).state > 0.5) {
        return true;
      } else {
        return false;
      }
sensor:
# Bed Sensor - FSR Voltage
  - platform: adc
    pin: GPIO33
    attenuation: 11db
    # Commented name to hide the sensor from HA
    # name: $friendly_name Bed Sensor Voltage
    id: bed_sensor_v
    icon: mdi:bed
    update_interval: 0.5s
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 1
      - or:
          - throttle: 180s
          - delta: 0.2

A few more days of testing and I’ll continue automating night routines and also automate a bedjet using the new ESPHome integration.
Thanks for the great tutorial!

1 Like

I just build the bed occupancy sensor as well and I LOVE it! many thanks for the clear instructions, it works very reliable and like a charm.

BTW: I used this sensor, seems like it is the OEM-brand which also produces the Sparkfun labelled-ones: https://www.digikey.ch/en/products/detail/interlink-electronics/30-61710/2476472

glad to help anybody if you have questions.

2 Likes

Always good to have more sources but its cheaper to buy it from Sparkfun than Digikey Australia.

Thank you for your reply.
I followed your example and changed out the Fibaro smart implant with an asp32 and your code, witch is working really well.
When I get in bed it reacts fast and accurate, but when I get out off bed after a night sleep the value drops really slowly sometimes it takes hours.
My guess is that there is still some mechanical strain on the sensor that takes some time to level out, I put it between my two thick matrassen and you put it on the wooden slate.
i’am gonna try to put a piece of wood under the sensor to see of that helps, or maybe you have some advice for me

The only tests I have done are with the FSR between a mattress and a solid base.

1 Like

That is a nifty filter approach. Never thought to use or: like that.

I knew some brand name sensors do similar but never noticed anyone doing it with ESPHome.

Cool way to optimise sending data to HA.

@tom_l Hi. do you have a diagram to replicate the connections in the option of 2 FSR with 1 ESP32?

Just pick another ADC capable input and wire it exactly the same as the first one.

1 Like

Just got this working! Thank you for sharing! I have run into a bit of a problem though. Not sure if you know the answer, but for some reason my trigger level is not updating. I had set it at one number and then decided on a new number, but when I went and changed the input_number it did not update in the trigger sensor.

It’s working for me. I just checked.

Check your logs (home assistant and esphome).

Hi, noob question on measuring resistance for R1
Do i just connect different resistors (10Ω, 100Ω, 1kΩ, 10kΩ) until I get the right values?

No you read and follow the instructions.

Sorry, what i meant was for the Rin & Rout values.
I just have to keep testing with different resistors until i get the correct values then use R1 math.