This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:tech:bedsensor [2021/01/19 03:57] – [Motivation] bullar | en: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 |
{{: | {{: | ||
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 |
====Hardware==== | ====Hardware==== | ||
Line 65: | Line 65: | ||
{{ : | {{ : | ||
- | ====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:// | After the hardware has been created we still have to program the ESP module. As already mentioned, the bed sensor is based on [[https:// | ||
- | Wenn alles geklappt hat und das Modul im heimischen WLAN eingebunden ist, kann die gesamte weitere Einstellung über das Webinterface erfolgen. Dazu benötigen wir: | + | If everything went well and the module is integrated in the home WiFi, all further settings can be made via the web interface. For this we need: |
- | * MQTT Controller | + | * MQTT controller |
- | * Device | + | * Device |
* Rules Setup | * Rules Setup | ||
===MQTT Controller setup=== | ===MQTT Controller setup=== | ||
- | Der Bettsensor soll sich ja mit einem vorhandenen | + | The bed sensor should connect to an existing |
{{ : | {{ : | ||
===Devices=== | ===Devices=== | ||
- | Als zweites brauchen wir ein Device was den analogen Wert misst und speichert. Das lässt sich über den Reiter | + | Second, we need a device that measures and stores the analog value. This can be done via the // |
{{ : | {{ : | ||
- | Die grünen Zahlen rechts geben übrigens die aktuellen Messwerte wieder. In dem Beispiel liegt keiner im Bett.\\ | + | Incidentally, |
- | Hier die Einstellungen für die Devices: | + | Here are the settings for the devices: |
{{: | {{: | ||
Line 91: | Line 91: | ||
===Rules=== | ===Rules=== | ||
- | Nun haben wir eine Anbindung an den MQTT Server und wir können die Messwerte des ADC abfragen. Was fehlt ist die Ablaufsteuerung. Innerhalb des ESPEasy gibt es dafür die // | + | 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 control. There are the // |
- | Dazu den folgenden Code in das Rules Set 1 kopieren. | + | To do this, copy the following code into Rules Set 1. |
< | < | ||
Line 132: | Line 132: | ||
</ | </ | ||
- | Während des SystemBoot setzen wir den Multiplexer entsprechend auf Eingang | + | During the system boot we set the multiplexer to input 1, the start values to |
- | Jede Sekunde werden dann beide Werte ausgelesen und wenn es eine Veränderung um den Schwellwert gegeben hat, wird das Ergebnis an den MQTT Server gesendet. Das sind die Zustände | + | Both values are read out every second and if there has been a change to the threshold value, the result is sent to the MQTT server. These are the states |
- | ====Beispiel==== | + | ====Programming (ESPHome)==== |
- | Hier die Aufzeichnung der konvertierten Werte [0..1023] einer Nacht. Die Drops sind nicht bedingt durch eine altersbedingte Inkontinenz sondern das kurzzeitige Wegkuscheln auf die Bettmitte | + | The integration into [[https:// |
+ | Here the final code for Bedsensor: | ||
- | {{ :tech:bed?diagram.jpeg? | + | <code yaml> |
+ | esphome: | ||
+ | name: bedsensor | ||
+ | on_boot: | ||
+ | then: | ||
+ | - delay: 20s | ||
+ | - output.turn_off: led_blue | ||
+ | esp8266: | ||
+ | board: esp01_1m | ||
- | ====Fazit==== | + | # Enable logging |
- | Der Bettsensor läuft jetzt seit 2 Jahren ohne Probleme. Je nachdem wie stabil das heimische WLAN ist kann aber mal ein Neustart des Bettsensors notwendig werden. | + | logger: |
+ | |||
+ | # Enable Home Assistant API | ||
+ | api: | ||
+ | encryption: | ||
+ | key: " | ||
+ | |||
+ | ota: | ||
+ | password: " | ||
+ | |||
+ | wifi: | ||
+ | ssid: !secret wifi_ssid | ||
+ | password: !secret wifi_password | ||
+ | |||
+ | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
+ | ap: | ||
+ | ssid: " | ||
+ | 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: | ||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====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 :-) | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | ====Conclusion==== | ||
+ | The bed sensor has been running without problems for 2 years now. Depending 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:// | * [[http:// | ||
+ | |||
+ | ==== Donate ==== | ||
+ | |||
+ | If you like my articles feel to donate a cappuccino or so... | ||
+ | |||
+ | < | ||
+ | |||
+ | <form action=" | ||
+ | <input type=" | ||
+ | <input type=" | ||
+ | <img alt="" | ||
+ | </ | ||
+ | |||
+ | </ | ||