GrKoR / esphome_aux_ac_component

ESPHome component for AUX based air conditioners. Direct wifi control of HVAC by ESPHome and Home Assistant. HVAC status and command feedback are available.
Other
197 stars 47 forks source link

fix: Better handle fractional setpoints #83

Closed KazWolfe closed 11 months ago

KazWolfe commented 12 months ago

Hi - apologies for dropping in on this PR unannounced. I recently got this working with my AUX ASW-H12U3/JIR1DI-US air conditioner, but noticed an issue when adjusting the temperature setpoint in Home Assistant.

Because I'm US-based, my unit of choice is Fahrenheit, and setting the temperature would cause some unpredictable jumping:

firefox_sHZNo9VcxC

A brief analysis seems to show that the setpoint was being rounded improperly:

[D][climate:011]: 'AUX AC' - Setting
[D][climate:040]:   Target Temperature: 22.22
...
[V][AirCon:2408]: Target temperature: 22.500000

This change will only set the fractional flag if the setpoint is actually a value of 0.5 or higher, which appears to have resolved the issue on my end. I'm not particularly sure what (if anything) this will negatively impact elsewhere in the project, but would still like to propose my changes nonetheless.

I will also note that the temperature displayed on my unit is in Celsius whenever set through the API, but that seems tolerable for now and would likely require additional RE work of the protocol to find that flag.

GrKoR commented 12 months ago

Hi @KazWolfe ! Thank you for your PR. I'll check it a bit later.

It seems like you are the first US-based user of my component. At least this is the first comment about the temperature in Fahrenheit. =) If you can save a log while you are changing display settings from Celsius to Fahrenheit, I'll add this feature to the component. Check this file for a brief instruction about capturing a log.

KazWolfe commented 12 months ago

Glad to be of service!

I've generated two log files for you, one where I was just swapping the unit between C and F at the same setpoint, and one where the setpoint was alternated directly between 16 deg C and 90 deg F (32 deg C). I couldn't get the script working properly on my setup, so I just captured the log directly from the device, including verbose info. Hopefully this isn't too much of an inconvenience for you. If these logs are insufficient, let me know and I can recapture/try to get the script working properly.

GrKoR commented 11 months ago

I merged your commit with better temperature fractional setpoint assignment, Thank you!

And thank you for your logs. I probably found the unit of measurement for the temperature in the protocol. I'll make changes in dev-branch and text you here, when complete this patch.

GrKoR commented 11 months ago

Hope I made it. Could you test dev-version? Change your ac_config.yaml like that:

external_components:
  - source: github://GrKoR/esphome_aux_ac_component@dev
    components: [ aux_ac ]
    refresh: 0s

Expected: air conditioner not switch from Fahrenheit to Celsius when command received.

KazWolfe commented 11 months ago

I can confirm that the temperature stays on the set unit on the dev branch, regardless of C or F state. Thanks!

I did notice that the setpoint is jumping around a bit (for example, I can't set to 74 F again); it looks like the change got lost on dev somehow (seems like the last merge accidentally wiped it):

https://github.com/GrKoR/esphome_aux_ac_component/blob/93a034f2be0f3f96164be514bb5586565714f303/components/aux_ac/aux_ac.h#L1914

Thank you for getting this in!

GrKoR commented 11 months ago

I can confirm that the temperature stays on the set unit on the dev branch, regardless of C or F state. Thanks!

Cool!

it looks like the change got lost on dev somehow (seems like the last merge accidentally wiped it):

Yep, it's my inattention =) Now it is fixed. Thank you! Now all this changes are in the master.

Thank you for your help! And enjoy! =)

KazWolfe commented 11 months ago

Things look good on my end! I think I'm running into an HVAC bug, because even with the fix I still have setpoints jumping around:

