Site Tools


en:tech:bedsensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:tech:bedsensor [2021/01/19 03:56] – created bullaren:tech:bedsensor [2026/08/12 13:53] (current) claude
Line 4: Line 4:
  
 Everyone who has become infected with the topic of smart home considers almost continuously how he/she can still automate manual, recurring tasks further. Provided that the appropriate sensors and actuators are already available. A sensor area that seems somewhat underrepresented is the occupancy sensor, e.g. to trigger or refrain from actions by going to bed. \\ Everyone who has become infected with the topic of smart home considers almost continuously how he/she can still automate manual, recurring tasks further. Provided that the appropriate sensors and actuators are already available. A sensor area that seems somewhat underrepresented is the occupancy sensor, e.g. to trigger or refrain from actions by going to bed. \\
-There are alarm mats as bed rugs or professional bed sensors from the care sector. The seat sensors from the automotive industry also perform a similar task. What they all have in common, however, is the lack of connection to an open protocol such as MQTT and of course the usually very high purchase costs.+There are alarm mats as bed rugs or professional bed sensors from the care sector. The seat sensors from the automotive industry also perform a similar task. What they all have in common, however, is the lack of connection to an open protocol such as MQTT or Home Assistant and of course the usually very high purchase costs.
  
-{{:tech:bettsensor_prof.png?direct&300|Professional bedsensor}} +{{:media:tech:bedsensor:bettsensor_prof.png?direct&300|Professional bedsensor}} 
-{{:tech:sitzbelegungsmatte.jpg?direct&200|Car seat sensor}}+{{:media:tech:bedsensor:sitzbelegungsmatte.jpg?direct&200|Car seat sensor}}
  
 Some resourceful developers have addressed this gap and have, for example, integrated switches into the bed frame [[https://homematic-forum.de/forum/viewtopic.php?t=16239|Selbstgebauter Bettsensor... Steuern und Regeln im Schlaf!]] Some resourceful developers have addressed this gap and have, for example, integrated switches into the bed frame [[https://homematic-forum.de/forum/viewtopic.php?t=16239|Selbstgebauter Bettsensor... Steuern und Regeln im Schlaf!]]
Line 13: Line 13:
 My approach looks a little different to be as minimally invasive as possible for the bedstead. I use a pressure-sensitive resistor (FSR) as a sensor. It is also available in an extra long version of 60cm [[https://cdn.sparkfun.com/datasheets/Sensors/Pressure/FSR408-Layout2.pdf|FSR 408]]. When unloaded, the resistance is high ohm (> 10MOhm) and with a load of 10kg the value is reduced to a few 100 ohms. The sensor is self-adhesive and can be easily attached to a slatted frame, for example. My approach looks a little different to be as minimally invasive as possible for the bedstead. I use a pressure-sensitive resistor (FSR) as a sensor. It is also available in an extra long version of 60cm [[https://cdn.sparkfun.com/datasheets/Sensors/Pressure/FSR408-Layout2.pdf|FSR 408]]. When unloaded, the resistance is high ohm (> 10MOhm) and with a load of 10kg the value is reduced to a few 100 ohms. The sensor is self-adhesive and can be easily attached to a slatted frame, for example.
  
-{{ :tech:fsr408.png?direct&300 |FSR 408}}  +{{ :media:tech:bedsensor:fsr408.png?direct&300 |FSR 408}}  
-{{ :tech:force_curve.png?direct&300 |Typical Force Curve}} +{{ :media:tech:solarvilla:force_curve.png?direct&300 |Typical Force Curve}} 
-{{ :tech:bedsensor_mounted.jpeg?direct&300 |Mounted Bed Sensor}} +{{ :media:tech:bedsensor:bedsensor_mounted.jpeg?direct&300 |Mounted Bed Sensor}} 
  
-With the FSR 408, the existing pressure can easily be evaluated with a simple resistor network and an A/D converter or comparator. There are several options for getting the value into the smart home network. One of the simplest is an ESP8266 module (ESP-07) with the open-source firmware called [[https://www.letscontrolit.com/wiki/index.php/ESPEasy|ESP Easy]]. By the way, you can find a similar approach with a Raspberry Pi {{https://community.home-assistant.io/t/bed-occupancy-sensor-force-sensing-resistor-fsr-raspberry-pi-zero-wh-analogzero-phat/91999|hier}}.+With the FSR 408, the existing pressure can easily be evaluated with a simple resistor network and an A/D converter or comparator. There are several options for getting the value into the smart home network. One of the simplest is an ESP8266 module (ESP-07) with the open-source firmware called [[https://www.letscontrolit.com/wiki/index.php/ESPEasy|ESP Easy]]. By the way, you can find a similar approach with a Raspberry Pi {{https://community.home-assistant.io/t/bed-occupancy-sensor-force-sensing-resistor-fsr-raspberry-pi-zero-wh-analogzero-phat/91999|here}}.
  
-{{ :tech:esp07.png?direct&200 |ESP-07}}+{{ :media:tech:powermeter:esp07.png?direct&200 |ESP-07}}
  
 ====Features==== ====Features====
Line 26: Line 26:
   * Two sensor inputs for a double bed   * Two sensor inputs for a double bed
   * WiFi integration   * WiFi integration
-  * MQTT protocol+  * MQTT protocol or ESPHome
  
 ====Hardware==== ====Hardware====
Line 32: Line 32:
 The resistor network for evaluating the pressure looks like this: The resistor network for evaluating the pressure looks like this:
  
-{{ :tech:bedsensor_network.png?direct&200 | Resistor Network}}+{{ :media:tech:bedsensor:bedsensor_network.png?direct&200 | Resistor Network}}
  
 The output voltage to the ADC is calculated as follows: The output voltage to the ADC is calculated as follows:
Line 51: Line 51:
 In our application, the maximum value should not exceed 1V, as the internal analog reference voltage of the ESP-07 is 1V. We also need a multiplexer to evaluate two sensors. The complete circuit diagram is still very simple. In our application, the maximum value should not exceed 1V, as the internal analog reference voltage of the ESP-07 is 1V. We also need a multiplexer to evaluate two sensors. The complete circuit diagram is still very simple.
  
-{{ :tech:bedsensor_schematic.png?direct&400 | Schematic Bed Sensor}}+{{ :media:tech:bedsensor:bedsensor_schematic.png?direct&400 | Schematic Bed Sensor}}
  
 Of course, you can also connect just one FSR408 with R2 directly to the module, possibly avoiding the circuit board with free wiring. Of course, you can also connect just one FSR408 with R2 directly to the module, possibly avoiding the circuit board with free wiring.
Line 57: Line 57:
 In order to keep the module as small as possible, the circuit is made in SMD. Suitable home soldering techniques have already been published in various places. In order to keep the module as small as possible, the circuit is made in SMD. Suitable home soldering techniques have already been published in various places.
  
-{{ :tech:bedsensor_pcb.png?direct&400 |PCB Bed Sensor}} +{{ :media:tech:bedsensor:bedsensor_pcb.png?direct&400 |PCB Bed Sensor}} 
-{{ :tech:bedsensor_pcb.jpeg?direct&400 |PCB Bed Sensor}}+{{ :media:tech:bedsensor:bedsensor_pcb.jpeg?direct&400 |PCB Bed Sensor}}
  
 The sensors are connected via standard 2.5mm jack sockets (JY029). The power supply can also be plugged in with a 5.5 / 2.1mm hollow socket (HEBW21). You can find it very inexpensive [[https://www.ebay.de/itm/351218451793|Power Supplies]] with stabilized 3.3V DC voltage output. The bed sensor does not need more wired connectivity. \\ The sensors are connected via standard 2.5mm jack sockets (JY029). The power supply can also be plugged in with a 5.5 / 2.1mm hollow socket (HEBW21). You can find it very inexpensive [[https://www.ebay.de/itm/351218451793|Power Supplies]] with stabilized 3.3V DC voltage output. The bed sensor does not need more wired connectivity. \\
 With a 3D printer an inconspicuous housing can be realized which can easily be attached with double-sided adhesive tape underneath the bed. With a 3D printer an inconspicuous housing can be realized which can easily be attached with double-sided adhesive tape underneath the bed.
-{{ :tech:bedsensor_case.png?direct&400 |Housing Bed Sensor}} +{{ :media:tech:bedsensor:bedsensor_case.png?direct&400 |Housing Bed Sensor}} 
-{{ :tech:bedsensor_module.jpeg?direct&400 | Bed Sensor open}}+{{ :media:tech:bedsensor:bedsensor_module.jpeg?direct&400 | Bed Sensor open}}
  
-====Programing====+====Programming (ESPEasy)====
  
 After the hardware has been created we still have to program the ESP module. As already mentioned, the bed sensor is based on [[https://www.letscontrolit.com/wiki/index.php/ESPEasy|ESPEasy]]. In the link you can also find instructions on how the ESPEasy firmware is installed on the module. In order to get into the programming mode, the jumper SJ1 must be closed during the reset release. The programming is done serially via JP1 (USB-serial converter). After the hardware has been created we still have to program the ESP module. As already mentioned, the bed sensor is based on [[https://www.letscontrolit.com/wiki/index.php/ESPEasy|ESPEasy]]. In the link you can also find instructions on how the ESPEasy firmware is installed on the module. In order to get into the programming mode, the jumper SJ1 must be closed during the reset release. The programming is done serially via JP1 (USB-serial converter).
  
-Wenn alles geklappt hat und das Modul im heimischen WLAN eingebunden istkann die gesamte weitere Einstellung über das Webinterface erfolgenDazu benötigen wir+If everything went well and the module is integrated in the home WiFiall further settings can be made via the web interfaceFor this we need
-  * MQTT Controller setup +  * MQTT controller setup 
-  * Device Setup+  * Device setup
   * Rules Setup   * Rules Setup
  
 ===MQTT Controller setup=== ===MQTT Controller setup===
-Der Bettsensor soll sich ja mit einem vorhandenen MQTT Server verbinden und die aktuelle Belegungsinformation bei Änderung dorthin übertragenDazu gehen wir auf den Reiter //Controller// und tragen die entsprechende Daten ein. Dazu gehören u.adie IP Adresse des MQTT Servers sowie die Account Daten für die AnmeldungDas Resultat sollte ähnlich dem folgenden Beispiel aussehen.+The bed sensor should connect to an existing MQTT server and transfer the current occupancy information to it if there is a changeTo do this, we go to the //Controller// tab and enter the relevant dataThis includes the IP address of the MQTT server and the account data for logging inThe result should look similar to the following example.
  
-{{ :tech:easyesp_controller.png?direct&300 | MQTT Controller Setup}}+{{ :media:tech:bedsensor:easyesp_controller.png?direct&300 | MQTT Controller Setup}}
  
 ===Devices=== ===Devices===
-Als zweites brauchen wir ein Device was den analogen Wert misst und speichertDas lässt sich über den Reiter //Devices// erreichenFür jeden Sensor gibt es ein eigenes Device und zusätzlich benötigen wir noch ein Dummy Device um den vorherigen Messewert zwischen zu speichern.+Second, we need a device that measures and stores the analog valueThis can be done via the //Devices// tabThere is a separate device for each sensor and we also need a dummy device to temporarily store the previous measurement value.
  
-{{ :tech:easyesp_devices.png?direct&400 | Devices Setup}}+{{ :media:tech:bedsensor:easyesp_devices.png?direct&400 | Devices Setup}}
  
-Die grünen Zahlen rechts geben übrigens die aktuellen Messwerte wieder. In dem Beispiel liegt keiner im Bett.\\ +Incidentally, the green numbers on the right indicate the current measured values. In the example nobody is in bed. \\ 
-Hier die Einstellungen für die Devices:+Here are the settings for the devices:
  
-{{:tech:easyesp_analog.png?direct&300| Analog Device Setup}} +{{:media:tech:bedsensor:easyesp_analog.png?direct&300| Analog Device Setup}} 
-{{:tech:easyesp_dummy.png?direct&300| Dummy Device Setup}}+{{:media:tech:bedsensor:easyesp_dummy.png?direct&300| Dummy Device Setup}}
  
 ===Rules=== ===Rules===
-Nun haben wir eine Anbindung an den MQTT Server und wir können die Messwerte des ADC abfragenWas fehlt ist die AblaufsteuerungInnerhalb des ESPEasy gibt es dafür die //Rules//: +Now we have a connection to the MQTT server and we can query the measured values ​​of the ADC. What is missing is the flow controlThere are the //Rules// for this within the ESPEasy
-Dazu den folgenden Code in das Rules Set 1 kopieren.+To do this, copy the following code into Rules Set 1.
  
 <code> <code>
Line 132: Line 132:
 </code> </code>
  
-Während des SystemBoot setzen wir den Multiplexer entsprechend auf Eingang 1, die Startwerte auf 100 und einen Timer der jede Sekunde die folgende Routine aufruft+During the system boot we set the multiplexer to input 1, the start values ​​to 100 and a timer that calls the following routine every second
-Jede Sekunde werden dann beide Werte ausgelesen und wenn es eine Veränderung um den Schwellwert gegeben hatwird das Ergebnis an den MQTT Server gesendetDas sind die Zustände IN bzw. OUT. Man kann natürlich auch die aktuellen Werte übermitteln und die Entscheidung ob IN oder OUT der Homeautomatisierung überlassenIm folgenden Beispiel habe ich so mal eine Nacht aufgezeichnet+Both values ​​are read out every second and if there has been a change to the threshold valuethe result is sent to the MQTT serverThese are the states IN and OUT. You can of course also transmit the current values ​​and leave the decision as to whether IN or OUT to the home automationIn the following example I recorded a night like this.
  
-====Beispiel==== +====Programming (ESPHome)==== 
-Hier die Aufzeichnung der konvertierten Werte [0..1023einer NachtDie Drops sind nicht bedingt durch eine altersbedingte Inkontinenz sondern das kurzzeitige Wegkuscheln auf die Bettmitte :-)  +The integration into [[https://www.home-assistant.io|Home Assistant]] lcan be easily done with [[https://esphome.io|ESPHome]]. All mandatory infos about the programming can also be found there online. 
 +Here the final code for Bedsensor:
  
-{{ :tech:bed?diagram.jpeg?direct&500 | Aufzeichnung einer Nacht}}+<code yaml> 
 +esphome: 
 +  namebedsensor 
 +  on_boot: 
 +    then: 
 +      - delay: 20s 
 +      - output.turn_off: led_blue
  
 +esp8266:
 +  board: esp01_1m
  
-====Fazit==== +# Enable logging 
-Der Bettsensor läuft jetzt seit Jahren ohne ProblemeJe nachdem wie stabil das heimische WLAN ist kann aber mal ein Neustart des Bettsensors notwendig werden.+logger: 
 + 
 +# Enable Home Assistant API 
 +api: 
 +  encryption: 
 +    key: "--key--" 
 + 
 +ota: 
 +  password: "---password---" 
 + 
 +wifi: 
 +  ssid: !secret wifi_ssid 
 +  password: !secret wifi_password 
 + 
 +  # Enable fallback hotspot (captive portal) in case wifi connection fails 
 +  ap: 
 +    ssid: "Bedsensor Fallback Hotspot" 
 +    password: "--password--" 
 + 
 +captive_portal: 
 + 
 +switch: 
 +  - platform: gpio 
 +    pin: GPIO12 
 +    id: sensor_select 
 +    internal: true 
 + 
 +output: 
 +  - platform: gpio 
 +    pin: GPIO2 
 +    inverted: true 
 +    id: led_blue 
 + 
 +sensor: 
 +  - platform: adc 
 +    pin: A0 
 +    id: bed_raw_adc 
 +    update_interval: 1s 
 +    raw: true 
 +    accuracy_decimals:
 +    internal: true 
 +    on_raw_value: 
 +      then: 
 +        - lambda: |- 
 +            if (id(sensor_select).state) {    
 +              if (x < 50) { 
 +                id(bed_sensor_2).publish_state(false);   
 +              } else { 
 +                id(bed_sensor_2).publish_state(true);   
 +              }                 
 +              id(sensor_select).turn_off(); 
 +            } else { 
 +              if (x < 50) { 
 +                id(bed_sensor_1).publish_state(false);   
 +              } else { 
 +                id(bed_sensor_1).publish_state(true);   
 +              }     
 +              id(sensor_select).turn_on(); 
 +            }     
 + 
 +binary_sensor: 
 +  - platform: template 
 +    name: "Bed Sensor 1" 
 +    id: bed_sensor_1 
 + 
 +  - platform: template 
 +    name: "Bed Sensor 2" 
 +    id: bed_sensor_2 
 +</code> 
 + 
 + 
 +====Example==== 
 +Here the recording of the converted values ​​[0..1023] for one night. The drops are not caused by age-related incontinence but rather the short-term cuddling away in the middle of the bed :-)   
 + 
 +{{ :media:tech:bedsensor:bed_diagram.jpeg?direct&500 | Recoding of one night}} 
 + 
 + 
 +====Conclusion==== 
 +The bed sensor has been running without problems for years nowDepending on how stable the home WiFi is, it may be necessary to restart the bed sensor.
  
 ====Downloads==== ====Downloads====
-  * {{:tech:bedsensor_BOM.pdf|Bestückungsliste (BOM)}} +  * {{:media:tech:bedsensor:bedsensor_bom.pdf|Bestückungsliste (BOM)}} 
-  * {{:tech:bedsensor.brd.zip|PCB}} Eagle format (.brd) +  * {{:media:tech:bedsensor:bedsensor.brd.zip|PCB}} Eagle format (.brd) 
-  * {{:tech:bedsensor_v3.stl.zip|Gehäuse}} (STL Datei)+  * {{:media:tech:bedsensor:bedsensor_v3.stl.zip|Gehäuse}} (STL Datei)
  
 ====Links==== ====Links====
   * [[http://www.heise.de/hardware-hacks/artikel/SMD-Loeten-in-der-Pizzapfanne-1276166.html]] SMD Löten mit einfachen Mittel   * [[http://www.heise.de/hardware-hacks/artikel/SMD-Loeten-in-der-Pizzapfanne-1276166.html]] SMD Löten mit einfachen Mittel
 +
 +==== Donate ====
 +
 +If you like my articles feel to donate a cappuccino or so...
 +
 +<html>
 +
 +<form action="https://www.paypal.com/donate" method="post" target="_top">
 +<input type="hidden" name="hosted_button_id" value="49N24HL36GF9U" />
 +<input type="image" src="https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" />
 +<img alt="" border="0" src="https://www.paypal.com/en_DE/i/scr/pixel.gif" width="1" height="1" />
 +</form>
 +
 +</html>
  
en/tech/bedsensor.1611028592.txt.gz · Last modified: by bullar