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 04:05] – bullar | en: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 |
| - | {{: | + | {{:media:tech:bedsensor: |
| - | {{: | + | {{:media:tech:bedsensor: |
| Some resourceful developers have addressed this gap and have, for example, integrated switches into the bed frame [[https:// | Some resourceful developers have addressed this gap and have, for example, integrated switches into the bed frame [[https:// | ||
| 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:// | 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:// | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| - | {{ : | + | {{ :media:tech:solarvilla: |
| - | {{ : | + | {{ :media:tech:bedsensor: |
| 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:// | 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:// | ||
| - | {{ : | + | {{ :media:tech:powermeter: |
| ====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 |
| ====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: | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| 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, | In our application, | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| 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. | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| - | {{ : | + | {{ :media:tech:bedsensor: |
| 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:// | 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:// | ||
| 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. | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| - | {{ : | + | {{ :media:tech:bedsensor: |
| - | ====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:// | ||
| Line 77: | Line 77: | ||
| The bed sensor should connect to an existing MQTT server and transfer the current occupancy information to it if there is a change. To do this, we go to the // | The bed sensor should connect to an existing MQTT server and transfer the current occupancy information to it if there is a change. To do this, we go to the // | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| ===Devices=== | ===Devices=== | ||
| Second, we need a device that measures and stores the analog value. This can be done via the //Devices// tab. There is a separate device for each sensor and we also need a dummy device to temporarily store the previous measurement value. | Second, we need a device that measures and stores the analog value. This can be done via the //Devices// tab. There is a separate device for each sensor and we also need a dummy device to temporarily store the previous measurement value. | ||
| - | {{ : | + | {{ :media:tech:bedsensor: |
| Incidentally, | Incidentally, | ||
| Here are the settings for the devices: | Here are the settings for the devices: | ||
| - | {{: | + | {{:media:tech:bedsensor: |
| - | {{: | + | {{:media:tech:bedsensor: |
| ===Rules=== | ===Rules=== | ||
| Line 134: | Line 134: | ||
| 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. | 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. | ||
| 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 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 automation. In the following example I recorded a night like this. | 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 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 automation. In the following example I recorded a night like this. | ||
| + | |||
| + | ====Programming (ESPHome)==== | ||
| + | The integration into [[https:// | ||
| + | Here the final code for Bedsensor: | ||
| + | |||
| + | <code yaml> | ||
| + | esphome: | ||
| + | name: bedsensor | ||
| + | on_boot: | ||
| + | then: | ||
| + | - delay: 20s | ||
| + | - output.turn_off: | ||
| + | |||
| + | esp8266: | ||
| + | board: esp01_1m | ||
| + | |||
| + | # Enable logging | ||
| + | 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==== | ====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 : | 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? | + | {{ :media:tech:bedsensor: |
| Line 145: | Line 232: | ||
| ====Downloads==== | ====Downloads==== | ||
| - | * {{:tech:bedsensor_BOM.pdf|Bestückungsliste (BOM)}} | + | * {{:media:tech:bedsensor: |
| - | * {{: | + | * {{:media:tech:bedsensor: |
| - | * {{: | + | * {{:media:tech:bedsensor: |
| ====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="" | ||
| + | </ | ||
| + | |||
| + | </ | ||