Bed occupancy DIY sensor

Yes…

No idea to be honest. I just have the solder that came with my slightly-better-than-budget soldering iron!

I’ll get some…

Thanks for the guidance.

Give it a go with what you have.

Ok, Thanks. I’ll let you know what happens…

No difference.
I think I’ll try ordering a new strain gauge.

Your D1 mini ADC might now be kaput too. Not meant to take more than 3.3v. Try out the sensor with the multimeter before connecting the new module to A0. Adjust with the pot for less than 3.3v.

1 Like

I’ve ordered another D1 Mini (it is only a couple of pounds).
But…
The spec of my strain gauge seems to say that it only outputs 0-3.5V?


Voltage: 5V
Two tube reverse protection ~ (to prevent the power supply connected to the back)
On board with a blue LED power indicator
Analog output
The higher the bending degree, the higher the output voltage
Zero potentiometer
Can be used to adjust the output voltage of the starting voltage
Output analog voltage 0-3.5V
Board size: 32 X 17 mm
The board is printed with pin output definition

eheh … like 10 litle monkeys jumping on the bed ? :slight_smile:

@tom_l could you say what is the use case? In the past, I had in mind that I needed that, but not any more

When I go to bed everything switches off, lights, tv, stereo etc… and the heating is turned down.

While in bed the alarm is armed in home mode and the bedroom motion automated light is disabled.

When I get up I get the day’s announcements and the light sunrise simulation turns off (if it is still running).

3 Likes

I did something like this with ESPHome as well, but oriented at my favorite arm chair. Taking a page from [https://selfhostedhome.com/diy-bed-presence-detection-home-assistant/](DIY Bed Presence) I check to see if the average value has changed more than 500 before pushing out a new value.

I also set up template binary sensors to check the occupancy state of the chair.

Both of these allow the chair to react quickly to stimuli, but not overload the network or home assistant with constantly updating values.

Basic code is as such… You’ll have to change the main sensor to reflect what you’re using, but other than that the rest is directly applicable.

globals:
   - id: last_chair_load_state
     type: int
     restore_value: no
     initial_value: '0'


sensor:
  - platform: hx711
    id: "chair_load"
    dout_pin: D2
    clk_pin: D3
    filters:
    - sliding_window_moving_average:
        window_size: 5
        send_every: 5
        update_interval: 3s
        unit_of_measurement: mg

  - platform: template
    name: "chair_load_value"
    lambda: |-
      //if the load value has changed more than 500 from the last saved average, publish a new value and change the average
      if (abs(id(chair_load).state-id(last_chair_load_state))>500) { 
        id(last_chair_load_state)=id(chair_load).state;
        return (float)id(chair_load).state;
      } else {
        return {};  //don't publish a value
      }

binary_sensor:
  - platform: template
    name: "chair occupied"
    lambda: |-
      if (id(chair_load).state > 9050000 && id(chair_load).state < 9300000) {
        // Someone in Chair
        return true;
      } else {
        return false;
      }
1 Like

Hello Guys,
would like to use this sensor setup, too.

Wich sensor is the best ?

There are links to the parts used in this project in the first post.

I am a newbie. Do I just add this code into my esphomeyaml or somewhere else?

Best wishes.

James.

That goes in home assistant to define a binary sensor from the discovered ESP strain gauge sensor. The ESP configuration is here: Bed occupancy DIY sensor

Thank you. Just ordered the sensor, so i’ll let you know how I get on.

Best wishes.

I’ve actually made the sensor much more responsive now that I’m not using a cheap noisy 5V power supply. The sensor config in the ESP home file is now:

  - platform: adc
    pin: A0
    name: "Master Bed Sensor"
    update_interval: 3s
    filters:
      - multiply: 3.25
      - sliding_window_moving_average:
          window_size: 10
          send_every: 10
          send_first_at: 10

This gives a reaction time of about 30 seconds for in/out of bed. It could probably be made even faster.

I’m about to set this up. You just referenced a better power supply. Any chance you can share what you used?

I used a spare iPhone charger I had lying around.

Any good quality 5V or 3.3V regulated and filtered power supply will do. i.e. not a $1 Aliexpess plug pack.

Hi Tom, thanks for doing this write up! i got a few d1 minis and strain sensors and just finished setting this up the other day. I’m using the same sensor code you posted on Jun 23, but I’m still getting results like the ones you were getting before you started using a better power supply. I have tried 3 different power supplies, and they each seem to act a little bit different, but not the great steady results you are getting. I can smooth out the line by raising the window_size, but i was hoping to get a slightly better reaction time. any thoughts?

With the best power supply I had lying around (an apple iPhone charger 5V 1.5A) and using this sensor filtering:

  - platform: adc
    pin: A0
    name: "Master Bed Sensor"
    update_interval: 3s
    filters:
      - multiply: 3.25
      - sliding_window_moving_average:
          window_size: 10
          send_every: 10
          send_first_at: 10

I’m getting this sort of result (ignore the really flat bit - that was an mqtt problem)

Annotation%202019-07-25%20134212 :

For this I get a reaction time of 30 seconds at most, which is more than enough for me.

Have you tried adjusting the potentiometer on the board to give you about 2-3V out when the bed is unloaded?

Be careful with the adjustment it is possible to damage the D1 mini’s input if you go avove 3.3V.

You can decrease the update interval for faster reaction times but I wouldn’t reduce the filtering much further.

Also to get a better voltage swing between in and out of be I raised the measuring slat up 5mm using wooden shims under each side of the slat. Though this probably won’t affect noise.

Have you got a screen shot of what you are seeing?

Edit: I just changed the update interval to 1 sec. The sensor now reacts within 10 seconds. No change to noise level. This possibly now has privacy issues if used on my spare bed though :slight_smile:

Please ask for wiring diagram