mac-zhou / midea-ac-py

Home Assistant Custom Integration for Midea Group(Hualing, Senville, Klimaire, AirCon, Century, Pridiom, Thermocore, Comfee, Toshiba, Carrier, Goodman, Friedrich, Samsung, Kenmore, Trane, Lennox, LG and much more) Air Conditioners via LAN.
MIT License
539 stars 103 forks source link

Implementation of Freeze Protection mode #190

Open HausnerR opened 2 years ago

HausnerR commented 2 years ago

Hey, I saw in source code (especially in midea-msmart repo) comments about freeze protection mode. Any chance to implement it based on this (https://github.com/mac-zhou/midea-msmart/blob/97723d055d8e5a3775eaaca96807f2dbbd6db2aa/msmart/device/AC/command.py#L478)?

Best, HausnerR

mill1000 commented 2 years ago

We need a little more info on how to control the freeze protection mode. The comment referenced above only has information on what bit to check to see if it's enabled or not. We'd need to know what bit to send to control the mode.

Some packet captures between the mobile app and AC device would be a good start.

audreez commented 2 years ago

i can probably provide that, is it not encrypted?

audreez commented 2 years ago

i captured this between the minisplit and the router when i sent the FP command, is that what you are looking for ?

image

mill1000 commented 2 years ago

No, I believe we need to packets between your phone and the minisplit unit. Those are more difficult to capture.

HausnerR commented 2 years ago

Hey, I found that this repo probably have code for enabling/disabling FP mode (based on readme).

https://github.com/reneklootwijk/midea-uart

Maybe it can be analyzed and ported into this project?

mill1000 commented 2 years ago

Nice find. Working on this functionality in a branch here.

audreez commented 2 years ago

want me to test?

mill1000 commented 2 years ago

That would be great. You'll need to manually install this branch of msmart as well: https://github.com/mill1000/midea-msmart/tree/feature/freeze_protection

audreez commented 2 years ago

getting this when trying to add the repo <Integration mill1000/midea-msmart> Repository structure for master is not compliant

mill1000 commented 2 years ago

midea-msmart isn't a HACS repo. It has to be installed manually with pip in your HA environment

mill1000 commented 2 years ago

I've updated the branches and I think this functionality is ready, but I can't actually test as my units don't implement this.

Manually install msmart branch in your HA environment

pip install git+https://github.com/mill1000/midea-msmart.git@feature/freeze_protection

Manually install midea-ac-py branch in your HA custom_components

git clone -b feature/freeze_protection https://github.com/mill1000/midea-ac-py.git
cp -r midea-ac-py/custom_components/midea_ac/ <path-to-custom-components>
audreez commented 2 years ago

thanks! im planning on testing this weekend

audreez commented 2 years ago

getting this after copying it to custom components

Logger: homeassistant.components.climate Source: helpers/entity_platform.py:193 Integration: Climate (documentation, issues) First occurred: 2:10:53 PM (2 occurrences) Last logged: 2:10:53 PM

The midea_ac platform for the climate integration does not support platform setup. Please remove it from your config.

mill1000 commented 2 years ago

Try removing any midea_ac sections from your configuration.yaml. My branch uses the GUI for configuration.

audreez commented 2 years ago

got it working, how/where do i turn on the FP ? usually it needs to be in heat operation and you set the FP preset/mode but i dont see anything in operation or presets

mill1000 commented 2 years ago

Ah. I added it as a switch. You should see it on the device page if the unit report supporting it.

It appears I may have misunderstood this function. Would it be better suited as a preset? I see there's a PRESET_AWAY would that be equivalent?

audreez commented 2 years ago

added both of my splits (both support FP) to it but no switch was created, only 2 temp sensors and climate

yes away kind of makes sense

audreez commented 2 years ago

yes them more i think, preset "away" would be great, only available in heat mode as you can not turn on FP in any other mode

mill1000 commented 2 years ago

Can you enable logging? Add the following to your YAML.

  default: warning
  logs:
    custom_components.midea_ac: info
    msmart: debug

Then check your home-assistant.log, you may see something like this. Post yours here.

2022-09-10 10:03:53 INFO (MainThread) [custom_components.midea_ac] Querying device capabilities.
2022-09-10 10:03:54 INFO (MainThread) [custom_components.midea_ac.sensor] Setting up sensor platform.
2022-09-10 10:03:55 INFO (MainThread) [custom_components.midea_ac.binary_sensor] Setting up binary sensor platform.
2022-09-10 10:03:55 INFO (MainThread) [custom_components.midea_ac.switch] Setting up switch platform.
2022-09-10 10:03:55 INFO (MainThread) [custom_components.midea_ac.switch] Device does not support freeze protection.
2022-09-10 10:03:55 INFO (MainThread) [custom_components.midea_ac.climate] Setting up climate platform.

You may also see something like

2022-09-10 21:51:33 DEBUG (SyncWorker_0) [msmart.device.AC.command] Supported capabilities: {'eco_mode': False, 'eco_mode_2': True, 'freeze_protection': False, 'heat_mode': False, 'cool_mode': True, 'dry_mode': True, 'auto_mode': True, 'swing_horizontal': False, 'swing_vertical': True, 'nest_check': True, 'nest_need_change': False, 'turbo_heat': False, 'turbo_cool': True, 'fan_speed_control': False, 'cool_min_temperature': 16.0, 'cool_max_temperature': 30.0, 'auto_min_temperature': 16.0, 'auto_max_temperature': 30.0, 'heat_min_temperature': 16.0, 'heat_max_temperature': 30.0, 'decimals': True, 'light_control': True}

which we can confirm FP is supported.

audreez commented 2 years ago

2022-09-10 22:06:50.970 WARNING (MainThread) [custom_components.midea_ac.helpers] Device does not support 'get_capabilities' method. 2022-09-10 22:06:51.085 WARNING (MainThread) [custom_components.midea_ac.helpers] Device does not support 'filter_alert' property. 2022-09-10 22:06:51.725 WARNING (MainThread) [custom_components.midea_ac.helpers] Device does not support 'toggle_display' method. 2022-09-10 22:06:51.727 WARNING (MainThread) [custom_components.midea_ac.helpers] Device does not support 'supports_freeze_protection' property.

mill1000 commented 2 years ago

Looks like you're running an older version of msmart. If you're running a docker image, be sure to run the above pip install command within the container.

IF you're running HAOS you can use this extension, https://github.com/hassio-addons/addon-ssh, to access the shell and run pip

audreez commented 2 years ago

i run haos on proxmox, at some point i reinstalled haos and loaded from a backup so msmart was gone haos didnt have pip, i installed python + pip and installed msmart, now i can run midea-discover -i ip_address and it shows all the keys etc, (from ssh terminal addon)

when i restart home assistant log still displays same "not supported" messages any other ideas?

audreez commented 2 years ago

maybe dont require feature check ? jsut add an option: image

audreez commented 2 years ago

well deleted everything and reinstalled, still same issue image

image

mill1000 commented 2 years ago

i run haos on proxmox, at some point i reinstalled haos and loaded from a backup so msmart was gone haos didnt have pip, i installed python + pip and installed msmart, now i can run midea-discover -i ip_address and it shows all the keys etc, (from ssh terminal addon)

when i restart home assistant log still displays same "not supported" messages any other ideas?

HomeAssistant is still run within a container on HAOS. You most likely weren't inside the container (hence why you had to install Python)

The feature check is there to provide backwards compatibility with older msmart versions. Without it the integration would completely fail.

audreez commented 2 years ago

you are correct, i assumed the ssh addon takes you inside the homeassistnat docker container i was wrong,

anyway i got inside the docker container and installed msmart now i see freeze protection

image

so the switch does turn on the freeze protection, but it doesn't stay "on" to display status that its actually on and it does not turn it off if i try to toggle it again

mill1000 commented 2 years ago

Ok. That's some progress. Were there any log messages when trying to turn off the freeze protection? What model is your unit? I'm trying to understand how FP is used in the app/unit.

audreez commented 2 years ago

no errors in the log FP is used as vacation mode / away mode basically if you are leaving the house for the weekend you turn on heat mode and the FP which basically will keep your house from freezing and will set itself to i think ~46-47F (on regular remote lowest it goes is 62F i believe) on the app itself the heating set point stays the same you just torn on FP and it ignores the setpoint and uses 46F (hard set, non adjustable) as baseline, screen on the mini split also shows FP instead of temperature

here's a pic of the app

image

mill1000 commented 2 years ago

Ok thanks. That's helpful. Is FP mutual exclusive with ECO and Boost?

Can you enable debug logs when trying to turn on and off the FP? Even better if you can capture logs while using the app to toggle FP mode. We should be able to confirm that I'm using the right bits.

  default: warning
  logs:
    msmart: debug
mill1000 commented 2 years ago

I made another branch that re-implements FP as an "Away" preset. Make sure to grab the latest msmart branch as well. https://github.com/mill1000/midea-ac-py/tree/feature/fp_away_mode_preset

audreez commented 2 years ago

im goign to setup logs and run some tests, in FP mode i can turn on Boost, but not ECO

so i ran: pip install git+https://github.com/mill1000/midea-msmart.git@feature/freeze_protection --upgrade then: git clone -b feature/fp_away_mode_preset https://github.com/mill1000/midea-ac-py.git then: cp -r midea-ac-py/custom_components/midea_ac/ /config/custom_components/ then restarted

switched are now not working at all (expected) but i don't see an away preset image

audreez commented 2 years ago

for the logging, are you looking for these when i turn on/off FP? there is a lot of fluff there just narrowing down on what you need would help

Line 20: 2022-09-14 09:55:35.245 DEBUG (SyncWorker_4) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 33: 2022-09-14 09:55:50.981 DEBUG (SyncWorker_4) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 46: 2022-09-14 09:56:08.983 DEBUG (SyncWorker_6) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 55: 2022-09-14 09:56:20.985 DEBUG (SyncWorker_7) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 64: 2022-09-14 09:56:35.988 DEBUG (SyncWorker_2) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 81: 2022-09-14 09:57:05.985 DEBUG (SyncWorker_6) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000000000
Line 90: 2022-09-14 09:57:20.984 DEBUG (SyncWorker_0) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 99: 2022-09-14 09:57:35.987 DEBUG (SyncWorker_1) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584b0000000000000000800000
Line 112: 2022-09-14 09:57:53.995 DEBUG (SyncWorker_4) [msmart.device.AC.command] State response payload: c00185667f7f003c800004584a0000000000000000800000
mill1000 commented 2 years ago

Could you post the full log? I wonder if the capabilities aren't reporting FP support.

EDIT: Could also be that I'm checking the wrong operation mode when trying to add the Away preset

audreez commented 2 years ago

redacted sens infoa bit and attached midealog.txt

mill1000 commented 2 years ago

Thanks. Looks like FP is supported. Could you remove and re-install msmart via pip? I just want to make sure it's using the latest version of that branch and I'm not sure how --upgrade works when installing from git

audreez commented 2 years ago

she werks! it does turn on and off FP on the split image image

mill1000 commented 2 years ago

Awesome! Does it properly detect Away mode if you use the remote to enable it?

audreez commented 2 years ago

i used the app to run in and off (don't us the remote dnt know where it is) and it does detect it both ways

audreez commented 2 years ago

are you going to merge tp main branch or should i keep using your version? also let me buy you a beer!

mill1000 commented 2 years ago

I'll merge the FP changes into my "future" branch and create PRs for the main branch as well.