ScratMan / HASmartThermostat

Smart Thermostat with PID controller for HomeAssistant
353 stars 50 forks source link

Option for setting an aditional min_cycle_duration for PID off #45

Closed TTLucian closed 2 years ago

TTLucian commented 2 years ago

Is your feature request related to a problem? Please describe. In regards to smart_thermostat.set_pid_mode service and generic usage of HASmartThermostat Before HASmartThermostat I've used generic thermostat with min_cycle_duration of 10 seconds and hot/cold tolerance of 0.1 °C so I would get fast response when changing target_temperature. However, seting a cycle duration of 10 seconds in HASmartThermostat is not a viable option (at least for systems with big inertia like gas boilers + radiators; mine for example takes 7-8 seconds to light the flame on) because it would cause short, unnecessary cycles when the error is small. I have found that a min_cycle_duration of 10 to 15 minutes is ideeal for PID auto mode but when PID is off, with a min_cycle_duration of 15 minutes, I get big temperature fluctuations around the target temperature due to the big inertia of the system (the water in the radiators heats up to 60 °C).

Describe the solution you'd like Adding a pid_off_min_cycle_duration parameter in the config would solve this problem.

Thanks for this awesome component!

ScratMan commented 2 years ago

Hello, I don't understand how a lower cycle duration would help reducing the overshoot while in PID Off mode, as the heater will remain on till the measured temperature exceeds the set point + hot tolerance. With PID set to off, there is no modulation at all. Could you please show an example of the behaviors with the three modes (generic/10s, PID/15mn, PID off/15mn) ? Thanks

TTLucian commented 2 years ago

👋 Hi! Even though the target temperature reaches actual temperature + 0.1 degrees (hot/cold tolerance) , the heater wil not turn off until min_cycle_duration is reached. One scenario would be this: image So it runs the entire cycle of 15 minutes even though I don't want it to. The generic_thermostat with min_cycle_duration of 10 seconds would turn it off 10 seconds after actual temp > target temp + tolerance.

ScratMan commented 2 years ago

OK, understand. But the goal of the min_cycle_duration is to:

So, reducing the delay to 10 seconds, these two objectives won't be met. If your heating system is fast enough, you should reduce the min_cycle_duration but keep it for all conditions.

TTLucian commented 2 years ago

I've been using generic_thermostat for 2 years now and it's been working great with these settings with almost no overshoots, the downside being however, that I had to manually adjust it to low power to slow it down for mild winters, 10 seconds min_cycle_durations being ideal (radiators still gowing to 40 °C even at minimum power). Now, I can increase the power so it reaches the target temperature faster in certain conditions, having PID slowing it down before reaching the target temp and 15 mis cycle is almost perfect (I still need to tinker a bit with the PID). However, there are several scenarios in which I would like to use the "PID off" with schedules and automations (eg when it's not so cold outside, or when the boiler is preparing hot water etc - I'd rather not go into much details) but the 15 min cycle is really a problem for me in these cases and distinct cycles for both PID modes would help very much in automating the system for both very cold and mild winters. Anyway, I know that there are other important things that need time and work but maybe you would consider this. Thanks again for everything.

ScratMan commented 2 years ago

But 10 seconds is very short, it may damage your boiler. How long does it take for your heating system in PID off mode for the temperature to start to rise after the heater is switched on at 100% ? If it's fast like 5 minutes you may set the minimum duration to this, it should have limited impact on the PID, as the integral will in the end force a minimum heating duration.

TTLucian commented 2 years ago

We could stretch this discussion forever, so, disregarding all actual scenarios and parameter values, the component would greatly benefit from adding this to its already great flexibility and versatility. The more usage scenarios it can cover, the better. The component has tremendous potential of helping users get the most out of their setups. More features and settings are always better than less. I would like to pitch more ideas and proposals, if that's ok with you. Thanks again!

ScratMan commented 2 years ago

I'm OK with new ideas, I'm discussing about it to be sure to understand the purpose of the request. Regarding this one, setting short min cycle duration for PID off seems to be the opposite of what should be done, IMHO.

When considering PID, higher switching frequency (shorter PWM period) and wider modulation range (capability to make very short to very long ON pulses, reaching 0% and 100%) give better control accuracy. The PID will look at the temperature variation, will compute a ON time and a OFF time, and finally switch ON and OFF the heater accordingly even if temperature didn't move in between. That's PID regulation. But short ON pulses may not be compatible with all heating systems: if PID says 1 minute ON but boiler needs 5 minutes for the water to be hot in the pipes, the boiler will run for nothing. That's the purpose of adding the min_cycle_duration, but it will degrade the performance of the PID by limiting the modulation range (the minimum ON pulse width may be clamped to 5%, 10% or 30% depending on min cycle duration and PWM period, and the maximum ON pulse width would be 95%, 90% or 70%).

When in PID OFF mode, the min_cycle_duration should normally be useless, as the heater will remain ON until the temperature reaches the target + tolerance, so the boiler will have time to warm up the water, as the thermostat won't see the temperature increase if the water remains cold.

As far as I understand your request, you rather need a way to force the heater ON or OFF manually or by an automation without respecting the min cycle duration. Am I wrong ? This could be done by a service, using the internal force_on and force_off variables.

TTLucian commented 2 years ago

I appreciate the info and I totally agree and understand! PID is a totally different beast and that in PID OFF mode, the min_cycle_duration should normally be useless, however, even though the "pid_mode" is set to off, the heater actually won't turn off unless the actual "on time" is at least equal to the min_cycle_duration (I believe this is why), thus causing unwanted "on" time and temperature overshoots in specific situations. That's why the "generic_thermostat" had it set to 10 seconds. I don't want to force anything on or off manually. The comment and graph I posted earlier generically illustrates the situation. I'm sorry I don't have any graphs of my old "generic_thermostat" data to better illustrate the situation. So, actually, what I would like, if it's possible, is to be able to set an extra parameter in the config (something like "pid_off_min_cycle_duration") to be used instead of the "min_cycle_duration" only if "pid_mode" is off. The feature request would be better described simply as being able to set in the config a different min_cycle_duration parameter for when "pid_mode" is off.

The logic would be something like: if "pid_mode=auto" then cycle_on_parameter=min_cycle_duration else if "pid_mode = off" then cycle_parameter=pid_off_min_cycle_duration

Thanks again.

ScratMan commented 2 years ago

Hello, please test the v2022.1.0 that includes optional settings to force PID off mode while in boost preset and define different on/off cycle durations for PID off mode.

TTLucian commented 2 years ago

Thanks so much! Boost PID off is a great feature. 👍🏻