mirror of
https://github.com/CeeWeasel/fresh-home.git
synced 2026-08-10 11:00:14 -04:00
371 lines
11 KiB
YAML
371 lines
11 KiB
YAML
globals:
|
|
- id: left_initial_zero
|
|
type: float
|
|
restore_value: yes
|
|
# NOTE: make sure to align this value to the one used in "calibrate_linear" below!
|
|
initial_value: ${left_loadcell_zero}
|
|
|
|
- id: right_initial_zero
|
|
type: float
|
|
restore_value: yes
|
|
# NOTE: make sure to align this value to the one used in "calibrate_linear" below!
|
|
initial_value: ${right_loadcell_zero}
|
|
|
|
- id: left_auto_tare_difference
|
|
type: float
|
|
restore_value: yes
|
|
initial_value: '0'
|
|
|
|
- id: right_auto_tare_difference
|
|
type: float
|
|
restore_value: yes
|
|
initial_value: '0'
|
|
|
|
- id: left_manual_tare_flag
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: 'false'
|
|
|
|
- id: right_manual_tare_flag
|
|
type: bool
|
|
restore_value: no
|
|
initial_value: 'false'
|
|
|
|
- id: auto_tare_enabled
|
|
type: bool
|
|
restore_value: yes
|
|
initial_value: 'true'
|
|
|
|
- id: occupancy_forced
|
|
type: bool
|
|
restore_value: yes
|
|
initial_value: 'false'
|
|
|
|
sensor:
|
|
- platform: homeassistant
|
|
entity_id: input_number.${entity_name}_left_occupied
|
|
internal: true
|
|
id: left_occupied
|
|
|
|
- platform: homeassistant
|
|
entity_id: input_number.${entity_name}_right_occupied
|
|
internal: true
|
|
id: right_occupied
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Left Raw Value"
|
|
lambda: |-
|
|
return id(hx711_left_value_raw).raw_state;
|
|
unit_of_measurement: w
|
|
update_interval: 1s
|
|
state_class: measurement
|
|
disabled_by_default: true
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Right Raw Value"
|
|
lambda: |-
|
|
return id(hx711_right_value_raw).raw_state;
|
|
unit_of_measurement: w
|
|
update_interval: 1s
|
|
state_class: measurement
|
|
disabled_by_default: true
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Left Auto Tare"
|
|
lambda: |-
|
|
return id(left_auto_tare_difference);
|
|
unit_of_measurement: w
|
|
update_interval: 1s
|
|
state_class: measurement
|
|
disabled_by_default: true
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Right Auto Tare"
|
|
lambda: |-
|
|
return id(right_auto_tare_difference);
|
|
unit_of_measurement: w
|
|
update_interval: 1s
|
|
state_class: measurement
|
|
disabled_by_default: true
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Left Initial Zero"
|
|
lambda: |-
|
|
return id(left_initial_zero);
|
|
unit_of_measurement: w
|
|
state_class: measurement
|
|
update_interval: 60s
|
|
disabled_by_default: true
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Right Initial Zero"
|
|
lambda: |-
|
|
return id(right_initial_zero);
|
|
unit_of_measurement: w
|
|
state_class: measurement
|
|
update_interval: 60s
|
|
disabled_by_default: true
|
|
|
|
# Left RAW Scale input
|
|
- platform: hx711
|
|
id: hx711_left_value_raw
|
|
internal: True
|
|
dout_pin: ${left_dout_pin}
|
|
clk_pin: ${left_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: 3
|
|
send_every: 1
|
|
on_value:
|
|
then:
|
|
- sensor.template.publish:
|
|
id: hx711_left_value
|
|
state: !lambda 'return id(hx711_left_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_left_value).state < 10.0;'
|
|
then:
|
|
- if:
|
|
condition:
|
|
# current raw scale value is below expected zero value
|
|
- lambda: 'return id(hx711_left_value_raw).state < (id(left_initial_zero) - id(left_auto_tare_difference));'
|
|
then:
|
|
# INcrease Auto-Tare offset to slowly align real zero value with expected zero value
|
|
- lambda: |-
|
|
id(left_auto_tare_difference) += 10;
|
|
else:
|
|
# DEcrease Auto-Tare offset to slowly align real zero value with expected zero value
|
|
- lambda: |-
|
|
id(left_auto_tare_difference) -= 10;
|
|
|
|
# Right RAW Scale input
|
|
- platform: hx711
|
|
id: hx711_right_value_raw
|
|
internal: True
|
|
dout_pin: ${right_dout_pin}
|
|
clk_pin: ${right_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: 3
|
|
send_every: 1
|
|
on_value:
|
|
then:
|
|
- sensor.template.publish:
|
|
id: hx711_right_value
|
|
state: !lambda 'return id(hx711_right_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_right_value).state < 10.0;'
|
|
then:
|
|
- if:
|
|
condition:
|
|
# current raw scale value is below expected zero value
|
|
- lambda: 'return id(hx711_right_value_raw).state < (id(right_initial_zero) - id(right_auto_tare_difference));'
|
|
then:
|
|
# INcrease Auto-Tare offset to slowly align real zero value with expected zero value
|
|
- lambda: |-
|
|
id(right_auto_tare_difference) += 10;
|
|
else:
|
|
# DEcrease Auto-Tare offset to slowly align real zero value with expected zero value
|
|
- lambda: |-
|
|
id(right_auto_tare_difference) -= 10;
|
|
|
|
# Left Mapped value to lbs
|
|
- platform: template
|
|
id: hx711_left_value
|
|
name: "${friendly_name} Left Weight"
|
|
internal: False
|
|
filters:
|
|
# apply auto_tare difference
|
|
- lambda: 'return x + id(left_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
|
|
- ${left_loadcell_zero} -> 0
|
|
- ${left_loadcell_load} -> ${left_loadcell_weight}
|
|
# map values below 0.1 to 0 (to decrease value changes due to random fluctuation)
|
|
- lambda: |-
|
|
if (x <= 0.1 || id(hx711_left_error).state) {
|
|
return 0.0;
|
|
} else {
|
|
return x;
|
|
}
|
|
unit_of_measurement: lbs
|
|
accuracy_decimals: 0
|
|
update_interval: 0.5s
|
|
state_class: measurement
|
|
|
|
# Right Mapped value to lbs
|
|
- platform: template
|
|
id: hx711_right_value
|
|
name: "${friendly_name} Right Weight"
|
|
internal: False
|
|
filters:
|
|
# apply auto_tare difference
|
|
- lambda: 'return x + id(right_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
|
|
- ${right_loadcell_zero} -> 0
|
|
- ${right_loadcell_load} -> ${right_loadcell_weight}
|
|
# map values below 0.1 to 0 (to decrease value changes due to random fluctuation)
|
|
- lambda: |-
|
|
if (x <= 0.1 || id(hx711_right_error).state) {
|
|
return 0.0;
|
|
} else {
|
|
return x;
|
|
}
|
|
unit_of_measurement: lbs
|
|
accuracy_decimals: 0
|
|
update_interval: 0.5s
|
|
state_class: measurement
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Combined"
|
|
id: combined_weight
|
|
update_interval: 1s
|
|
unit_of_measurement: lbs
|
|
state_class: measurement
|
|
lambda: |-
|
|
return id(hx711_left_value).state + id(hx711_right_value).state;
|
|
|
|
binary_sensor:
|
|
- platform: template
|
|
name: "${friendly_name} Left Occupied"
|
|
id: is_left_occupied
|
|
lambda: |-
|
|
if (
|
|
id(hx711_left_value).state >= id(left_occupied).state
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Right Occupied"
|
|
id: is_right_occupied
|
|
lambda: |-
|
|
if (
|
|
id(hx711_right_value).state >= id(right_occupied).state
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Occupied"
|
|
lambda: |-
|
|
if ( id(is_left_occupied).state || id(is_right_occupied).state )
|
|
{
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Left HX711 Error"
|
|
id: hx711_left_error
|
|
device_class: problem
|
|
lambda: |-
|
|
if (
|
|
id(hx711_left_value_raw).raw_state > 8388000.0 || id(hx711_left_value_raw).raw_state < -8388000.0
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
- platform: template
|
|
name: "${friendly_name} Right HX711 Error"
|
|
id: hx711_right_error
|
|
device_class: problem
|
|
lambda: |-
|
|
if (
|
|
id(hx711_right_value_raw).raw_state > 8388000.0 || id(hx711_right_value_raw).raw_state < -8388000.0
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
- platform: template
|
|
name: "${friendly_name} HX711 Error"
|
|
id: hx711_error
|
|
device_class: problem
|
|
lambda: |-
|
|
if (
|
|
id(hx711_left_error).state || id(hx711_right_error).state
|
|
) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
switch:
|
|
- platform: template
|
|
id: auto_tare
|
|
name: "${friendly_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;
|
|
|
|
- platform: template
|
|
id: left_manual_tare
|
|
name: "${friendly_name} Left Manual Tare"
|
|
lambda: |-
|
|
return id(left_manual_tare_flag);
|
|
turn_on_action:
|
|
- lambda: |-
|
|
id(left_auto_tare_difference) = id(left_initial_zero) - id(hx711_left_value_raw).state;
|
|
- switch.turn_off: left_manual_tare
|
|
turn_off_action:
|
|
- lambda: |-
|
|
id(left_manual_tare_flag) = false;
|
|
|
|
- platform: template
|
|
id: right_manual_tare
|
|
name: "${friendly_name} Right Manual Tare"
|
|
lambda: |-
|
|
return id(right_manual_tare_flag);
|
|
turn_on_action:
|
|
- lambda: |-
|
|
id(right_auto_tare_difference) = id(right_initial_zero) - id(hx711_right_value_raw).state;
|
|
- switch.turn_off: right_manual_tare
|
|
turn_off_action:
|
|
- lambda: |-
|
|
id(right_manual_tare_flag) = false; |