From 0b90fb7fd27546e047817969b8a653b7c1e6b7e1 Mon Sep 17 00:00:00 2001 From: Jan Grewe <jan@faked.org> Date: Sun, 10 Mar 2024 23:16:20 +0100 Subject: [PATCH] fix pH calculation --- packages/water_ph.yaml | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/packages/water_ph.yaml b/packages/water_ph.yaml index c774d1d..b38ffba 100644 --- a/packages/water_ph.yaml +++ b/packages/water_ph.yaml @@ -13,10 +13,6 @@ globals: type: float restore_value: yes initial_value: ${ph700_raw} - - id: ph686_raw # raw V value from probe using pH 6.86 calibration solution. - type: float - restore_value: yes - initial_value: ${ph686_raw} - id: ph918_raw # raw V value from probe using pH 9.18 calibration solution. type: float restore_value: yes @@ -40,12 +36,6 @@ sensor: # update_interval: 5s # lambda: !lambda return id(ph400_raw); # - platform: template - # name: "pH: 6.86 Calibration Value" - # unit_of_measurement: "V" - # accuracy_decimals: 5 - # update_interval: 5s - # lambda: !lambda return id(ph686_raw); - # - platform: template # name: "pH: 7.00 Calibration Value" # unit_of_measurement: "V" # accuracy_decimals: 5 @@ -65,20 +55,22 @@ sensor: update_interval: 5s lambda: |- float slope; + float intersect; if (id(ph_slope_points).active_index() == 1) { - slope = (id(ph918_raw) - id(ph400_raw)) / (9.18 - 4.00); + slope = (9.18 - 4.0) / ((id(ph918_raw)-1.5) / 3.0 - (id(ph400_raw)-1.5) / 3.0); + intersect = 9.18 - slope * (id(ph918_raw)-1.5) / 3.0; } else { - slope = (id(ph700_raw) - id(ph400_raw)) / (7.00 - 4.00); + slope = (7.0 - 4.0) / ((id(ph700_raw)-1.5) / 3.0 - (id(ph400_raw)-1.5) / 3.0); + intersect = 7.0 - slope * (id(ph700_raw)-1.5) / 3.0; } - float intersect = id(ph686_raw) - (slope * 6.86); - return (id(analog_ph).state - intersect) / slope; + return slope * (id(analog_ph).state-1.5) / 3.0 + intersect; select: - platform: template id: ph_slope_points name: "pH: Calibration Points" options: ["4.00/7.00", "4.00/9.18"] - initial_option: "4.00/7.00" + initial_option: "4.00/9.18" optimistic: true restore_value: true @@ -89,12 +81,6 @@ button: - globals.set: id: ph400_raw value: !lambda return id(analog_ph).state; - - platform: template - name: "pH: Calibrate 6.86" - on_press: - - globals.set: - id: ph686_raw - value: !lambda return id(analog_ph).state; - platform: template name: "pH: Calibrate 7.00" on_press: -- GitLab