diff --git a/packages/ads1115.yaml b/packages/ads1115.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7f6ac90318f8ed8c7069aefa11c05ed7576bcdfa --- /dev/null +++ b/packages/ads1115.yaml @@ -0,0 +1,2 @@ +ads1115: + - address: 0x48 diff --git a/packages/ec.yaml b/packages/ec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..39494b9ffe1d2703639a5dc720ae6a8cbde489df --- /dev/null +++ b/packages/ec.yaml @@ -0,0 +1,61 @@ +substitutions: + ec_k: '0.992' + # ec_ref & ec_res2: https://github.com/DFRobot/DFRobot_EC/blob/master/DFRobot_EC.cpp#L28 // https://www.dfrobot.com/forum/topic/28708 + ec_ref: '200.0' + ec_res2: '820.0' + +globals: + - id: ec_k # raw V value from probe using EC 1.1413 calibration solution. + type: float + restore_value: yes + initial_value: ${ec_k} + +sensor: + - platform: ads1115 + id: analog_ec + name: "EC: Analog Voltage" + multiplexer: 'A1_GND' + gain: 4.096 # max: 3.4V + update_interval: 5s + accuracy_decimals: 5 + <<: !include filter.yaml + - platform: template + name: "EC: K Value" + unit_of_measurement: "K" + accuracy_decimals: 5 + update_interval: 5s + lambda: !lambda return id(ec_k); + - platform: template + name: "EC:" + id: ec + unit_of_measurement: "mS" + accuracy_decimals: 3 + update_interval: 5s + lambda: |- + float water_temperature = 20.0; + float ec_raw = id(analog_ec).state / ${ec_res2} / ${ec_ref} * 1000.0 * 1000.0; + float ec = ec_raw * id(ec_k); + return ec / (1 + (0.0185 * (water_temperature - 25))); // return with temperature correction + +button: + - platform: template + name: "EC: Calibrate" + on_press: + - then: + - lambda: |- + float water_temperature = 20.0; + float buffer_solution = -1; + if (id(ec).state > 0.9 && id(ec).state < 1.9) { // recognize 1.413us/cm buffer solution + ESP_LOGI("ec", "Calibrating EC with 1.413 mS/cm solution"); + buffer_solution = 1.413 * (1.0 + 0.0185 * (water_temperature - 25.0)); + } else if (id(ec).state > 9 && id(ec).state < 16.8) { // recognize 12.88ms/cm buffer solution + buffer_solution = 12.88 * (1.0 + 0.0185 * (water_temperature - 25.0)); + ESP_LOGI("ec", "Calibrating EC with 12.88 mS/cm solution"); + } else { + ESP_LOGI("ec", "Not calibrating EC, probe not in 1.413 or 12.88 mS/cm solution"); + } + if(buffer_solution != -1 ) { + float k = ${ec_res2} * ${ec_ref} * buffer_solution / 1000.0 / 1000.0 / id(analog_ec).state; + ESP_LOGI("ec", "New K value: %f", k); + id(ec_k) = k; + } diff --git a/packages/ph.yaml b/packages/ph.yaml new file mode 100644 index 0000000000000000000000000000000000000000..358d1d2c240c424ebf950b18a45d7a164b19d7b9 --- /dev/null +++ b/packages/ph.yaml @@ -0,0 +1,107 @@ +substitutions: + ph400_raw: '2.068' + ph686_raw: '1.574' + ph700_raw: '1.555' + ph918_raw: '1.215' + +globals: + - id: ph400_raw # raw V value from probe using pH 4.0 calibration solution. + type: float + restore_value: yes + initial_value: ${ph400_raw} + - id: ph700_raw # raw V value from probe using pH 7.0 calibration solution. + 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 + initial_value: ${ph918_raw} + +sensor: + - platform: ads1115 + id: analog_ph + name: "pH: Analog Voltage" + multiplexer: 'A0_GND' + gain: 4.096 # max: 3.0V + update_interval: 5s + accuracy_decimals: 5 + <<: !include filter.yaml + - platform: template + name: "pH: 4.00 Calibration Value" + unit_of_measurement: "V" + accuracy_decimals: 5 + 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 + update_interval: 5s + lambda: !lambda return id(ph700_raw); + - platform: template + name: "pH: 9.18 Calibration Value" + unit_of_measurement: "V" + accuracy_decimals: 5 + update_interval: 5s + lambda: !lambda return id(ph918_raw); + - platform: template + name: "pH:" + id: ph + unit_of_measurement: "pH" + accuracy_decimals: 2 + update_interval: 5s + lambda: |- + float slope; + if (id(ph_slope_points).active_index() == 1) { + slope = (id(ph918_raw) - id(ph400_raw)) / (9.18 - 4.00); + } else { + slope = (id(ph700_raw) - id(ph400_raw)) / (7.00 - 4.00); + } + float intersect = id(ph686_raw) - (slope * 6.86); + return (id(analog_ph).state - intersect) / slope; + +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" + optimistic: true + restore_value: true + +button: + - platform: template + name: "pH: Calibrate 4.00" + on_press: + - 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: + - globals.set: + id: ph700_raw + value: !lambda return id(analog_ph).state; + - platform: template + name: "pH: Calibrate 9.18" + on_press: + - globals.set: + id: ph918_raw + value: !lambda return id(analog_ph).state;