Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature increments are calculating incorrectly for Celsius #39

Open
codyc1515 opened this issue Jul 6, 2023 · 18 comments
Open

Temperature increments are calculating incorrectly for Celsius #39

codyc1515 opened this issue Jul 6, 2023 · 18 comments

Comments

@codyc1515
Copy link
Contributor

I am seeing that I can select in increments of .5 - which is right - but the issue is that they are offset.

Expected result

  • 20.5
  • 20.0
  • 19.5
  • 19.0

Actual result

  • 20.7
  • 20.2
  • 19.7
  • 19.2
@dotvezz
Copy link
Member

dotvezz commented Jul 6, 2023

Hey @codyc1515 thanks for the report. I'm not quite sure what you mean. You mention results, but could you fill more detail the process you followed to reach those results? (Where are you selecting increments of .5? etc)

If it helps, the device actually sends temperature data over MQTT in Kelvin, which this integration converts to °C by subtracting 273.15.

@codyc1515
Copy link
Contributor Author

codyc1515 commented Jul 6, 2023

It should not be possible to have temperature set to 19.7, as shown in HA. When I check the Dyson app I can only set by whole numbers (19/20/21) but when I look in HA it's 19.2. The HA integration let's me set .5 increments on this screen for some reason.

image

@dotvezz
Copy link
Member

dotvezz commented Jul 6, 2023

Aha, now I understand. I thought you were talking about the thermometer sensor, but you're actually talking about the thermostat? I'm actually not too familiar with that area yet - it was created long before I adopted the project.

I'll try to figure out what's going on here.

@codyc1515
Copy link
Contributor Author

Affirmative. I can take a look too.

@dotvezz
Copy link
Member

dotvezz commented Jul 6, 2023

Dug around for a few minutes in the target-temperature logic. Interestingly, it's using 273 instead of 273.15 for the C-to-K calculation. If HA is rounding .15 to .2 for the displayed value, that would explain why you're seeing 19.7 instead of 19.5, for example.

I'll do some testing and see if "fixing" that C-to-K value causes any other issues.

@codyc1515
Copy link
Contributor Author

codyc1515 commented Jul 7, 2023

While the 273 values are incorrect, I'm finding that it appears to still be rounding the digits (despite me correcting them). I think we should make use of the official HA function for Kelvin to Celsius.

@codyc1515 codyc1515 changed the title Temperature increments are calculating incorrectly for Celcius Temperature increments are calculating incorrectly for Celsius Jul 7, 2023
@dotvezz
Copy link
Member

dotvezz commented Jul 7, 2023

I 100% agree on using HA Core utils as much as possible. That said...

       "uses temperature utility. This is deprecated since 2022.10 and will "
       "stop working in Home Assistant 2023.4, it should be updated to use "
       "unit_conversion.TemperatureConverter instead"

So let's use the new one instead.

@dotvezz
Copy link
Member

dotvezz commented Jul 7, 2023

Okay, I found the actual reason - it's a limitation from the Dyson device itself: After receiving the command with a new target temperature, the device sends an MQTT "STATE-CHANGE" message over the status queue. In the message, it sends the device's (new) target temperature in Kelvin with a resolution of only .1K, so the device libdyson will always round a stray five-hundredths to a one-tenth. (edit: it also only receives target temp with a .1K resolution as well, so the rounding happens in libdyson technically, before sending to the device)

After a short series of repeated rounding quirks, the target temp rounding stabilizes at +0.2C.

So this means, weirdly enough, it's not calculating incorrectly at all! It's a weird user experience though, to be sure. What I think I'll wind up doing is round the (displayed) target temperature to the nearest 0.5c. Edit: No, I can be a little bit smarter than this I think. Example coming...

@dotvezz
Copy link
Member

dotvezz commented Jul 7, 2023

Example of how the 0.1K rounding causes this:

Setting Chagnge Target Temp Converts to K Rounds to K Converts to C (stored in Home Assistant sensor state) Rounds to C (displayed by Home Assistant)
Initial 21 294.15 294.2 21.05 21.1
21.05 - 0.5 20.65 293.8 293.8 20.65 20.7
20.65 - 0.5 20.15 293.3 293.3 20.15 20.2
20.15 - 0.5 19.65 292.8 292.8 19.65 19.7

But this only happens when using the "correct" 273.15 conversion. I'm guessing that the original creators of this integration chose to use the "incorrect" conversion intentionally because of this rounding quirk? Anyway, I'm not able to reproduce your error using the integration at its current release, weirdly enough. Could I ask you to help me track down where it's breaking down in your setup?

