Smegheid / water_heater

Running solar water heater system with a busted panel sensor from a raspberry pi
0 stars 0 forks source link

Vary nighttime off times based on time of year #6

Open Smegheid opened 2 years ago

Smegheid commented 2 years ago

At the moment, the hard time limits are set in common.sh with the variables CONTROL_DAY_BEGIN and CONTROL_DAY_END. These are fine for now at the beginning of summer, but have the potential to waste some hot water in the other half of the year.

Even with our exponential back-off applied to snooping the output of the panel, sunrise happens about an hour and 20 minutes later in these parts in "winter", and sunset about the same earlier. With fixed thresholds, we'll attempt to start over an hour earlier than the panel is known to be even capable of heating, which is pointless.

The control loop should modify the times over the course of the year so that startup cannot happen grossly early and stopping for the evening isn't considered until it's late.

Smegheid commented 2 years ago

My gut feel is that we could do this on entering the WAIT_FOR_DAYTIME state. I'm thinking that on each entry, the script would calculate new times for the beginning and end of a day and then go check the current time against those as it does now. This would probably involve a transition state in front of the existing wait state that calculates the times once and then moves on.

Instead of getting mired in how to figure out sunrise and sunset times, I figure we could use sunwait to generate sunrise and sunset times based on a latitude and longitude. This already knows how to calculates offsets from both sunrise and sunset, so the config file would then provide those offsets.

The existing values of 8am and 5pm could be used as a fallback position, but there shouldn't be a reason why sunwait should ever fail so long as its inputs are good.

Smegheid commented 2 years ago

There's already a transition state that leads into the long wait for the next day. STATE_DAYTIME_END is used when the daytime check decides that they day's over. It then turns off the pump and drops into the wait state STATE_WAIT_FOR_DAYTIME.

This would be a good place to go figure out the start and stop times for the next day. If we also make this the first state that's entered from init, this will make sure that the times are always calculated before getting going.