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
281 stars 100 forks source link

Obtaining a key for devices alternative method #71

Closed DaniilMir closed 1 week ago

DaniilMir commented 4 years ago

I have 2 Inventor ACs with CS532AE modules. Both modules were synced with the Gree+ app. In fact it is the same app as Ewpe app.

Tried to obtain keys using the adb backup, but faced issues with an empty backup. Then tried to access SQLite db on a rooted device and couldn't connect to it.

After that i tried a logcat method from Post

It worked just fine with latest app version available at this moment (1.8.3.10).

But after getting the key, component was still failing with this error:

2020-06-30 20:27:08 ERROR (MainThread) [homeassistant.helpers.entity] Update for climate.ac_test fails Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 472, in async_device_update await self.hass.async_add_executor_job(self.update) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/gree/climate.py", line 627, in update self.SyncState() File "/config/custom_components/gree/climate.py", line 410, in SyncState currentValues = self.GreeGetValues(optionsToFetch) File "/config/custom_components/gree/climate.py", line 241, in GreeGetValues return self.FetchResult(self.CIPHER, self._ip_addr, self._port, self._timeout, jsonPayloadToSend)['dat'] File "/config/custom_components/gree/climate.py", line 220, in FetchResult data, addr = clientSock.recvfrom(64000) socket.timeout: timed out

I was really disappointed and started trying everything until I get any response from module. As an alternative way I decided to test it outside of home assistant. For that I used the python script from referenced repository
https://github.com/tomikaa87/gree-remote It requires https://pypi.org/project/cryptography/ to be installed (it was a bit tricky for me) after that I just navigated to the folder contained this script and executed it with the following parameters : python gree_test.py -b 192.168.1.255 -command search -k %key_from_logcat %

and got the following result:

Searching for devices using broadcast address: 192.168.1.255
Search finished, found 2 device(s)
Binding device: 192.168.1.105 (1xxxxxx7, ID: f4911e3exxx1)
Bind to f4911e3exxx1 succeeded, key = 4xxxxxxxxxxxxxx9
Binding device: 192.168.1.106 (1xxxxxxe, ID: f4911e3exxx2)
Bind to f4911e3exxx2 succeeded, key = FxxxxxxxxxxxxxxU

As you can see - it provided 2 different keys for 2 ACs First AC I connected to app had the same key in script output as the key I got from the logcat Second AC had a different key. My Issue was that I started configuring using the second AC and it's key in fact was different.

More interesting below ))) If I run this script even without providing the key, it still gives me the same output as above. python gree_test.py -b 192.168.1.255 -command search I don't know, maybe it is related to my modules or to firmware version, but it looks like it is possible to get keys without hacking Android app. Needs to be tested on other devices.

Small Update. I was able to reproduce this error again just by changing one character in a key. It looks like it is related to wrong key value and has nothing common with mac address formatting.
For one AC I have mac address in the following format : 'FF:FF:FF:FF:FF:FF' (uppercase in single quotes ) for the second it have ff:ff:ff:ff:ff:ff (lowercase no quotes) both are working without issues.

PLTorrent commented 4 years ago

Please check this: https://github.com/RobHofmann/HomeAssistant-GreeClimateComponent/issues/64#issuecomment-655345702

berdyshev commented 3 years ago

hey. it seems this is a much simpler method to get the required parameters without debugging via adb. Can it be added to README?

HawkUser commented 3 years ago

python gree_test.py -b 192.168.1.255 -command search

Thank You!

CyberLogicDEV commented 1 month ago

Hey, it looks like this solution doesn't work anymore, or I'm having some other issue. I have tried many possible solutions, but unfortunately without any luck,

When I use above python script it looks like this:

python gree.py -b 192.168.1.255 -command search

Searching for devices using broadcast address: 192.168.1.255
Search finished, found 3 device(s)
Binding device: 192.168.1.32 (, ID: 9424b8b18c47)
Traceback (most recent call last):
  File "C:\xxxxxx\gree.py", line 191, in <module>
    search_devices()
  File "C:\xxxxxx\gree.py", line 105, in search_devices
    bind_device(r)
  File "C:\xxxxxx\gree.py", line 115, in bind_device
    result = send_data(search_result.ip, 7000, bytes(request, encoding='utf-8'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\xxxxxx\gree.py", line 31, in send_data
    return s.recv(1024)
           ^^^^^^^^^^^^
TimeoutError: timed out

It's strange cause as you can see devices have been detected but without their names and then there is some problem with the script.

I'm using Sinclair AC. Gree+/EWPE apps works fine.

In HA logs we can see some weird issues:

2024-05-24 16:31:13.661 INFO (MainThread) [custom_components.gree.climate] Setting up Gree climate platform
2024-05-24 16:31:13.661 INFO (MainThread) [custom_components.gree.climate] Adding Gree climate device to hass
2024-05-24 16:31:13.661 INFO (MainThread) [custom_components.gree.climate] Initialize the GREE climate device
2024-05-24 16:31:13.661 INFO (MainThread) [custom_components.gree.climate] Retrieving HVAC encryption key
2024-05-24 16:31:13.664 INFO (MainThread) [custom_components.gree.climate] Fetching(192.168.1.31, 7000, 10, {"cid": "app","i": 1,"pack": "jvuNXfvi2CkYc/Ti5BoaoQ1f3homwy/9eNHe9XgYZvyj9mrs/0p7GUTdWxmNaBUt","t":"pack","tcid":"9424b8b4417c","uid": 0})
2024-05-24 16:31:23.675 ERROR (MainThread) [homeassistant.components.climate] Setup of platform gree is taking longer than 60 seconds. Startup will proceed without waiting any longer.
2024-05-24 16:31:45.396 ERROR (MainThread) [custom_components.hacs] Timeout of 20 reached while waiting for https://api.github.com/rate_limit
Traceback (most recent call last):
File "/config/custom_components/hacs/base.py", line 471, in async_can_update
response = await self.async_github_api_method(self.githubapi.rate_limit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/hacs/base.py", line 529, in async_github_api_method
raise HacsException(_exception)
custom_components.hacs.exceptions.HacsException: Timeout of 20 reached while waiting for https://api.github.com/rate_limit

Does anyone have a similar problem?

RobHofmann commented 1 month ago

Are you sure your connection is alright? You are getting a timeout to both the HVAC as to GitHub.

tomaszduda23 commented 1 month ago

There is another version of encryption https://github.com/RobHofmann/HomeAssistant-GreeClimateComponent/pull/165

CyberLogicDEV commented 1 month ago

Thank you guys, I can confirm that this solution is working for me.

toughvj commented 2 weeks ago

solved, can be closed