Since I'm not able to reproduce the rounding bug using my device, I wonder if you could help me with your device. I have a tool called dyson-mqtt-listen which you can use to export all the MQTT data that the device sends. Would you be willing to listen to the MQTT data whilst doing the following:

  1. Manually set the temperature specifically to 21.0 °C (or any other .0 or .5 °C initial value).
    • This can be done using the default thermostat Lovelace card, or by sending a service call. Annoyingly enough, the Climate entity view doesn't seem to let you set arbitrary values as far as I can see.
  2. Using the Climate entity view (the view in your screenshot) slowly increment/decrement the target temperature until you start seeing the rounding drift.
  3. Paste the MQTT data here or in a gist to review (feel free to censor out your serial number, credential, etc).

@dotvezz
Copy link
Member

dotvezz commented Jul 12, 2023

@codyc1515 Sorry to be a bother here. Just wanted to make sure you'd seen the above message. I'm not quite able to reproduce the behavior you're seeing.

@codyc1515
Copy link
Contributor Author

Thank you for the reminder. I appreciate it (lots going on). Curiously, setting the temperature via the service in HA worked okay, same with changing in 0.5c increments with the clicker in HA. Going back to the Dyson app, however, brings us back to 0.2c and 0.7c increments, so it appears the issue is when setting a temperature in the Dyson app and the Dyson reporting that temperature back to HA.

I will need to do some research on how to use your tool as I recently moved from the Container install to HAOS method.

@dotvezz
Copy link
Member

dotvezz commented Jul 12, 2023

lots going on

Dude I totally understand, thanks for following up!

Going back to the Dyson app, however, brings us back to 0.2c and 0.7c increments

Iiiiinteresting. I'll try to reproduce it that way.

I will need to do some research on how to use your tool as I recently moved from the Container install to HAOS method.

Sure thing. It should be pretty easy in theory: You can even just download the .exe (or the executable for whatever OS you use) from the github release and just run it in cmd., But getting the credentials might be a bit trickier if your device is a more recent variant. The readme has more info though.

Anywho I'm happy to help (and feedback on the tool is welcome too! It's very slapped-together right now)

@codyc1515
Copy link
Contributor Author

codyc1515 commented Jul 12, 2023

Thanks for the patience. The tool worked well. I didn't have Python installed, so obtained my credentials from the HA .storage folder. I managed to work out the tool parameters reasonably quickly.

Here is the results:

