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
519 stars 101 forks source link

HA loses access to aircons #132

Closed tinuva closed 2 years ago

tinuva commented 2 years ago

Describe the bug (描述一下问题) A clear and concise description of what the bug is.

The addon works fine, can control ACs and if ACs controlled manually HA sees the updates. However sometimes 12 hours or 24 hours or anything random inbetween after HA started, I lose access to control them. I am able to change mode for example, and the entity updates to the new mode, but the actual action doesn't happen. The devices never become unknown or anything.

When I restart Home Assistant, the issue is gone and I can control them again.

Almost like something in the state become out of sync and communication fail. Logs says 2022-02-21 15:59:40 WARNING (SyncWorker_1) [msmart.device] Got Null from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01 Got Null? Why would a restart of HA fix this.

Screenshots / Logs / Pcap File(屏幕截图/日志/抓包文件) If applicable, add screenshots or your home-assistant log file or pcap file to help explain your problem. 请提交相关截图,日志,抓包让开发者能够更快的解决问题

Debug logs:

2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.command] Finalize request data: aa23ac000000000000024001aa6603ff0030000000000000000000000000260000003e48
2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.device] pkt_builder: 10.0.0.53:6444 len: 104 data: 5a5a0111680020000000000016263b0f150216140b940000001e0000000000000000000000000000406378f790b427e06d567d4621860469ed6256eccaed50f3b7371045f41a47fcc7f8adcfc9f63d52b5c0964e20d0772ab3124788c95cf23ae81d0a1b20ef71a8
2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.lan] Socket 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85142.94 tcp_key: 625000d61c8224bb915d32289d5086d4114c5083cb522333700827706ebe2a2c
2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.lan] Sending 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85142.94 message: 8370008e20668d84b54fc25873edcfe08a40708e7780d9d80ab36e7a02a3991189233f926e8bb125c1f4ae3976036c550d3d6e5f493b6d9e1ea20dcd1cc2a5a418e97d1a7239b183d262ee755d71e43300c8e5822d99baf27c749f657786e41e9c61598bd068958330bcbe87f13465c557687c26551b6122451691bdb81c5e83caf0365d14d540bbbfb53a75fe5f8d6f107fdb75002f
2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.lan] Recv 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85142.96 Response: 83700005200f20004552524f52
2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.lan] Got responses len: 13
2022-02-21 15:59:38 DEBUG (SyncWorker_0) [msmart.device] Got responses from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.02
2022-02-21 15:59:38 WARNING (SyncWorker_0) [msmart.device] Got Null from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.02
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.command] Finalize request data: aa20ac00000000000003418100ff03ff000200000000000000000000000026d175
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.device] pkt_builder: 10.0.0.53:6444 len: 104 data: 5a5a0111680020000000000019263b0f150216140b940000001e00000000000000000000000000006b000a76e27eed2c3647e57d8602df8b7760b65cc8abde8d47750695623f1296137efcc7f8fe55c6253e8dc10f59f57a02447a413bf8d1fe838998b9dacc8357
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.lan] Socket 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85142.97 tcp_key: 625000d61c8224bb915d32289d5086d4114c5083cb522333700827706ebe2a2c
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.lan] Sending 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85142.97 message: 8370008e206612806efe8a556208907fa6bc4cb50c790725657038919725b190ffee2b5d2a317fce2a9bb113fd0e41d2cca3a09b10c1addfceb8824beb74c13a591744161ad8d08132deb5e9caf5c01ce2baaeccac845eab56ee881c5ce2e9d98e9910c93c1886f9da782a62fa8caab37ab1bd87d7559c021e56c51e6b0c285211731072654d417504ae81e475f3bffb58f599aedbb0
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.lan] Recv 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85142.98 Response: 83700005200f00204552524f52
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.lan] Got responses len: 13
2022-02-21 15:59:38 DEBUG (SyncWorker_5) [msmart.device] Got responses from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01
2022-02-21 15:59:38 WARNING (SyncWorker_5) [msmart.device] Got Null from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.command] Finalize request data: aa23ac000000000000024000aa6603ff003000000000000000000000000028000000b9cc
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.device] pkt_builder: 10.0.0.53:6444 len: 104 data: 5a5a011168002000000000000b283b0f150216140b940000001e000000000000000000000000000039f4de7006abeedb866e73bb954263e8c111bb839b8f1841f8b94a753499581372005ed0c5f05d502d9bbaf7b6de31f20f61fddef6945cd4679f3f0cd87a9d87
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.lan] Socket 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85144.83 tcp_key: 625000d61c8224bb915d32289d5086d4114c5083cb522333700827706ebe2a2c
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.lan] Sending 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85144.83 message: 8370008e2066c9d216576682bea6c8ba0d8033546764651b81f9ec7ec10008bb1ad3fa495b09f53bc6c11bb708d1b05e637c1e62341c81e251ed9418c7fe00357d0a75adef7b998b36ec31808699c9f0b23632909dff190994a3fe40492de1d5c747fa9a976359c09965bfa09e277ef1cbed656e08a55986b8e88ba29ffff0277db1edb10cfa2f319e89667bd04a521cdb44b9514022
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.lan] Recv 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85144.84 Response: 83700005200f20004552524f52
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.lan] Got responses len: 13
2022-02-21 15:59:40 DEBUG (SyncWorker_1) [msmart.device] Got responses from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01
2022-02-21 15:59:40 WARNING (SyncWorker_1) [msmart.device] Got Null from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.command] Finalize request data: aa20ac00000000000003418100ff03ff000200000000000000000000000028ce76
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.device] pkt_builder: 10.0.0.53:6444 len: 104 data: 5a5a011168002000000000000e283b0f150216140b940000001e00000000000000000000000000006b000a76e27eed2c3647e57d8602df8b9d742e43c1c1774fddb00e7877f991b0f4f6edc5dacd8853308e764c935ef4a48104f1a8b8113ca0e32ce910191ac7e9
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.lan] Socket 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85144.85 tcp_key: 625000d61c8224bb915d32289d5086d4114c5083cb522333700827706ebe2a2c
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.lan] Sending 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85144.85 message: 8370008e2066a9bd0917bac4671ecc61b9bd5fcaa7c164f74b283f3e5c8899bb2d3af6dd0d6ece52a26a5eaac6d1b770245c24f9396fbdcc7a902e1d455b04a39d052387e74e931b8dcd39a1f4f0fc5e85b802586cfd3b752280bc01096e73893d7e5a0c6babae9e011d68a16edfe3439921b291d7df1bb82ad4fae947deea92f2d1d90a73ca8093d1265af61c40740049c56aca31e2
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.lan] Recv 10.0.0.14:43788 -> 10.0.0.53:6444 retries: 0 time: 85144.86 Response: 83700005200f00204552524f52
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.lan] Got responses len: 13
2022-02-21 15:59:40 DEBUG (SyncWorker_4) [msmart.device] Got responses from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01
2022-02-21 15:59:40 WARNING (SyncWorker_4) [msmart.device] Got Null from 10.0.0.53:6444 Version: 3 Count: 0 Spend time: 0.01

