HomeAssistant-GreeClimateComponent icon indicating copy to clipboard operation
HomeAssistant-GreeClimateComponent copied to clipboard

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

Open ilya-draigor opened this issue 1 year ago • 9 comments

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 avatar Jul 20 '24 19:07 ilya-draigor

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.

ilya-draigor avatar Aug 04 '24 22:08 ilya-draigor

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 avatar Aug 05 '24 20:08 sceppi

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 avatar Aug 05 '24 20:08 sceppi

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.

sceppi avatar Aug 14 '24 14:08 sceppi

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

ilya-draigor avatar Aug 14 '24 14:08 ilya-draigor

Closing stale issue, Feel free to reopen if needed.

RobHofmann avatar Jun 09 '25 14:06 RobHofmann

Hi everyone,

I'm kind of new to this, but I also have a VRF system with 7 indoor units. I managed to read the state of each unit using their individual MAC addresses (I get temperature, power state, etc.), but I can't seem to control them — I can't turn them on/off or change the temperature.

Can someone tell me where I can find the methods or info to understand what I might be doing wrong? Maybe there's something I missed in the request format or encryption?

Thanks a lot in advance!

L0quillo avatar Jun 27 '25 08:06 L0quillo

I’d like to start by saying a big thank-you to everyone here in the community. I’m pretty new to all this—I’ve never done any programming before—and I’ve been leaning heavily on AI for guidance, as well as the tips and tricks I found on these forums.

After gathering information, I decided to experiment with direct communication to my Gree VRF system. Although I wasn’t able to retrieve the full devList, I did manage to pull data straight from the official Gree app, and ultimately succeeded in sending commands to the units. To make everything work, I dove into the climate.py file and added some custom modifications; with those changes, my VRF setup began responding perfectly.

Here’s a brief summary of my setup and what I did, in case it helps the next person or the project maintainers looking to expand VRF compatibility:

Encryption & Modules: My system uses Encryption Type 1 and the ME31-00/C3 Wi-Fi module.

External Unit: A GMV504 controller.

Internal Units: Seven GMV ND36 indoor units.

What I couldn’t get in devList: The call still failed, but I could obtain the MAC addresses of each sub-unit from the official Gree app.

Key changes in climate.py:

Parsed the MAC addresses of each sub-unit from a new sub_units: list in configuration.yaml.

Updated the bind/handshake routine to loop through every MAC in that list.

Added logging statements to capture both requests and responses for each sub-device.

Tweaked the command-dispatch logic so that each VRF branch can be controlled independently.

Since making those updates, everything has run smoothly with my VRF network. I’m not 100% sure this is the “official” way to contribute, but I hope these notes help anyone trying to add or improve VRF support in this integration. If there’s anything I can clarify or expand on, just let me know!

Gree Climate Integration: VRF Support Enhancement

Overview: We have extended the existing Gree Climate integration for Home Assistant to support VRF (Variable Refrigerant Flow) systems. This allows you to control a master controller plus multiple indoor units (sub‑units) individually.

Gree Climate Integration: VRF Support Enhancement

Overview: We have extended the existing Gree Climate integration for Home Assistant to support VRF (Variable Refrigerant Flow) systems. This allows you to control a master controller plus multiple indoor units (sub‑units) individually.

  1. Configuration Changes

Update your configuration.yaml under climate: as follows (using placeholder values):

climate:

  • platform: gree name: "Office Main" host: 192.168.X.Y # Replace with your Gree Wi‑Fi module IP (e.g., 192.168.1.50) mac: "AA:BB:CC:DD:EE:FF" # Master controller MAC (no separators also supported) port: 7000 # Optional, default = 7000 timeout: 10 # Optional, default = 10 seconds sub_units: # List of VRF indoor‑unit MACs (as reported by the official Gree+ app)
    • "11:22:33:44:55:66"
    • "77:88:99:AA:BB:CC" sub_unit_names: # (Optional) Friendly names in the same order
    • "AC Lobby"
    • "AC Conference Room"

Note: If you omit sub_units, the integration will register only the master controller as a single entity.

  1. Code Modifications in climate.py

Below are the exact snippets applied to your final climate.py to add VRF support:

2.1 New Configuration Keys

--- INICIO CAMBIOS VRF ---

CONF_SUB_UNITS = 'sub_units' CONF_SUB_UNIT_NAMES = 'sub_unit_names'

--- FIN CAMBIOS VRF ---

@@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_NAME, default='Gree Climate'): cv.string, vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PORT, default=DEFAULT_PORT): cv.positive_int, vol.Required(CONF_MAC): cv.string, vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, @@

  • --- INICIO CAMBIOS VRF ---

  • Define optional VRF keys with defaults

  • vol.Optional(CONF_SUB_UNITS, default=[]): vol.All(cv.ensure_list, [cv.string]),
  • vol.Optional(CONF_SUB_UNIT_NAMES, default=[]): vol.All(cv.ensure_list, [cv.string]),
  • --- FIN CAMBIOS VRF ---

})

2.2 Platform Setup Logic

async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Configura la plataforma de clima Gree.""" _LOGGER.info("Iniciando configuración de la plataforma Gree Climate.")

  • Read VRF lists (empty if not provided)

  • sub_units = config.get(CONF_SUB_UNITS)

  • sub_unit_names = config.get(CONF_SUB_UNIT_NAMES) master_name = config.get(CONF_NAME) or default_name

    devices = []

    if not sub_units:

  •    # Standard mode: only master device
    
  •    # Standard mode: only master device
       device_config = { **config, "name": master_name, "sub_unit_mac": None }
       devices.append(device_config)
    
    else:
  •    # VRF mode: create one config per sub-unit
    
  •    # VRF mode: create one config per sub-unit
       for i, sub_mac in enumerate(sub_units):
           sub_name = sub_unit_names[i] if i < len(sub_unit_names) else f"{master_name} {sub_mac[-6:]}"
           _LOGGER.info(f"Creando dispositivo VRF: '{sub_name}' MAC {sub_mac}")
           device_config = {
               **config,
               "name": sub_name,
    
  •            "sub_unit_mac": sub_mac  # string with separators
    
  •            # strip separators before passing to constructor
    
  •            "sub_unit_mac": sub_mac.replace(':', '').lower(),
           }
           devices.append(device_config)
    

    Instantiate entities

    entities_to_add = []

2.3 Entity Initialization and Command Handling

class GreeClimate(ClimateEntity): def init(..., sub_unit_mac=None): self._master_mac_addr = master_mac_addr.lower()

  •    # standard unique id
    
  •    self._unique_id = 'climate.gree_' + self._master_mac_addr
    
  •    # VRF: if sub_unit_mac is set, use it for unique_id
    
  •    self._sub_unit_mac = sub_unit_mac
    
  •    if self._sub_unit_mac:
    
  •        self._unique_id = 'climate.gree_' + self._sub_unit_mac
    
  •    else:
    
  •        self._unique_id = 'climate.gree_' + self._master_mac_addr
    

def GreeGetValues(self, propertyNames):

  • mac_to_query = self._master_mac_addr
  • mac_to_query = self._sub_unit_mac or self._master_mac_addr _LOGGER.debug(f"Requesting status for MAC {mac_to_query}") plaintext = '{"cols":' + simplejson.dumps(propertyNames) + '...'
  1. Why These Changes?

Individual Control: VRF indoor units each have a unique MAC. Exposing them as separate entities enables per‑unit control of temperature, mode, fan, and swing.

Official App Discovery: You can retrieve sub‑unit MACs using the official Gree+ mobile app under Wi‑Fi module details.

Backward Compatibility: Existing single‑unit setups remain unchanged if sub_units is not defined.

Enhanced Logging: Clear debug/info logs for VRF scenarios help troubleshooting network communication.

Feel free to post questions or share feedback on this GitHub Forum thread. Enjoy finer control of your Gree VRF system in Home Assistant!

L0quillo avatar Jun 29 '25 18:06 L0quillo

Nicely done!

It would be great to further iterate on this. Theres a few things i'm thinking of that should be fixed before we can do a broader test:

  1. Add the config_flow way. Right now you've created support for the configuration in the YAML's. Recently the feature was added to add your Gree system through the UI of Home Assistant too (under Settings --> Devices & Services --> Add Integration --> Gree. Make sure to remove it from your YAML configuration first). This UI "config flow" is the desired way by Home Assistant to configure your integrations.
  2. Add support for the translations (AI should be able to help you greatly with this). Look in the translations folder for the translation files.

When those features have been supported by your new version, I could give it a try and check if the backwards compatility is still in place and we could merge those VRF/non-VRF setups together :).

EDIT: PS. Not sure if you are aware, but you can fork this repository (and make a copy of your own). Then add the modifications there (and test it). Then whenever you are ready you can make a pull request towards this repository so we can see the differences and start testing & integrating them :).

RobHofmann avatar Jul 01 '25 20:07 RobHofmann