Calculate water percentage below 30 percent

This commit is contained in:
Ollo 2024-02-24 16:21:39 +01:00
parent 4f7e57988b
commit f8629586f8

View File

@ -1067,9 +1067,21 @@ void plantcontrol()
if (!isnan(waterRawSensor.getAverage()))
{
/* measuring the distance from top -> smaller value means more water: */
sensorWater.setProperty("remaining").send(String(100.0 * (waterRawSensor.getAverage()/ESP_ADC_MAX)));
long averageWater = waterRawSensor.getAverage();
if (averageWater < ESP_ADC_MAX) {
long percentage = (averageWater * averageWater);
percentage = percentage / 570000;
/* Add offset */
if (percentage > 0)
{
percentage += 4;
}
sensorWater.setProperty("remaining").send(String(percentage));
} else {
sensorWater.setProperty("remaining").send(String("100"));
}
sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage()));
sensorWater.setProperty("raw").send(String(waterRawSensor.getAverage()));
}
}
sensorLipo.setProperty("percent").send(String(100 * mBatteryVoltage / VOLT_MAX_BATT));