From 85bcbd166c06286e00f3fffae73b3255e808ccb7 Mon Sep 17 00:00:00 2001 From: Empire Date: Sun, 4 Jun 2023 19:21:53 +0200 Subject: [PATCH] Fix remaining mqtt calculation --- esp32/src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 12f59bd..18751b9 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -1094,10 +1094,14 @@ void plantcontrol() if (waterRawSensor.getCount() > 0) { float remaining = (waterLevelMax.get() - waterRawSensor.getAverage()); + float actualDifference = waterLevelMax.get() - waterLevelMin.get(); + float ratio = remaining/actualDifference; + sensorWater.setProperty("useable").send(String(actualDifference)); if (!isnan(remaining)) { /* measuring the distance from top -> smaller value means more water: */ - sensorWater.setProperty("remaining").send(String(100.0 - (remaining/100))); + sensorWater.setProperty("remaining").send(String(ratio*100)); + } if (!isnan(waterRawSensor.getAverage())) {