chamberlain2007 / aprilaire-ha

A custom component for Home Assistant to interact with Aprilaire thermostats.
MIT License
12 stars 5 forks source link

When Target Temp and Current Temp is 73, Home Assistant shows 72. #27

Closed hollywoodscotty closed 8 months ago

hollywoodscotty commented 11 months ago

Setting Target Tempurature to 73* F in Home Assistant, the number shows 73 in red for a moment, goes white, then shows to 72. Current Temperature shows as 72. On AprilAire app, temp and target temp are indeed 73. It appears my temps are off by 1 degree. However, when I set the target temp to 76 in Home Assistant, it stays 76 in Home Assistant, and the app also shows 76, so this issue is inconsistent. Device is 8840M.

chamberlain2007 commented 10 months ago

@hollywoodscotty Which version are you using?

hollywoodscotty commented 10 months ago

Owner

In HACS I see 0.7.0. Under device info I see Firmware: 3.03 and Hardware: Rev. H

chamberlain2007 commented 8 months ago

@hollywoodscotty Thanks for this report. I was finally able to find the issue. Resolved in #30 which will be the 0.7.1 release. It is currently in testing and will be released in a few days when I am comfortable with it.

The problem here is with the conversion between Celcius and Fahrenheit that HA does and when it rounds. Basically:

To fix this (without trying to modify HA core):

It's hacky but it works.

Thanks again for the report.

hollywoodscotty commented 8 months ago

"python rounds to even" that's bananas, but excellent catch. Thank you!

chamberlain2007 commented 8 months ago

According to the docs https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex

round(x[, n]) | x rounded to n digits, rounding half to even. If n is omitted, it defaults to 0.

In C# which is my day-to-day language, it also rounds to even by default, however it also has a parameter for specifying the midpoint rounding, eg

double temperature = 72.5;

Console.WriteLine(Math.Round(temperature)); // 72
Console.WriteLine(Math.Round(temperature, MidpointRounding.AwayFromZero)); // 73
Console.WriteLine(Math.Round(temperature, MidpointRounding.ToNegativeInfinity)); // 72
Console.WriteLine(Math.Round(temperature, MidpointRounding.ToPositiveInfinity)); // 73
Console.WriteLine(Math.Round(temperature, MidpointRounding.ToZero)); // 72