Skip to content

Commit

Permalink
Bed Presence Mk1 - 2024.10.0 Release (#28)
Browse files Browse the repository at this point in the history
# Eliminate DB bloat, improve sensor response, add lots of options for customization.
This is the first firmware update for Bed Presence Mk1. It will be the `2024.10.0` release and be available OTA to managed devices. Devices already imported into the ESPHome Dashboard will need to be recompiled to get access to the new features.

## Eliminate DB Bloat
The default delta threshold and reporting interval have been updated so that the sensor only reports new values when something actually changes. This will decrease the update frequency dramatically and eliminate bloating the database.

## Improved Sensor Response
The sensor now uses a window average by default. This helps smooth out any quick movements, while also slightly improving the response time for getting out of bed.

## Calibrated Sensor
If you're annoyed by a different response from each side of your bed, the `Calibrated Sensor` is for you. This is an additional sensor that scales your raw pressure values between the `Unoccupied Pressure` and `Occupied Pressure`.

## Status Sensor
Added a binary status sensor to expose the device's connectivity state.

## Option to Use Full Range
By default, Pressure [Right/Left] is focused on the most sensitive zone of the pressure sensor (Full Range = Off). This should perform well for most setups. By turning on Full Range, you can expand it to use the full range of the sensor. Consider turning ON Full Range if slight movements in bed quickly drop the sensor value to zero, causing frequent false negatives.

## Lots of Customization
If you import the device into the ESPHome Dashboard, there are now lots more substitutions within the package to customize behavior.

See https://github.com/ElevatedSensors/sensor-configs/blob/main/bed-presence-mk1/sensor.yaml for substitution descriptions.

substitutions:
- trigger_percentile: '0.75'
- averaging_window_samples: '5'
- fast_delayed_on: '0ms'
- fast_delayed_off: '0ms'
- standard_delayed_on: '0s'
- standard_delayed_off: '1s'
- reporting_delta: '1.0'
- reporting_interval_max: '180s'
- calibrate_100: '408000'
- calibrate_0: '276000'
  • Loading branch information
stephenpapierski authored Oct 28, 2024
1 parent 9f87514 commit ee13dd9
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 193 deletions.
2 changes: 1 addition & 1 deletion bed-presence-mk1.factory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ packages:
esphome:
project:
name: ElevatedSensors.BedPresenceMk1
version: 2024.9.0
version: 2024.10.0

# Allow ESPHome Adoption
dashboard_import:
Expand Down
39 changes: 18 additions & 21 deletions bed-presence-mk1.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
substitutions:
# Calibrate Trigger Percentile
# This controls how the trigger threshold is set during calibration. During calibration, the unoccupied and occupied
# pressure values are determined. This is the percentage of the difference between those values required to trigger
# the "occupied" state.
# - 0.75 Requires 75% of the occupied pressure to trigger (Default)
# - 0.50 Set trigger exactly in the middle of unoccupied and occupied pressures
# - 0.25 More sensitive, likely to be triggered by partner
trigger_percentile: '0.75'

# Fast Sensor Delay
# This controls how long the "Fast" sensor must register its value before updating. Without any delay, the sensor
# will register frequent fall negatives as you shift in bed.
# - 2s Same response as standard sensor
# - 500ms Good starting point for getting speed without too many false negatives (Default)
# - 0ms No delay, expect frequent false negatives
fast_delayed_off: '500ms'

esphome:
name: bed-presence
friendly_name: Bed Presence
min_version: 2024.6.0
name_add_mac_suffix: true
project:
name: ElevatedSensors.BedPresenceMk1
version: "DIY"
version: DIY
platformio_options:
board_build.flash_mode: dio # dio flash_mode fixes issue where board bootloops using esp-idf
board_build.flash_mode: dio

esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf # using arduino causes board to reset multiple times/day
type: esp-idf

# Enable logging
logger:
Expand Down Expand Up @@ -58,3 +40,18 @@ packages:
ref: main
files: ['bed-presence-mk1/base.yaml']
refresh: 1s

# See https://github.com/ElevatedSensors/sensor-configs/blob/main/bed-presence-mk1/sensor.yaml for a detailed
# description of available substitutions.
#
# substitutions:
# trigger_percentile: '0.75'
# averaging_window_samples: '5'
# fast_delayed_on: '0ms'
# fast_delayed_off: '0ms'
# standard_delayed_on: '0s'
# standard_delayed_off: '1s'
# reporting_delta: '1.0'
# reporting_interval_max: '180s'
# calibrate_100: '408000'
# calibrate_0: '276000'
107 changes: 60 additions & 47 deletions bed-presence-mk1/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,72 @@ packages:
sensor_gpio: GPIO20

sensor:
- platform: wifi_signal # Reports the WiFi signal strength in dB
name: WiFi Signal dB
id: wifi_signal_db
update_interval: 60s
- platform: wifi_signal # Reports the WiFi signal strength in dB
name: WiFi Signal dB
id: wifi_signal_db
update_interval: 60s

- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi Signal Percent"
id: wifi_signal_percent
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
device_class: ""
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: WiFi Signal Percent
id: wifi_signal_percent
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: '%'
entity_category: diagnostic
device_class: ""

- platform: uptime
type: seconds
id: bed_presence_uptime
name: "Uptime"
- platform: uptime
type: seconds
id: bed_presence_uptime
name: Uptime

binary_sensor:
- platform: template
name: Bed Occupied Both (Fast)
id: bed_occupied_both_fast
device_class: occupancy
icon: mdi:bunk-bed
disabled_by_default: true
lambda: return id(bed_occupied_left_fast).state && id(bed_occupied_right_fast).state;
- platform: template
name: Bed Occupied Both (Fast)
id: bed_occupied_both_fast
device_class: occupancy
icon: mdi:bunk-bed
disabled_by_default: true
lambda: return id(bed_occupied_left_fast).state && id(bed_occupied_right_fast).state;

- platform: template
name: Bed Occupied Either (Fast)
id: bed_occupied_either_fast
device_class: occupancy
icon: mdi:bunk-bed
disabled_by_default: true
lambda: return id(bed_occupied_left_fast).state || id(bed_occupied_right_fast).state;
- platform: template
name: Bed Occupied Either (Fast)
id: bed_occupied_either_fast
device_class: occupancy
icon: mdi:bunk-bed
disabled_by_default: true
lambda: return id(bed_occupied_left_fast).state || id(bed_occupied_right_fast).state;

- platform: template
name: Bed Occupied Both
id: bed_occupied_both
device_class: occupancy
icon: mdi:bunk-bed
lambda: return id(bed_occupied_left).state && id(bed_occupied_right).state;
- platform: template
name: Bed Occupied Both
id: bed_occupied_both
device_class: occupancy
icon: mdi:bunk-bed
lambda: return id(bed_occupied_left).state && id(bed_occupied_right).state;

- platform: template
name: Bed Occupied Either
id: bed_occupied_either
device_class: occupancy
icon: mdi:bunk-bed
lambda: return id(bed_occupied_left).state || id(bed_occupied_right).state;
- platform: template
name: Bed Occupied Either
id: bed_occupied_either
device_class: occupancy
icon: mdi:bunk-bed
lambda: return id(bed_occupied_left).state || id(bed_occupied_right).state;

- platform: status
id: bed_presence_status
name: Status

button:
- platform: restart
name: Restart
id: btn_restart
entity_category: "diagnostic"
- platform: restart
name: Restart
id: btn_restart
entity_category: diagnostic

switch:
- platform: template
name: Full Range
id: full_range
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
entity_category: config
icon: mdi:arrow-expand
Loading

0 comments on commit ee13dd9

Please sign in to comment.