Versions (版本信息)

Config:

logger:
  logs:
    msmart: debug

homeassistant:
  customize:
    climate.midea_ac_30786325862093:
      friendly_name: 'AC Main Bedroom'
    climate.midea_ac_30786325862153:
      friendly_name: 'AC Child Bedroom'
    climate.midea_ac_32985348871179:
      friendly_name: 'AC Office'

climate:
  - platform: midea_ac
    host: !secret midea_ac1_ip
    id: !secret midea_ac1_id
    # v3 need token and k1(key)
    token: !secret midea_ac1_token
    k1: !secret midea_ac1_k1
    prompt_tone: false

  - platform: midea_ac
    host: !secret midea_ac2_ip
    id: !secret midea_ac2_id
    # v3 need token and k1(key)
    token: !secret midea_ac2_token
    k1: !secret midea_ac2_k1
    prompt_tone: false

  - platform: midea_ac
    host: !secret midea_ac3_ip
    id: !secret midea_ac3_id
    # v3 need token and k1(key)
    token: !secret midea_ac3_token
    k1: !secret midea_ac3_k1
    prompt_tone: false
mac-zhou commented 2 years ago

respone 83700005200f20004552524f5 is ERROR

>>> bytearray.fromhex('83700005200f20004552524f52')[8:]
bytearray(b'ERROR')

this may require updating tcp_key, i think how to solve

mac-zhou commented 2 years ago
  1. modify the file custom_components/midea_ac/manifest.json, change msmart version to 0.2.1, like:
    {
        "domain": "midea_ac",
        "name": "Midea Smart Aircon",
        "version": "0.2.0",
        "documentation": "",
        "requirements": ["msmart==0.2.1", "pycryptodome", "pycryptodomex", "click"],
        "dependencies": [],
        "codeowners": ["@mac-zhou"]
    }
  2. restart your HA
tinuva commented 2 years ago

Thank you. Have done so and will monitor it over the next few days.

root@home-assistant:/usr/share/hassio/homeassistant# docker exec -it homeassistant python -m pip show msmart
Name: msmart
Version: 0.2.1
Summary: A library to control Midea appliances via the Local area network
Home-page: https://github.com/mac-zhou/midea-msmart
Author: mac_zhou
Author-email: mac.zfl@gmail.com
License: MIT
Location: /usr/local/lib/python3.9/site-packages
Requires: ifaddr, pycryptodome, click, requests
Required-by: 
tinuva commented 2 years ago

I am optimistic, it looks like my ACs have been 100% now for 48 hours. If it continues like this for the next few days I think this issue can be resolved.

0xa51f commented 2 years ago

I am optimistic, it looks like my ACs have been 100% now for 48 hours. If it continues like this for the next few days I think this issue can be resolved.

This has defintely helped for me - also up for 48hrs, whereas previously it would disconnect 12-24 hrs after a HA restart

mac-zhou commented 2 years ago

The new version should solve this issue, please update