19:40:24: Connected to device...
19:40:24: Subscribed to 527E/XXX-XX-XXXXXXXX/status/current
19:40:24: Subscribed to 527E/XXX-XX-XXXXXXXX/command
19:40:24: Press Ctrl+C to exit.
19:40:39|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"CURRENT-STATE","time":"2023-07-12T07:40:40.000Z","mode-reason":"PRC","state-reason":"MODE","rssi":"-39","channel":"149","fqhp":"103944","fghp":"70816","product-state":{"fpwr":"ON","auto":"ON","oscs":"ON","oson":"ON","nmod":"OFF","rhtm":"ON","fnst":"FAN","ercd":"32U2","wacd":"NONE","nmdv":"0004","fnsp":"AUTO","bril":"0002","corf":"ON","cflr":"INV","hflr":"0044","cflt":"NONE","hflt":"GCOM","sltm":"OFF","osal":"0146","osau":"0236","ancp":"0180","hmod":"OFF","hmax":"2932","tilt":"OK","hsta":"OFF","psta":"CLNG","fdir":"ON"},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:40:43|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"STATE-CHANGE","time":"2023-07-12T07:40:44.000Z","mode-reason":"NONE","state-reason":"MODE","product-state":{"fpwr":["ON","ON"],"auto":["ON","ON"],"oscs":["ON","ON"],"oson":["ON","ON"],"nmod":["OFF","OFF"],"rhtm":["ON","ON"],"fnst":["FAN","FAN"],"ercd":["32U2","32U2"],"wacd":["NONE","NONE"],"nmdv":["0004","0004"],"fnsp":["AUTO","AUTO"],"bril":["0002","0002"],"corf":["ON","ON"],"cflr":["INV","INV"],"hflr":["0044","0044"],"cflt":["NONE","NONE"],"hflt":["GCOM","GCOM"],"sltm":["OFF","OFF"],"osal":["0146","0146"],"osau":["0236","0236"],"ancp":["0180","0180"],"hmod":["OFF","HEAT"],"hmax":["2932","2932"],"tilt":["OK","OK"],"hsta":["OFF","OFF"],"psta":["CLNG","CLNG"],"fdir":["ON","OFF"]},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:40:45|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"STATE-CHANGE","time":"2023-07-12T07:40:46.000Z","mode-reason":"NONE","state-reason":"MODE","product-state":{"fpwr":["ON","ON"],"auto":["ON","ON"],"oscs":["ON","ON"],"oson":["ON","ON"],"nmod":["OFF","OFF"],"rhtm":["ON","ON"],"fnst":["FAN","FAN"],"ercd":["32U2","32U2"],"wacd":["NONE","NONE"],"nmdv":["0004","0004"],"fnsp":["AUTO","AUTO"],"bril":["0002","0002"],"corf":["ON","ON"],"cflr":["INV","INV"],"hflr":["0044","0044"],"cflt":["NONE","NONE"],"hflt":["GCOM","GCOM"],"sltm":["OFF","OFF"],"osal":["0146","0146"],"osau":["0236","0236"],"ancp":["0180","0180"],"hmod":["HEAT","HEAT"],"hmax":["2932","2942"],"tilt":["OK","OK"],"hsta":["OFF","HEAT"],"psta":["CLNG","CLNG"],"fdir":["OFF","ON"]},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:40:48|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"STATE-CHANGE","time":"2023-07-12T07:40:49.000Z","mode-reason":"RAPP","state-reason":"MODE","product-state":{"fpwr":["ON","ON"],"auto":["ON","ON"],"oscs":["ON","ON"],"oson":["ON","ON"],"nmod":["OFF","OFF"],"rhtm":["ON","ON"],"fnst":["FAN","FAN"],"ercd":["32U2","32U2"],"wacd":["NONE","NONE"],"nmdv":["0004","0004"],"fnsp":["AUTO","AUTO"],"bril":["0002","0002"],"corf":["ON","ON"],"cflr":["INV","INV"],"hflr":["0044","0044"],"cflt":["NONE","NONE"],"hflt":["GCOM","GCOM"],"sltm":["OFF","OFF"],"osal":["0146","0146"],"osau":["0236","0236"],"ancp":["0180","0180"],"hmod":["HEAT","HEAT"],"hmax":["2942","2932"],"tilt":["OK","OK"],"hsta":["HEAT","HEAT"],"psta":["CLNG","CLNG"],"fdir":["ON","ON"]},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:41:04|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"STATE-CHANGE","time":"2023-07-12T07:41:05.000Z","mode-reason":"LAPP","state-reason":"MODE","product-state":{"fpwr":["ON","ON"],"auto":["ON","ON"],"oscs":["ON","ON"],"oson":["ON","ON"],"nmod":["OFF","OFF"],"rhtm":["ON","ON"],"fnst":["FAN","FAN"],"ercd":["32U2","32U2"],"wacd":["NONE","NONE"],"nmdv":["0004","0004"],"fnsp":["AUTO","AUTO"],"bril":["0002","0002"],"corf":["ON","ON"],"cflr":["INV","INV"],"hflr":["0044","0044"],"cflt":["NONE","NONE"],"hflt":["GCOM","GCOM"],"sltm":["OFF","OFF"],"osal":["0146","0146"],"osau":["0236","0236"],"ancp":["0180","0180"],"hmod":["HEAT","HEAT"],"hmax":["2932","2937"],"tilt":["OK","OK"],"hsta":["HEAT","HEAT"],"psta":["CLNG","CLNG"],"fdir":["ON","ON"]},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:41:08|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"STATE-CHANGE","time":"2023-07-12T07:41:09.000Z","mode-reason":"LAPP","state-reason":"MODE","product-state":{"fpwr":["ON","ON"],"auto":["ON","ON"],"oscs":["ON","ON"],"oson":["ON","ON"],"nmod":["OFF","OFF"],"rhtm":["ON","ON"],"fnst":["FAN","FAN"],"ercd":["32U2","32U2"],"wacd":["NONE","NONE"],"nmdv":["0004","0004"],"fnsp":["AUTO","AUTO"],"bril":["0002","0002"],"corf":["ON","ON"],"cflr":["INV","INV"],"hflr":["0044","0044"],"cflt":["NONE","NONE"],"hflt":["GCOM","GCOM"],"sltm":["OFF","OFF"],"osal":["0146","0146"],"osau":["0236","0236"],"ancp":["0180","0180"],"hmod":["HEAT","HEAT"],"hmax":["2937","2932"],"tilt":["OK","OK"],"hsta":["HEAT","HEAT"],"psta":["CLNG","CLNG"],"fdir":["ON","ON"]},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:41:10|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"CURRENT-STATE","time":"2023-07-12T07:41:11.000Z","mode-reason":"LAPP","state-reason":"MODE","rssi":"-46","channel":"149","fqhp":"103944","fghp":"70816","product-state":{"fpwr":"ON","auto":"ON","oscs":"ON","oson":"ON","nmod":"OFF","rhtm":"ON","fnst":"FAN","ercd":"32U2","wacd":"NONE","nmdv":"0004","fnsp":"AUTO","bril":"0002","corf":"ON","cflr":"INV","hflr":"0044","cflt":"NONE","hflt":"GCOM","sltm":"OFF","osal":"0146","osau":"0236","ancp":"0180","hmod":"HEAT","hmax":"2932","tilt":"OK","hsta":"HEAT","psta":"CLNG","fdir":"ON"},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}
19:41:12|527E/XXX-XX-XXXXXXXX/status/current: {"msg":"STATE-CHANGE","time":"2023-07-12T07:41:13.000Z","mode-reason":"LAPP","state-reason":"MODE","product-state":{"fpwr":["ON","ON"],"auto":["ON","ON"],"oscs":["ON","ON"],"oson":["ON","ON"],"nmod":["OFF","OFF"],"rhtm":["ON","ON"],"fnst":["FAN","FAN"],"ercd":["32U2","32U2"],"wacd":["NONE","NONE"],"nmdv":["0004","0004"],"fnsp":["AUTO","AUTO"],"bril":["0002","0002"],"corf":["ON","ON"],"cflr":["INV","INV"],"hflr":["0044","0044"],"cflt":["NONE","NONE"],"hflt":["GCOM","GCOM"],"sltm":["OFF","OFF"],"osal":["0146","0146"],"osau":["0236","0236"],"ancp":["0180","0180"],"hmod":["HEAT","HEAT"],"hmax":["2932","2937"],"tilt":["OK","OK"],"hsta":["HEAT","HEAT"],"psta":["CLNG","CLNG"],"fdir":["ON","ON"]},"scheduler":{"srsc":"0000000064618f8d","dstv":"0001","tzid":"0001"}}

