return;
}
- static time_t last_change = 0;
time_t now = ::time(NULL);
- if (now < last_change + 300) {
- ESP_LOGD("control_valve", "Too soon to turn %s (%d seconds)", want_state ? "ON" : "OFF", now - last_change);
+ if (now < id(control_valve_last_change) + 300) {
+ ESP_LOGD("control_valve", "Too soon to turn %s (%d seconds)", want_state ? "ON" : "OFF",
+ now - id(control_valve_last_change));
return;
}
- last_change = now;
+ id(control_valve_last_change) = now;
id(valve_output).toggle();
# As soon as we know what the time is (and at 7am and 7pm), decide if the pump should be on.
restore_value: no
initial_value: '1'
+ - id: control_valve_last_change
+ type: time_t
+ restore_value: no
+ initial_value: '0'
+
time:
- platform: sntp
id: sntp_time
script.execute:
id: pump_default
force: true
+
+ # Before turning the pump on in the morning, both 'solar in'
+ # both 'solar in' and 'solar out' sensors will be reading the
+ # ambient temperature, as no water is flowing. So open the
+ # bypass valve (pump directly back to pool) and set the
+ # control_valve_last_change time so that the temperature logic
+ # in the control_valve script won't close it again for at
+ # least five minutes. By which time the 'solar in' sensor
+ # should be giving *water* temperature, so we won't close the
+ # valve until the roof genuinely is warmer than the
+ # water. This means we don't use the pool water to heat up the
+ # rubber and plastic sitting on the roof; let the *sun* do
+ # that first!
+ - seconds: 0
+ minutes: 59
+ hours: 6
+ then:
+ lambda: |-
+ id(control_valve_last_change) = ::time(NULL);
+ id(valve_output).turn_off();
+
on_time_sync:
then:
script.execute: