gree-remote
gree-remote copied to clipboard
Simple way for remote control from linux server?
Hi, I want to use your code for remote control my gree ac, I need to auto set temperature on ac at some time using cron on my linux server...is it easy possible with "gree-remote" code? Also I must note that my server is not on same network as AC!
If it possible with gree-remote code on linux server please somebody write how I can easy do that, please step by step...
Thanks.
Hi,
There is no command line utility at the moment, but there are implementations in multiple languages that can be adapted. I have a python test script somewhere which can send commands to the AC. I get back to you when I found it.
Will be nice if you can do that with all info step by step how I can use it...your script using gree api? I need to control my AC from remote location, not from local network...
Thanks.
The script can only communicate directly with the units. If you can setup your firewall to allow trafic to your AC units, the script will reach them, but it uses the local communication protocol. I don't have implementation for the cloud API unfortunately.
Ok, I can work with it, I can open firewall ports to AC... If you know how directly to communicate with gree ac, do you know for some option to schedule temp changes from windows os?
Thanks.
Just a quick update, I'm working on the script. It's not finished, yet. You can track the progress on this branch: https://github.com/tomikaa87/gree-remote/tree/feature/python-cli-script/PythonCLI
Can I use it to set temperature on my gree ac, how? In this moment I just need that function...
I've finished with the initial implementation of the device control function of the script. You can use it in the following way:
-
You need to scan your network with the script in search mode:
python3 gree.py search -b <LAN broadcast address>If this succeeds, you should get a list of the devices found on your network. Each device has an ID, an IP address and a unique password. Make a note of these. -
You can read a parameter's value from a specific device like this:
python3 gree.py get <parameter name> -c <device IP address> -k <device password> -i <device ID>If the command succeeds, you should see the value of the parameter. -
You can also set a value of a parameter:
python3 gree.py set <parameter name> <value> -c <device IP address> -k <device password> -i <device ID>If the command succeeds, you should hear a beep from the unit.
The script can be found here: https://github.com/tomikaa87/gree-remote/blob/feature/python-cli-script/PythonCLI/gree.py It requires Python 3 to run.
Great, I`ll test it, thanks.
Hi!
Could you please adapt this script so it doesnt use pycrypto? For one, i'm having issues installing it, and second everywhere I read it states that pycrypto is compromised and not developing anymore.
@dulemis hi, i've updated the script, it now uses cryptography instead of pycrypto. You should be able to install it with python3 -m pip install cryptography. I've tested it, works fine in my environment.
Super, thank you very much!
Do you have any idea why I get following error?
pip install cryptography
Collecting cryptography Using cached cryptography-2.9.tar.gz (517 kB) Installing build dependencies ... ^[[B^[[B^[[error ERROR: Command errored out with exit status 1: command: /opt/bin/python3 /opt/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /opt/tmp/pip-build-env-t5jylq31/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.8,!=1.11.3; platform_python_implementation != '"'"'PyPy'"'"'' cwd: None Complete output (67 lines): Collecting setuptools>=40.6.0 Using cached setuptools-46.1.3-py3-none-any.whl (582 kB) Collecting wheel Using cached wheel-0.34.2-py2.py3-none-any.whl (26 kB) Collecting cffi!=1.11.3,>=1.8 Using cached cffi-1.14.0.tar.gz (463 kB) Collecting pycparser Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB) Installing collected packages: setuptools, wheel, pycparser, cffi Running setup.py install for cffi: started Running setup.py install for cffi: finished with status 'error' ERROR: Command errored out with exit status 1: command: /opt/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/opt/tmp/pip-install-ow212_5a/cffi/setup.py'"'"'; file='"'"'/opt/tmp/pip-install-ow212_5a/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /opt/tmp/pip-record-wa88x_k_/install-record.txt --single-version-externally-managed --prefix /opt/tmp/pip-build-env-t5jylq31/overlay --compile --install-headers /opt/tmp/pip-build-env-t5jylq31/overlay/include/python3.7/cffi cwd: /opt/tmp/pip-install-ow212_5a/cffi/ Complete output (50 lines): unable to execute 'arm-openwrt-linux-gnueabi-gcc': No such file or directory unable to execute 'arm-openwrt-linux-gnueabi-gcc': No such file or directory
No working compiler found, or bogus compiler options passed to
the compiler from Python's standard "distutils" module. See
the error messages above. Likely, the problem is not related
to CFFI but generic to the setup.py of any Python package that
tries to compile C code. (Hints: on OS/X 10.8, for errors about
-mno-fused-madd see http://stackoverflow.com/questions/22313407/
Otherwise, see https://wiki.python.org/moin/CompLangPython or
the IRC channel #python on irc.freenode.net.)
Trying to continue anyway. If you are trying to install CFFI from
a build done in a different context, you can ignore this warning.
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.7
creating build/lib.linux-armv7l-3.7/cffi
copying cffi/cffi_opcode.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/error.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/pkgconfig.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/model.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/verifier.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/vengine_cpy.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/vengine_gen.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/__init__.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/recompiler.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/setuptools_ext.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/commontypes.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/cparser.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/lock.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/api.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/backend_ctypes.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/ffiplatform.py -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_cffi_include.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/parse_c_type.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_embedding.h -> build/lib.linux-armv7l-3.7/cffi
copying cffi/_cffi_errors.h -> build/lib.linux-armv7l-3.7/cffi
warning: build_py: byte-compiling is disabled, skipping.
running build_ext
building '_cffi_backend' extension
creating build/temp.linux-armv7l-3.7
creating build/temp.linux-armv7l-3.7/c
arm-openwrt-linux-gnueabi-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=soft -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=soft -DNDEBUG -fno-inline -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=soft -DNDEBUG -fno-inline -I/media/ware/Entware.2019.10/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/include -I/media/ware/Entware.2019.10/staging_dir/toolchain-arm_cortex-a9_gcc-7.4.0_glibc-2.23_eabi/include -fPIC -I/usr/include/ffi -I/usr/include/libffi -I/opt/include/python3.7 -c c/_cffi_backend.c -o build/temp.linux-armv7l-3.7/c/_cffi_backend.o
unable to execute 'arm-openwrt-linux-gnueabi-gcc': No such file or directory
error: command 'arm-openwrt-linux-gnueabi-gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /opt/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/opt/tmp/pip-install-ow212_5a/cffi/setup.py'"'"'; file='"'"'/opt/tmp/pip-install-ow212_5a/cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /opt/tmp/pip-record-wa88x_k_/install-record.txt --single-version-externally-managed --prefix /opt/tmp/pip-build-env-t5jylq31/overlay --compile --install-headers /opt/tmp/pip-build-env-t5jylq31/overlay/include/python3.7/cffi Check the logs for full command output.
ERROR: Command errored out with exit status 1: /opt/bin/python3 /opt/lib/python3.7/site-packages/pip install --ignore-installed --no-user --prefix /opt/tmp/pip-build-env-t5jylq31/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.6.0' wheel 'cffi>=1.8,!=1.11.3; platform_python_implementation != '"'"'PyPy'"'"'' Check the logs for full command output.
@dulemis according to this line: unable to execute 'arm-openwrt-linux-gnueabi-gcc': No such file or directory you don't have gcc on your openwrt device and the installer tries to compile the necessary components. You can try installing with static wheels: https://cryptography.io/en/latest/installation/
Edit: after a quick search I've found this: https://openwrt.org/packages/pkgdata/python-cryptography
opkg install python3-cryptography
Installing python3-cryptography (2.8-1) to root... Downloading http://bin.entware.net/armv7sf-k2.6/python3-cryptography_2.8-1_armv7-2.6.ipk Configuring python3-cryptography.
python3 /jffs/gree.py search -b 10.1.1.63
Traceback (most recent call last):
File "/jffs/gree.py", line 3, in
Maybe you can try to modify the script and load the module manually using a full path: https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
Thank you! I seem to have continued issues with my environment. See below.
/jffs/gree.py
Traceback (most recent call last):
File "/jffs/gree.py", line 5, in
I noticed that cryptographt module is getting installed in a folder named pythhn3.8/site-packages, but my Python version is actually 3.7 and all my current files and packages are located in python3.7/site-packages. So I tried moving the cryptography folder to python3.7-folder, and then i started getting above magic number error...
Please ignore my last post, i've upgraded to Python 3.8 now and then it works. However, ihere is the next issue:
/jffs/gree.py search -b 10.1.1.63
Searching for devices using broadcast address: 10.1.1.63
Traceback (most recent call last):
File "/jffs/gree.py", line 188, in
I got to work by replacing the broadcast address with the actual IP of the Gree unit. Then I got the ID and key, so everything seems to work!
Two more questions!
1 do you have the original version with pycrypto? Could you publish it I would like to test something.
- Is it possible to somehow send several cimmsnds/settings in one request?
Thank you @tomikaa87, I've managed to make this work, but had to set the broadcast param to the actual AC's IP. When I tried with 192.168.1.255 it gave me the same permission error as for @dulemis. This answer gives a hint, but I couldn't make it work because of lack of Python knowledge.
@dulemis You can easily tweak the Python code so it sends an array of more than one element of cols list for get_param or more than one element for both opt and p list in set_param.
I'll make a pull request that enables printing more than one element (and avoid IndexError: list index out of range if there's no elements) in get_param. After that you can do a quick and dirty trick to get more than one param with get 'host", "name' even without changing the code.
BTW, @tomikaa87, you should update the script's URL with master branch instead of feature/... in this comment.
Hi Marko,
Great find, I added s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) before s.settimeout(3) and now the broadcast search seem to work :)
However, I tried your changed code and it doesnt work to get/set multiple values in one request.
gree.py get Pow, SetTem -c 10.1.1.16 -k xxxxxxxxxx -i xxxxxxxxx Getting parameter: Pow,
You should use single and double quotes exactly as in example in order for that hack to work.
Hello again @sm4rk0,
Okey, sorry I misunderstood, it does work now. However, the following doesnt:
gree.py set 'Pow 1", "SetTem 22'
@tomikaa87 do you know if is it possible to retrieve the inside/outside temperature from the Gree unit somehow?
@dulemis unfortunately my device doesn't have that feature and I didn't manage to capture the related communication. If your device can do that and the mobile app show this temperature, you should try capturing the data. On android, you can use Packet Capture, or if you have a laptop and a pendrive, you can use Kali Linux live to capture WiFi communication. You can decrypt the data in the packets with the device-specific password.
@tomikaa87 Script works great! Didn't notice your guide in this issue before now. Maybe you could add it to a README.md in the PythonCLI directory?
I also created my own guide fwiw: https://gist.github.com/grav/6004ded69263f54dc391c86adf20f89c
Hello all got a Gree aircon and try to set gree.py script from @tomikaa87 under Jeedom Debian 10 aircon is already set in wifi network using EWPE smart control
root@jeedom:/var/www/html/plugins/script/data# ./gree.py search -b 192.168.170.109
Searching for devices using broadcast address: 192.168.170.109
Search finished, found 1 device(s)
Binding device: 192.168.170.109 (c6xxxx60, ID: )
Traceback (most recent call last):
File "./gree.py", line 213, in
seems does not return any unique ID .
Thanks for your great job.
@DeadF
Hi, I've updated the script to have a new --verbose switch to enable debug logging. Please try to run that and share the output here to find out why it can't detect the device ID of your unit.
Hi tomikaa87 thanks for update. i use jeedom in proxmox VM. also try to create another ubuntu VM but still same result.
root@jeedom:/var/www/html/plugins/script/data# ./gree.py search -b 192.168.170.255 --verbose Searching for devices using broadcast address: 192.168.170.255 Search finished, found 0 device(s)
root@jeedom:/var/www/html/plugins/script/data# ./gree.py search -b 192.168.170.255 --verbose
Searching for devices using broadcast address: 192.168.170.255
search_devices: resp={'t': 'pack', 'i': 1, 'uid': 0, 'cid': '502ccxxxxx60', 'tcid': '', 'pack': 'LP24Ek0OaYogxs3iQLjL4N9zkK6Z9KWVTRCvhRWqV8Q6Hcv+Un2MiFEJz3NDMsHEI/Pa9syFI0kYFCUeBNxq44+UmYq4E5g5QzzU+6/Qd+QbBAoXfR9+9YbpzBBkmy3uZtdFMALbzIQfSicO3KpLeXLpvz93fYRRHLTlg2Zgioxbb7w7uMPP71vKyFENZweODvEJeWbjZ/VwJNq+lUDDeRlndWQaq6aF/gj7M7NaYGZz2sTOyF/t3EXhqAlo/Ivz'}, pack={'t': 'dev', 'cid': '', 'bc': 'gree', 'catalog': 'gree', 'mid': '10001', 'model': 'gree', 'name': 'cxxxxx60', 'series': 'gree', 'vender': '1', 'ver': 'V1.2.1', 'brand': 'gree', 'mac': '502ccxxxxx60', 'lock': 0}
Search finished, found 1 device(s)
Binding device: 192.168.170.109 (cxxxxx60, ID: )
send_data: ip=192.168.170.109, port=7000, data=b'{"cid":"app","i":1,"t":"pack","uid":0,"tcid":"","pack":"6/DYYuNvtRtMP9mIBJNNhzSDZ337NlMJxh04RiPPNys="}'
Traceback (most recent call last):
File "./gree.py", line 238, in
I see the problem, the script looks for cid in pack, which is empty. I'll improve the logic by taking cid from resp in this case.
Edit: I've just updated the script, please try it again.