I changed temp a few times in the native Dyson app, then a few times in HA.

Are we looking at the hmax value? It looks like, for example, 2937 would become 293.7 which itself becomes 20.05 then as you said becomes rounded to 20.1 in *C. So, I think that we may need to change, for example, 2937 or rather 293.7 to become 293.65, so a change of just -2.

The most baffling thing to me is that the Dyson app itself does not support half-degrees, so not sure where this comes in.

@codyc1515
Copy link
Contributor Author

Lastly, it looks like the app always sets X.2 whereas HA allows half-increments (X.2 then X.7). Is there a way to forbid this in HA (so they have to be whole increments, X.2 or X.0 ideally)?

@dotvezz
Copy link
Member

dotvezz commented Jul 12, 2023

I didn't have Python installed, so obtained my credentials from the HA .storage folder.

Oh nice! Those json files can be a bit monstrous, so I wondered whether or not I should suggest looking at them. Glad you got it!

Are we looking at the hmax value?

Yep!

It looks like, for example, 2937 would become 293.7 which itself becomes 20.05 then as you said becomes rounded to 20.1 in *C

Yep!

The most baffling thing to me is that the Dyson app itself does not support half-degrees, so not sure where this comes in.

Whaaaa... So the Dyson app only supports full-degree increments?

Funny enough, I'm not even able to test this on my device. Apparently regulations on movable heaters force compliance to UL 1278, preventing that feature from functioning in the US. So big thanks for sharing your MQTT data.

I'm trying to think of the best way to handle this...

@Paul-McNeice
Copy link

Funny enough, I'm not even able to test this on my device. Apparently regulations on movable heaters force compliance to UL 1278, preventing that feature from functioning in the US

It's not possible to enable heat mode remotely, however, if you use your physical remote to turn heat mode on, I think you can then use the app to change the temperature if that helps.

@codyc1515
Copy link
Contributor Author

Still an issue. Did not have any luck fixing myself. I am able to enable heat mode remotely. If someone would like to access my account, I can share details over email.

@codyc1515
Copy link
Contributor Author

Frustratingly, I am still facing this issue.

codyc1515 pushed a commit to codyc1515/ha-dyson that referenced this issue Jan 10, 2024
This is in line with what the app allows you to set (whole numbers only) for heating and resolves libdyson-wg#39.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants