complete bedscale ui
This commit is contained in:
@@ -34,30 +34,142 @@ wifi:
|
|||||||
|
|
||||||
captive_portal:
|
captive_portal:
|
||||||
|
|
||||||
# sensor:
|
# Web server for calibration UI
|
||||||
# - platform: hx711
|
web_server:
|
||||||
# name: "HX711 Value"
|
port: 80
|
||||||
# dout_pin: D4
|
include_internal: true
|
||||||
# clk_pin: D3
|
|
||||||
# gain: 128
|
|
||||||
# update_interval: 3s
|
|
||||||
|
|
||||||
|
# Global variables for calibration
|
||||||
globals:
|
globals:
|
||||||
- id: constant_weight
|
- id: constant_weight
|
||||||
type: float
|
type: float
|
||||||
|
initial_value: "0.0"
|
||||||
|
- id: use_calibrated
|
||||||
|
type: bool
|
||||||
|
initial_value: "false"
|
||||||
|
- id: cal_raw1
|
||||||
|
type: float
|
||||||
|
initial_value: "2290200.0"
|
||||||
|
- id: cal_value1
|
||||||
|
type: float
|
||||||
|
initial_value: "0.0"
|
||||||
|
- id: cal_raw2
|
||||||
|
type: float
|
||||||
|
initial_value: "2856500.0"
|
||||||
|
- id: cal_value2
|
||||||
|
type: float
|
||||||
|
initial_value: "50.0"
|
||||||
|
|
||||||
|
# Number inputs for calibration values
|
||||||
|
number:
|
||||||
|
- platform: template
|
||||||
|
name: "Calibration Raw Value 1"
|
||||||
|
id: cal_raw1_input
|
||||||
|
min_value: 0
|
||||||
|
max_value: 10000000
|
||||||
|
step: 1
|
||||||
|
mode: box
|
||||||
|
optimistic: true
|
||||||
|
initial_value: 2290200
|
||||||
|
on_value:
|
||||||
|
- lambda: |-
|
||||||
|
id(cal_raw1) = x;
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
name: "Calibration Calibrated Value 1"
|
||||||
|
id: cal_value1_input
|
||||||
|
min_value: -1000
|
||||||
|
max_value: 1000
|
||||||
|
step: 0.1
|
||||||
|
mode: box
|
||||||
|
optimistic: true
|
||||||
|
initial_value: 0
|
||||||
|
on_value:
|
||||||
|
- lambda: |-
|
||||||
|
id(cal_value1) = x;
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
name: "Calibration Raw Value 2"
|
||||||
|
id: cal_raw2_input
|
||||||
|
min_value: 0
|
||||||
|
max_value: 10000000
|
||||||
|
step: 1
|
||||||
|
mode: box
|
||||||
|
optimistic: true
|
||||||
|
initial_value: 2856500
|
||||||
|
on_value:
|
||||||
|
- lambda: |-
|
||||||
|
id(cal_raw2) = x;
|
||||||
|
|
||||||
|
- platform: template
|
||||||
|
name: "Calibration Calibrated Value 2"
|
||||||
|
id: cal_value2_input
|
||||||
|
min_value: -1000
|
||||||
|
max_value: 1000
|
||||||
|
step: 0.1
|
||||||
|
mode: box
|
||||||
|
optimistic: true
|
||||||
|
initial_value: 50
|
||||||
|
on_value:
|
||||||
|
- lambda: |-
|
||||||
|
id(cal_value2) = x;
|
||||||
|
|
||||||
|
# Switch to toggle between raw and calibrated output
|
||||||
|
switch:
|
||||||
|
- platform: template
|
||||||
|
name: "Use Calibrated Output"
|
||||||
|
id: use_calibrated_switch
|
||||||
|
optimistic: true
|
||||||
|
restore_mode: RESTORE_DEFAULT_ON
|
||||||
|
lambda: |-
|
||||||
|
return id(use_calibrated);
|
||||||
|
turn_on_action:
|
||||||
|
- lambda: |-
|
||||||
|
id(use_calibrated) = true;
|
||||||
|
turn_off_action:
|
||||||
|
- lambda: |-
|
||||||
|
id(use_calibrated) = false;
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
|
# Raw HX711 sensor
|
||||||
- platform: hx711
|
- platform: hx711
|
||||||
id: bed
|
id: bed_raw
|
||||||
internal: true
|
internal: true
|
||||||
dout_pin: D4
|
dout_pin: D4
|
||||||
clk_pin: D3
|
clk_pin: D3
|
||||||
update_interval: 3s
|
update_interval: 3s
|
||||||
gain: 128
|
gain: 128
|
||||||
filters:
|
|
||||||
- calibrate_linear:
|
# Display raw value
|
||||||
- 2290200 -> 0
|
- platform: template
|
||||||
- 2856500 -> 50
|
name: "HX711 Raw Value"
|
||||||
|
id: hx711_raw_display
|
||||||
|
update_interval: 3s
|
||||||
|
lambda: "return id(bed_raw).state;"
|
||||||
|
|
||||||
|
# Calibrated sensor using template with dynamic calibration
|
||||||
|
- platform: template
|
||||||
|
name: "Bedscale Calibrated"
|
||||||
|
id: bed_calibrated
|
||||||
|
icon: mdi:weight-kilogram
|
||||||
|
update_interval: 3s
|
||||||
|
unit_of_measurement: kg
|
||||||
|
accuracy_decimals: 2
|
||||||
|
lambda: |-
|
||||||
|
float raw = id(bed_raw).state;
|
||||||
|
float raw1 = id(cal_raw1);
|
||||||
|
float value1 = id(cal_value1);
|
||||||
|
float raw2 = id(cal_raw2);
|
||||||
|
float value2 = id(cal_value2);
|
||||||
|
|
||||||
|
// Linear calibration: y = m*x + b
|
||||||
|
// m = (value2 - value1) / (raw2 - raw1)
|
||||||
|
// b = value1 - m * raw1
|
||||||
|
float m = (raw2 - raw1) != 0.0 ? (value2 - value1) / (raw2 - raw1) : 0.0;
|
||||||
|
float b = value1 - m * raw1;
|
||||||
|
float calibrated = m * raw + b;
|
||||||
|
|
||||||
|
return calibrated;
|
||||||
on_value:
|
on_value:
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
@@ -69,13 +181,20 @@ sensor:
|
|||||||
then:
|
then:
|
||||||
- lambda: "id(constant_weight) = x;"
|
- lambda: "id(constant_weight) = x;"
|
||||||
|
|
||||||
|
# Final output sensor that switches between raw and calibrated
|
||||||
- platform: template
|
- platform: template
|
||||||
name: Bedscale
|
name: "Bedscale"
|
||||||
icon: mdi:weight-kilogram
|
icon: mdi:weight-kilogram
|
||||||
update_interval: 3s
|
update_interval: 3s
|
||||||
unit_of_measurement: kg
|
unit_of_measurement: kg
|
||||||
lambda: "return id(bed).state;"
|
accuracy_decimals: 2
|
||||||
|
lambda: |-
|
||||||
|
if (id(use_calibrated)) {
|
||||||
|
float calibrated = id(bed_calibrated).state;
|
||||||
|
float adjusted = calibrated - id(constant_weight);
|
||||||
|
return adjusted >= 10.0 ? adjusted : 0.0;
|
||||||
|
} else {
|
||||||
|
return NAN;
|
||||||
|
}
|
||||||
filters:
|
filters:
|
||||||
- lambda: "return x - id(constant_weight);"
|
|
||||||
- lambda: "return x >= 10.0 ? x : 0;"
|
|
||||||
- delta: 0.5
|
- delta: 0.5
|
||||||
|
|||||||
Reference in New Issue
Block a user