// seems to be reading *lower* than the output by about 0.1°C, so we
// end up pumping heat into the sky, especially in the evenings. So
// we now make the correction in the opposite direction.
- intemp += 0.1;
-
- if (outtemp == intemp)
- return;
+ //
+ // Those tests with a single on/off threshold informed the 'off at 0,
+ // on at +0.3°C' logic we now have below.
time_t now = ::time(NULL);
- boolean want_state = outtemp > intemp;
+ boolean cur_state = id(valve_output).state;
+ boolean want_state = cur_state;
+ if (cur_state) {
+ // Only turn off if the output has got all the way down below the input temp
+ want_state = outtemp >= intemp;
+ } else {
+ // If already off but the roof is warming up, no need to turn it on
+ // too early; the water that's sitting there can continue to gather
+ // heat.
+ want_state = outtemp > intemp + 0.3;
+ }
- if (id(valve_output).state == want_state) {
+ if (cur_state == want_state) {
ESP_LOGD("control_valve", "Leaving valve %s", want_state ? "ON" : "OFF");
if (!want_state && id(pool_pump).state && now > id(control_valve_last_change) + 600) {
auto t = id(sntp_time).now();
return;
}
+ ESP_LOGD("control_valve", "Turning valve %s", want_state ? "ON" : "OFF");
id(control_valve_last_change) = now;
id(valve_output).toggle();