Site Tools


en:tech:bedsensor

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:tech:bedsensor [2021/01/19 03:57] – [Motivation] bullaren:tech:bedsensor [2022/09/26 09:59] (current) – external edit 127.0.0.1
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}} {{:tech:bettsensor_prof.png?direct&300|Professional bedsensor}}
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 65: Line 65:
 {{ :tech:bedsensor_module.jpeg?direct&400 | Bed Sensor open}} {{ :tech: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}} {{ :tech: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}} {{ :tech: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}} {{:tech:easyesp_analog.png?direct&300| Analog Device Setup}}
Line 91: Line 91:
  
 ===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 :-)   
 + 
 +{{ :tech: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====
Line 151: Line 238:
 ====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.1611028629.txt.gz · Last modified: 2021/01/19 03:57 (external edit)