mirror of
https://github.com/CeeWeasel/fresh-home.git
synced 2026-08-09 18:40:14 -04:00
75fb9c2ab8
finally fixing hvac-multisensor. All of this was caused by the display switch referenced the display while it wasn't plugged in. Updated code to check for the existence first.
192 lines
5.2 KiB
YAML
192 lines
5.2 KiB
YAML
globals:
|
|
- id: initial_zero
|
|
type: float
|
|
restore_value: yes
|
|
# NOTE: make sure to align this value to the one used in "calibrate_linear" below!
|
|
initial_value: ${loadcell_zero}
|
|
|
|
- id: auto_tare_enabled
|
|
type: bool
|
|
restore_value: yes
|
|
initial_value: 'true'
|
|
|
|
- id: auto_tare_difference
|
|
type: float
|
|
restore_value: yes
|
|
initial_value: '0'
|
|
|
|
- id: occupancy_forced
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: 'false'
|
|
|
|
sensor:
|
|
- platform: homeassistant
|
|
entity_id: input_number.${entity_name}_occupied
|
|
internal: true
|
|
id: occupied
|
|
|
|
- platform: template
|
|
name: "Raw Value"
|
|
lambda: |-
|
|
return id(hx711_value_raw).raw_state;
|
|
unit_of_measurement: w
|
|
update_interval: 1s
|
|
state_class: measurement
|
|
|
|
- platform: template
|
|
name: "Auto Tare"
|
|
lambda: |-
|
|
return id(auto_tare_difference);
|
|
unit_of_measurement: w
|
|
update_interval: 1s
|
|
state_class: measurement
|
|
|
|
- platform: template
|
|
name: "Initial Zero"
|
|
lambda: |-
|
|
return id(initial_zero);
|
|
unit_of_measurement: w
|
|
state_class: measurement
|
|
update_interval: 60s
|
|
|
|
# RAW Scale input
|
|
- platform: hx711
|
|
id: hx711_value_raw
|
|
internal: True
|
|
dout_pin: ${dout_pin}
|
|
clk_pin: ${clk_pin}
|
|
gain: 128
|
|
accuracy_decimals: 3
|
|
update_interval: 0.2s
|
|
filters:
|
|
- lambda: !lambda |-
|
|
if (x > 8388000.0) return {};
|
|
if (x < -8388000.0) return {};
|
|
return x;
|
|
- sliding_window_moving_average:
|
|
window_size: 15
|
|
send_every: 15
|
|
on_value:
|
|
then:
|
|
- sensor.template.publish:
|
|
id: hx711_value
|
|
state: !lambda 'return id(hx711_value_raw).state;'
|
|
- if:
|
|
condition:
|
|
and:
|
|
- lambda: 'return id(auto_tare_enabled);'
|
|
# current smart scale value is below approx. 10KG (raw value -375000 aka nobody is standing on the scale
|
|
- lambda: 'return id(hx711_value).state < 10.0;'
|
|
then:
|
|
- if:
|
|
condition:
|
|
# current raw scale value is below expected zero value
|
|
- lambda: 'return id(hx711_value_raw).state < (id(initial_zero) - id(auto_tare_difference));'
|
|
then:
|
|
# INcrease Auto-Tare offset to slowly align real zero value with expected zero value
|
|
- lambda: |-
|
|
id(auto_tare_difference) += 10;
|
|
else:
|
|
# DEcrease Auto-Tare offset to slowly align real zero value with expected zero value
|
|
- lambda: |-
|
|
id(auto_tare_difference) -= 10;
|
|
|
|
# Mapped value to lbs
|
|
- platform: template
|
|
id: hx711_value
|
|
name: "Weight"
|
|
internal: False
|
|
filters:
|
|
# apply auto_tare difference
|
|
- lambda: 'return x + id(auto_tare_difference);'
|
|
# apply rough calibration
|
|
- calibrate_linear:
|
|
# retrieve these values by evaluating the raw values with loads of known mass.
|
|
# note that a bigger difference between measurements usually results in higher resolution,
|
|
# so measure 0 Kg and the highest known mass you have (like f.ex. your own weight, measured by a normal scale with good accuracy)
|
|
# 1221300 difference between the two
|
|
# was at -23800 for the longest time
|
|
- ${loadcell_zero} -> 0
|
|
- ${loadcell_load} -> ${loadcell_weight}
|
|
# map values below 0.1 to 0 (to decrease value changes due to random fluctuation)
|
|
- lambda: |-
|
|
if (x <= 0.1 || id(hx711_error).state) {
|
|
return 0.0;
|
|
} else {
|
|
return x;
|
|
}
|
|
|
|
unit_of_measurement: lbs
|
|
accuracy_decimals: 0
|
|
update_interval: 0.5s
|
|
state_class: measurement
|
|
|
|
binary_sensor:
|
|
- platform: template
|
|
device_class: occupancy
|
|
name: "Occupied"
|
|
icon: mdi:bed
|
|
lambda: |-
|
|
if (
|
|
id(hx711_value).state >= id(occupied).state || id(occupancy_forced)
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
- platform: template
|
|
name: "HX711 Error"
|
|
id: hx711_error
|
|
device_class: problem
|
|
lambda: |-
|
|
if (
|
|
id(hx711_value_raw).raw_state > 8388000.0 || id(hx711_value_raw).raw_state < -8388000.0
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
switch:
|
|
- platform: template
|
|
id: force_occupancy
|
|
name: "Force Occupancy"
|
|
lambda: |-
|
|
return id(occupancy_forced);
|
|
turn_on_action:
|
|
- lambda: |-
|
|
id(occupancy_forced) = true;
|
|
turn_off_action:
|
|
- lambda: |-
|
|
id(occupancy_forced) = false;
|
|
|
|
- platform: template
|
|
id: auto_tare
|
|
# optimistic: true
|
|
# assumed_state: true
|
|
name: "Auto Tare"
|
|
lambda: |-
|
|
return id(auto_tare_enabled);
|
|
turn_on_action:
|
|
- lambda: |-
|
|
id(auto_tare_enabled) = true;
|
|
turn_off_action:
|
|
- lambda: |-
|
|
id(auto_tare_enabled) = false;
|
|
|
|
button:
|
|
- platform: template
|
|
id: manual_tare
|
|
name: "Manual Tare"
|
|
on_press:
|
|
- lambda: |-
|
|
id(auto_tare_difference) = id(initial_zero) - id(hx711_value_raw).state;
|
|
|
|
- platform: template
|
|
id: reset_tare
|
|
name: "Reset Tare"
|
|
on_press:
|
|
- lambda: |-
|
|
id(auto_tare_difference) = 0; |