[12:51:39][D][climate:011]: 'AUX AC' - Setting
[12:51:39][D][climate:040]:   Target Temperature: 26.67
[12:51:39][D][AirCon:1645]: 0000317320: [=>] [BB 00 06 80 00 00 02 00] 11 01 [2B 7E] 
[12:51:39][D][AirCon:1359]: 0000317524: [<=] [BB 00 07 00 00 00 0F 00] 01 11 68 00 01 A0 00 22 00 00 00 00 10 00 00 [B4 2B] 
[12:51:39][W][AirCon:1914]: set packet temp_target: 21.000000 21 0
[12:51:39][W][AirCon:1914]: set packet temp_target: 26.666666 26 1
[12:51:39][W][AirCon:1914]: set packet temp_target: 21.000000 21 0
[12:51:39][W][AirCon:1914]: set packet temp_target: 26.666666 26 1
[12:51:39][D][AirCon:1645]: 0000317586: [=>] [BB 00 06 80 00 00 0F 00] 01 01 90 00 80 A0 00 22 00 00 00 00 10 00 00 [0D BB] 
[12:51:39][W][component:204]: Component aux_ac.climate took a long time for an operation (0.06 s).
[12:51:39][W][component:205]: Components should block for at most 20-30ms.
[12:51:39][D][AirCon:1359]: 0000317798: [<=] [BB 00 07 00 00 00 04 00] 01 01 0D BB [2B 43] 
[12:51:39][D][AirCon:1645]: 0000317855: [=>] [BB 00 06 80 00 00 02 00] 11 01 [2B 7E] 
[12:51:40][D][AirCon:1359]: 0000318057: [<=] [BB 00 07 00 00 00 0F 00] 01 11 90 00 00 A0 00 22 00 00 00 00 10 00 00 [8D 2B] 
[12:51:40][D][climate:378]: 'AUX AC' - Sending state:
[12:51:40][D][climate:381]:   Mode: OFF
[12:51:40][D][climate:383]:   Action: OFF
[12:51:40][D][climate:386]:   Fan Mode: AUTO
[12:51:40][D][climate:389]:   Custom Fan Mode: 
[12:51:40][D][climate:392]:   Preset: NONE
[12:51:40][D][climate:395]:   Custom Preset: 
[12:51:40][D][climate:398]:   Swing Mode: OFF
[12:51:40][D][climate:401]:   Current Temperature: 43.00°C
[12:51:40][D][climate:407]:   Target Temperature: 26.00°C

The ESP32 is sending the correct temp target command to the unit it seems (80 F - 21.67 C, so fractional needed), but then the aircon is just ignoring the fractional flag. I suspect this is a bug with my air conditioner (?!) rather than your code, but will record it here for posterity. Setting to non-fractionals works as expected still as well, so the code itself appears to be working:

[=>] [BB 00 06 80 00 00 0F 00] 01 01 68 00 00 A0 00 22 00 00 00 00 10 00 00 [B5 BB]      # set command to 70 (21.0 C)

This isn't critical at all, so I'll poke at it and see if I can find what's happening (and PR another fix) or if it really just is my air conditioner misbehaving. Either way, everything else seems to work.

(Edit: I have logs swapping the temperature between 70 and 71 F from the remote as well, just in case that's helpful. Looking at it more, it seems like using "naive" temperature mode causes some things to behave differently (0x06 at the end)? Is nothing simple with these things?)

Thanks again for your attention and support!

GrKoR commented 11 months ago

I doubt that this is the bug of your AC. It is much more likely that I've reverse engineered the protocol with lacks... I have explored your log and I have no thoughts about this trouble yet. Assumptions only.

Here is my not well structured description of the AUX communication protocol (Russian only, sorry). Target temperature is specified by a byte 10 (integer part of T) and by one bit of a byte 12 (does T has fractional part or not). Also there is a byte 22 which contains fractional part in decimal form. When I RE the protocol, I found, that original wifi-module doesn't use byte 22 when sets the target temperature. It use bytes 10 and 12 only. And it's very strange: why do they include duplication of target temperature fractional part into the protocol? Anyway I implemented the same behavior. But now I think, may be the byte 22 is used for Fahrenheit support... Why not? I'll test this assumption later in the new dev-branch and will text you here. Let stay in touch)