Skip to content

Commit

Permalink
Allow for expanding the negative range
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenpapierski committed Oct 26, 2024
1 parent 13d8879 commit 3896966
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions bed-presence-mk1/sensor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,20 @@ sensor:
unit_of_measurement: '%'
icon: mdi:gauge
filters:
- calibrate_linear: # scale pulses/minute to 0->100%
- calibrate_linear: # scale pulses/minute to 0->100%
method: least_squares
datapoints:
- ${calibrate_linear_100} -> 100.0 # 6800Hz (sensor shorted/0ohms)
- ${calibrate_linear_0} -> 0.0 # 4600Hz (breakforce/10k)
- ${calibrate_linear_100} -> 100.0 # 6800Hz (sensor shorted/0ohms)
- ${calibrate_linear_0} -> 0.0 # 4600Hz (breakforce/10k)
- sliding_window_moving_average:
window_size: ${averaging_window_samples}
send_every: 1
- clamp:
min_value: 0.0
- lambda: |- # clamp to a min_value of 0 unless expand_negative_range is True
if (x >= 0 || id(expand_negative_range).state) {
return x;
} else {
return 0;
}
- 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`
Expand All @@ -100,14 +104,13 @@ number:
optimistic: true
restore_value: true
initial_value: 0
min_value: 0 # set to -200ish (calculate) and clamp below based on `extend_negative_range`
min_value: -210 # -210 == 0 pulses/minute (expand_negative_range)
max_value: 110
step: 1.0
mode: box
on_value:
then:
- lambda: |- # Update status and trigger
// id(val_unoccupied_status_${sensor_id}).publish_state(x);
id(update_trigger_${sensor_id})->execute();
- platform: template
name: ${sensor_name} Occupied Pressure
Expand All @@ -118,22 +121,21 @@ number:
optimistic: true
restore_value: true
initial_value: 100
min_value: 0
min_value: -210 # -210 == 0 pulses/minute (expand_negative_range)
max_value: 110
step: 1.0
mode: box
on_value:
then:
- lambda: |- # Update status and trigger
// id(val_occupied_status_${sensor_id}).publish_state(x);
id(update_trigger_${sensor_id})->execute();
- platform: template
name: ${sensor_name} Trigger Pressure
id: val_trigger_${sensor_id}
optimistic: true
restore_value: true
initial_value: 50
min_value: 0
min_value: -210 # -210 == 0 pulses/minute (expand_negative_range)
max_value: 110
step: 1.0
mode: box
Expand Down Expand Up @@ -165,6 +167,13 @@ button:
# round to 2 decimal places
value: !lambda return round(id(bed_sensor_${sensor_id}).state * 100)/100.0;

switch:
- platform: template
name: "Clamp Negative Range"
id: expand_negative_range
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF

script:
- id: update_trigger_${sensor_id}
mode: queued
Expand Down

0 comments on commit 3896966

Please sign in to comment.