Skip to content

Commit

Permalink
Adding manual calibration values so that the Muino reader also work w…
Browse files Browse the repository at this point in the history
…hen alot of noise is present
  • Loading branch information
martijnED committed Jan 12, 2025
1 parent 46445e3 commit 2013fe6
Showing 1 changed file with 89 additions and 4 deletions.
93 changes: 89 additions & 4 deletions muino-water-meter-esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ interval:
# - interval: 10s # Check every 10 seconds to reduce load, adjust as needed
# then:
# - lambda: |-

# - interval: 1s
# then:
# # - component.update: report_liters
Expand Down Expand Up @@ -112,6 +111,20 @@ switch:
- switch.turn_on: fastupdate
turn_off_action:
- switch.turn_off: fastupdate
# for manual calibration or auto
- platform: template
id: calibration_mode
name: "Manual Calibration"
icon: "mdi:tune-vertical"
optimistic: true
restore_mode: RESTORE_DEFAULT_ON # <--- important
turn_on_action:
- lambda: |-
id(manual_calibration) = true;
turn_off_action:
- lambda: |-
id(manual_calibration) = false;
text_sensor:
- platform: template
name: "debug_JSON"
Expand Down Expand Up @@ -424,9 +437,18 @@ sensor:
id(max_b)= max_average(id(max_b), b, alpha_cor);
id(max_c)= max_average(id(max_c), c, alpha_cor);
a -= (id(min_a) + id(max_a)) >> 1;
b -= (id(min_b) + id(max_b)) >> 1;
c -= (id(min_c) + id(max_c)) >> 1;
if (id(manual_calibration)) {
// Manual offsets
a -= id(manual_offset_a);
b -= id(manual_offset_b);
c -= id(manual_offset_c);
} else {
// Auto-calibration offsets
a -= (id(min_a) + id(max_a)) >> 1;
b -= (id(min_b) + id(max_b)) >> 1;
c -= (id(min_c) + id(max_c)) >> 1;
}
short pn[5];
if (id(phase) & 1)
pn[0] = a + a - b - c, pn[1] = b + b - a - c,
Expand Down Expand Up @@ -497,6 +519,69 @@ globals:
type: int
initial_value: "5"

# Switch that toggles between auto-calibration and manual calibration
- id: manual_calibration
type: bool
restore_value: yes # <--- important
initial_value: "false"

# Manual offsets for a, b, c
- id: manual_offset_a
type: int
initial_value: "0"
- id: manual_offset_b
type: int
initial_value: "0"
- id: manual_offset_c
type: int
initial_value: "0"

number:
- platform: template
id: offset_a_number
name: "Offset A (0-3300)"
restore_value: true # <--- important
initial_value: 0
min_value: 0
max_value: 3300
step: 1
set_action:
- lambda: |-
id(manual_offset_a) = (int) x; // Set the global
on_value:
lambda: |-
return id(manual_offset_a); // Return the global
- platform: template
id: offset_b_number
name: "Offset B (0-3300)"
restore_value: true # <--- important
initial_value: 0
min_value: 0
max_value: 3300
step: 1
set_action:
- lambda: |-
id(manual_offset_b) = (int) x;
on_value:
lambda: |-
return id(manual_offset_b); // Return the global
- platform: template
id: offset_c_number
name: "Offset C (0-3300)"
restore_value: true # <--- important
initial_value: 0
min_value: 0
max_value: 3300
step: 1
set_action:
- lambda: |-
id(manual_offset_c) = (int) x;
on_value:
lambda: |-
return id(manual_offset_c); // Return the global
# Make sure logging is correct for solving platform IO bugs
logger:
hardware_uart: USB_SERIAL_JTAG
Expand Down

0 comments on commit 2013fe6

Please sign in to comment.