jmcollin78 / versatile_thermostat

A full featured Thermostat for Home Assistant: presets, window, motion, presence and overpowering management
MIT License
289 stars 27 forks source link

Device Offset (Through Self-Regulation) Should Always be Applied #467

Open mag2352 opened 4 months ago

mag2352 commented 4 months ago

Firstly, I'm making a new issue for this because it is largely unrelated to the other issues I am commenting on. This change is a very simple change. I'm using VTherm with some AC/HVAC units in Cooling mode. They have an issue where their internal temperature is very inaccurate in both heating and cooling modes. The current version of VTherm stops using the device temperature in offset calculations if the target temperature is reached. This prevents my HVAC from turning off the compressor (it still blows cold air).

Here is a quick example: The target temperature is 20 C. The external temperature sensor is reading 22 C. The HVAC internal temperature is reading 24 C. The HVAC would be set to some value under 24 C (let's say 22 C). This is a very basic calculation, but leaving the regulation algorithm aside, this makes sense: 24-22= 2 C offset. Underlying target temperature should be set to 20, but the offset adds 2, the final target temperature on the underlying unit is 22 C. Now, let's consider that the external temperature is reading 19.9 C (some value under the target of 20 C). For simplicity, let's assume the HVAC internal temperature is still reading 24 C. The calculated offset would be 4.1 C, but this wouldn't be applied due to the following lines in the code:

https://github.com/jmcollin78/versatile_thermostat/blob/2fd60074c7c0c2b483f7e2af3134d2b82dfd3cec/custom_components/versatile_thermostat/thermostat_climate.py#L204-L223

This code makes it so that the offset is not used if the current temperature is less than the target temperature. This results in the underlying entity not having the offset applied, and will result in a smaller target being applied to the underlying entity (the 4.1 C offset is no longer added). This effectively turns the AC back on when it reaches under the VTherm target temperature. The solution is simple, just remove the condition that prevents offsets from being applied if the target is reached. The commit on my fork does this (I can make a PR, but I am waiting for the PR on #240 to be approved).

mag2352/versatile_thermostat@7456a41e4970be9349e664014839b7ca622e04b6

To put the preview here, it looks like this after this simple change:

            offset_temp = 0
            device_temp = 0
            if (
                # regulation can use the device_temp
                self.auto_regulation_use_device_temp
                # and we have access to the device temp
                and (device_temp := self._hass.states.get(under._entity_id).attributes.get("current_temperature")) is not None
            ):
                offset_temp = device_temp - self.current_temperature
jmcollin78 commented 3 months ago

Hello, I will have a look more closely. I'm not sure of your asumption.

mag2352 commented 3 months ago

Sounds good. There is no rush on this, as I have this on my branch and it seems to work fine. If this causes issues, I can just use my fork for now. I just find it strange to use the offset setting in the configuration, and then have the VTherm stop using the offset once the target temperature is reached. In my case, this causes my HVAC to turn back on when the offset is no longer being used. It would make the most sense to me to always use the offset calculation.