Skip to content

Commit

Permalink
Add calibrated sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenpapierski committed Oct 19, 2024
1 parent b00a3e5 commit 8fe9904
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions bed-presence-mk1/sensor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ substitutions:

# Reporting Duration (Max)
# The max amount of time between sensor reports (even if the value hasn't changed)
reporting_duration_max: '60s'
reporting_duration_max: '180s'

binary_sensor:
- platform: template
Expand Down Expand Up @@ -65,6 +65,7 @@ sensor:
pin: ${sensor_gpio}
name: ${sensor_name} Pressure Raw
id: bed_sensor_${sensor_id}_raw
disabled_by_default: true
update_interval: 0.5s
unit_of_measurement: '%'
icon: mdi:gauge
Expand All @@ -80,12 +81,6 @@ sensor:
# - or:
# - delta: ${reporting_delta} # only send if sensor changes by `reporting_delta` (eliminate sensor noise)
# - throttle: ${reporting_duration_max} # but still update every `reporting_duration_max`
# - platform: copy
# source_id: bed_sensor_${sensor_id}
# name: ${sensor_name} Pressure Calibrated
# id: bed_sensor_${sensor_id}_calibrated
# filters:
# - lambda: return float(id(val_unoccupied_${sensor_id})).state+((x/100)*(id(val_occupied_${sensor_id}).state - float(id(val_unoccupied_${sensor_id}).state)));
- platform: copy
source_id: bed_sensor_${sensor_id}_raw
name: ${sensor_name} Pressure
Expand All @@ -107,6 +102,23 @@ sensor:
- or:
- delta: ${reporting_delta} # only send if sensor changes by `reporting_delta` (eliminate sensor noise)
- throttle: ${reporting_duration_max} # but still update every `reporting_duration_max`
- platform: copy
source_id: bed_sensor_${sensor_id}_averaged
name: ${sensor_name} Pressure Calibrated
id: bed_sensor_${sensor_id}_calibrated
filters:
- lambda: |-
float val_cal_top = (x - id(val_unoccupied_${sensor_id}).state) * 100;
float val_cal_bot = id(val_occupied_${sensor_id}).state - id(val_unoccupied_${sensor_id}).state;
float val_calibrated = val_cal_top/val_cal_bot;
if (val_calibrated > 100.0 {
val_calibrated = 100.0;
} else if (val_calibrated < 0.0) {
val_calibrated = 0.0;
}
return val_calibrated;
number:
- platform: template
Expand Down

0 comments on commit 8fe9904

Please sign in to comment.