RobHofmann / HomeAssistant-GreeClimateComponent

Custom Gree climate component written in Python3 for Home Assistant. Controls AC's supporting the Gree protocol.
GNU General Public License v3.0
317 stars 105 forks source link

Errors on integration startup. (ValueError: invalid literal for int() with base 10:) #200

Open ilya-draigor opened 4 months ago

ilya-draigor commented 4 months ago

GCloud wifi module connected to one of the VRF units All works with Gree+ android app, i can controll all 6 units

Core 2024.7.3 Supervisor 2024.06.2 Operating System 12.4 Frontend 20240710.0

Gree A/C integration version: 2.14.0

Gree Wifi module: v1.10 MID: 6000-v2.8

My config:

- platform: gree
  name: 'Tadiran'
  host: 192.168.1.20
  port: 7000
  mac: '94:24:B8:FD:5B:A3'
  target_temp_step: 1

tryied with encryption_version: 1 and 2

Logs:

[homeassistant.components.climate] Setting up gree.climate
[custom_components.gree.climate] Setting up Gree climate platform
[custom_components.gree.climate] Adding Gree climate device to hass
[custom_components.gree.climate] Initialize the GREE climate device
[custom_components.gree.climate] name(): Tadiran
[custom_components.gree.climate] name(): Tadiran
[custom_components.gree.climate] supported_features(): 425
[custom_components.gree.climate] temperature_unit(): °C
[custom_components.gree.climate] hvac_modes(): [<HVACMode.AUTO: 'auto'>, <HVACMode.COOL: 'cool'>, <HVACMode.DRY: 'd
[custom_components.gree.climate] min_temp(): 16
[custom_components.gree.climate] max_temp(): 30
[custom_components.gree.climate] target_temperature_step(): 1.0
[custom_components.gree.climate] fan_list(): ['Auto', 'Low', 'Medium-Low', 'Medium', 'Medium-High', 'High', 'Turbo'
[custom_components.gree.climate] swing_modes(): ['Default', 'Swing in full range', 'Fixed in the upmost position', 
[custom_components.gree.climate] supported_features(): 425
[custom_components.gree.climate] Gree climate device added to hass()
[custom_components.gree.climate] update()
[custom_components.gree.climate] Retrieving HVAC encryption key
[custom_components.gree.climate] Fetching(192.168.1.20, 7000, 10, {"cid": "app","i": 1,"pack": "gvkovhIzmmW04owVls7
[custom_components.gree.climate] Fetched device encrytion key: b'edited'
[custom_components.gree.climate] Starting SyncState
[custom_components.gree.climate] Attempt to check whether device has an built-in temperature sensor
[custom_components.gree.climate] Fetching(192.168.1.20, 7000, 10, {"cid":"app","i":0,"pack":"BsT9dNJ5xTSAtGi5mckl8/
[custom_components.gree.climate] Device has an built-in temperature sensor
[custom_components.gree.climate] Fetching(192.168.1.20, 7000, 10, {"cid":"app","i":0,"pack":"DhyDQDqaFuHyIDObmCB44J
[custom_components.gree.climate] Setting acOptions with retrieved HVAC values
[custom_components.gree.climate] Setting Pow: 
[custom_components.gree.climate] Setting Mod: 
[custom_components.gree.climate] Setting SetTem: 
[custom_components.gree.climate] Setting WdSpd: 
[custom_components.gree.climate] Setting Air: 
[custom_components.gree.climate] Setting Blo: 
[custom_components.gree.climate] Setting Health: 
[custom_components.gree.climate] Setting SwhSlp: 
[custom_components.gree.climate] Setting Lig: 
[custom_components.gree.climate] Setting SwingLfRig: 
[custom_components.gree.climate] Setting SwUpDn: 
[custom_components.gree.climate] Setting Quiet: 
[custom_components.gree.climate] Setting Tur: 
[custom_components.gree.climate] Setting StHt: 
[custom_components.gree.climate] Setting TemUn: 
[custom_components.gree.climate] Setting HeatCoolType: 
[custom_components.gree.climate] Setting TemRec: 
[custom_components.gree.climate] Setting SvSt: 
[custom_components.gree.climate] Setting SlpMod: 
[custom_components.gree.climate] Setting TemSen: 
[custom_components.gree.climate] Done setting acOptions
[homeassistant.components.climate] Error adding entity climate.tadiran for domain climate with platform gree

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 598, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 912, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1361, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/gree/climate.py", line 1292, in async_added_to_hass
    self.update()
  File "/config/custom_components/gree/climate.py", line 1087, in update
    self.SyncState()
  File "/config/custom_components/gree/climate.py", line 714, in SyncState
    self.UpdateHAStateToCurrentACState()
  File "/config/custom_components/gree/climate.py", line 612, in UpdateHAStateToCurrentACState
    self.UpdateHATargetTemperature()
  File "/config/custom_components/gree/climate.py", line 445, in UpdateHATargetTemperature
    if (int(self._acOptions['StHt']) == 1):
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
[custom_components.gree.climate] should_poll()
ilya-draigor commented 3 months ago

I did some checks.

This can be supported, by adding subList function.

When sending {"t": "scan"} request i got: {"t":"dev","bc":"","catalog":"gree","series":"gree","model":"gree","lock":0,"vender":"1","mid":"60","name":"GR-Gcloud_60_0a_5ba3_EC","ver":"V3.2.M","mac":"9424b8fd5ba3","subCnt":6} "subCnt":6 is number of indoor units.

Then sending request to get a list of units: {"cid":"app","i":0,"pack":"Lmtc+jPqo5okmScSkppBww==","t":"subList","tcid":"9424b8fd5ba3","uid":0} (pack with empty payload), "t":"subList" is the point. The responce will be: {"t":"subList","i":0,"c":6,"r":200,"list":[{"mac":"09c4a41d000000","mid":"6049"},{"mac":"352ea01d000000","mid":"6092"},{"mac":"655ea31d000000","mid":"6049"},{"mac":"0741a01d000000","mid":"6092"},{"mac":"21eda91c000000","mid":"604c"}]} (Here i have something strange, i have 6 units, but list contain only 5, on phone app i see all 6 units)

And now if i send regular payload, but in "mac" i put internal unit mac adress, it works, {"cols":["Pow"],"mac":"21eda91c000000","t":"status"} i successfully got stats, powered on and off, changed temperature.

Hope this can help to update the integration.

sceppi commented 3 months ago

Hello @ilya-draigor ,

I have the same issue, also trying to get my VRF unit running. I'm able to reproduce everything above, in my case I get subCnt: 3 as there are 3 internal units. I'm trying to get the list of mac adresses with the "t":"subList", but not getting a response.

Can you clarify what you mean with: 'pack with empty payload'? Do you mean: pack = {"cols":[],"mac":"9424b8f55784","t":"status"}, so an empty cols array? or do you mean pack = {} or something else?

I tried all of the above, but not getting the response with the individual mac adresses. The pack needs to be encrypted with the specific encryption key from my device, not the generic encryption key, correct?

sceppi commented 3 months ago

OK, never mind, I found the solution. I found I had to put the master MAC adress in the request and the subunit MAC adress in the pack. I had used both subunit MAC adresses in the request and the pack.

Exploring this further now :-)

sceppi commented 3 months ago

Hi @ilya-draigor,

I managed to get data and control my VRF unit with the above information. I also i successfully got stats, powered on and off, changed temperature, etc...

However, the only thing that I still cannot achieve is to get the list of units from the request. I got the mac adresses using the Gree app itself (the mac adresses are also listed there). However, for this integration to work, I would need to be able to retrieve them using the subList function as well.

So again, could you clarify what you mean with: 'pack with empty payload'? How is your request exactly structured to achieve the list of units? I tried the following:

pack = f'{{"mac":"9424b8f55784","t":"status"}}'
pack_encrypted = encrypt(pack, <my encryption code>)
request = '{"cid":"app","i":0,"pack":"%s","t":"subList","tcid":"9424b8f55784","uid":0}' \
              % (pack_encrypted)

But I get no response. I tried many variations on the above, but nothing works.

Thanks for your help.

ilya-draigor commented 3 months ago

hope this will help

def GetUnitsList(mac_addr,ip_addr,port,timeout,encryption_version):
    GENERIC_GREE_DEVICE_KEY = "a3K8Bx%2r8Y7#xDh"
    json = '{"mac":"' + str(mac_addr) + '"}'
    pack = EncryptPack(GENERIC_GREE_DEVICE_KEY,json)
    jsonPayloadToSend = '{"cid": "app","i": 1,"pack": "' + pack + '","t":"subList","tcid":"' + str(mac_addr) + '","uid": 0}'      
    data = SendPack(jsonPayloadToSend,ip_addr,port,timeout,encryption_version)
    pack = DecryptPack(GENERIC_GREE_DEVICE_KEY,data,encryption_version)
    units_list = simplejson.loads(pack)

    return units_list

hope this will help

by the way, i already wrote all init stuff (all you need in config is IP of the wifi module) all other data fetching automatically, my issue that i don't know how to create multiple devices in home assistant from single integration