rytilahti / python-miio

Python library & console tool for controlling Xiaomi smart appliances
https://python-miio.readthedocs.io
GNU General Public License v3.0
3.77k stars 563 forks source link

Support for Zero Fog DWZF(G)-4500Z (`shuii.humidifier.jsq002`)humidifier #1171

Open iromeo opened 3 years ago

iromeo commented 3 years ago

Device information:

Use miiocli device --ip <ip address> --token <token>.

Additional context Some time ago I added shuii.humidifier.jsq001 support. Now I'm going to make a PR for shuii.humidifier.jsq002 device support. This issue is a first step for supporting it in HomeAssistant, as part of https://github.com/syssi/xiaomi_airpurifier/issues/50

wxy8866 commented 2 years ago

I have this device. Is there any chance to get it work?

iromeo commented 2 years ago

@wxy8866 I'm working on a PR in my spare time, not ready yet.

MJeka commented 2 years ago

Hi. I have the same problem.

iromeo commented 2 years ago

@MJeka @wxy8866

Hi guys, I implemented code to support this device, so e.g. it could be used for further integration with Home-Assistant (https://github.com/syssi/xiaomi_airpurifier/issues/50) or some other home automation hub. But before opening a pull request and merging it into python-miio we need to test my fix. I have only prev model shuii.humidifier.jsq001, so I cannot test shuii.humidifier.jsq002, they have different commands and response params.

In order to test my integration with device, you need to:

1) I assume you are familiar with command line and have git and python installed. It is easier to make it using Mac OS or Linux. But windows is also ok. 2) Also I assume you already have a token for your device, e.g you could use https://github.com/Squachen/micloud project or https://python-miio.readthedocs.io/en/latest/discovery.html 3) Clone my repo with fix and install miiocli tool from sources (with my changes). Here steps are similar to https://python-miio.readthedocs.io/en/latest/discovery.html#installation but using my repo.

git clone --branch features/1171_jsq002_support https://github.com/iromeo/python-miio.git python-miio-iromeo
cd python-miio-iromeo

poetry install

4) List of available commands:

$ poetry run miiocli airhumidifierjsq002 --help
Usage: miiocli airhumidifierjsq002 [OPTIONS] COMMAND [ARGS]...

Options:
  --ip TEXT     [required]
  --token TEXT  [required]
  --model TEXT
  --help        Show this message and exit.

Commands:
  info                          Get (and cache) miIO protocol information...
  off                           Power off.
  on                            Power on.
  raw_command                   Send a raw command to the device.
  set_buzzer                    Set buzzer on/off.
  set_child_lock                Set child lock on/off.
  set_heater                    Set water heater on/off.
  set_led                       Turn led on/off.
  set_led_brightness            Set led brightness.
  set_mode                      Set mode.
  set_target_humidity           Set the target humidity %, only 0..99.
  set_target_water_temperature  Set the target water temperature degrees...
  status                        partial(func, *args, **keywords) - new...
  test_properties               Helper to test device properties.

5) Please test commands, check that they changes device settings as expected. Also that in status command results all fields have values as expected.

Some times command could not from the first attempt due to Error: Unable to discover the device ... Just retry in few seconds.

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> info

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> on
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> off

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_buzzer true
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_buzzer false

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_child_lock true
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_child_lock false

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_heater true
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_heater false

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_led true
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_led false

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_led_brightness off
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_led_brightness low
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_led_brightness high

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_mode level1
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_mode level2
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_mode level3

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_humidity 30
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_humidity 0
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_humidity 31
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_humidity 99

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_water_temperature 30
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_water_temperature 33
miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> set_target_water_temperature 60

miiocli airhumidifierjsq002 --ip <IP> --token <TOKEN> status
AleksandrBoyarshinov commented 2 years ago

Checked all the commands. The commands to turn on and off the water heater do not work. All other commands are working.

miiocli airhumidifierjsq002 --ip <my ip> --token <my token> set_heater true - I get an error

Turning on water heater Traceback (most recent call last): File "", line 1, in File "/home/alex/python-miio-iromeo/miio/cli.py", line 63, in create_cli return cli(auto_envvar_prefix="MIIO") File "/home/alex/python-miio-iromeo/miio/click_common.py", line 51, in call return self.main(args, kwargs) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(args, kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 300, in wrap kwargs["result"] = func(*args, *kwargs) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func return ctx.invoke(f, obj, args, kwargs) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(*args, kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 265, in command_callback return miio_command.call(miio_device, *args, *kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 212, in call return method(args, kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 179, in _wrap return func(self, *args, **kwargs) TypeError: set_heater() got an unexpected keyword argument 'heater'

miiocli airhumidifierjsq002 --ip <my ip> --token <my token> set_heater false - I get an error

Turning off water heater Traceback (most recent call last): File "", line 1, in File "/home/alex/python-miio-iromeo/miio/cli.py", line 63, in create_cli return cli(auto_envvar_prefix="MIIO") File "/home/alex/python-miio-iromeo/miio/click_common.py", line 51, in call return self.main(args, kwargs) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(args, kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 300, in wrap kwargs["result"] = func(*args, *kwargs) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/decorators.py", line 84, in new_func return ctx.invoke(f, obj, args, kwargs) File "/home/alex/.cache/pypoetry/virtualenvs/python-miio-S5EGbLNS-py3.8/lib/python3.8/site-packages/click/core.py", line 754, in invoke return __callback(*args, kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 265, in command_callback return miio_command.call(miio_device, *args, *kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 212, in call return method(args, kwargs) File "/home/alex/python-miio-iromeo/miio/click_common.py", line 179, in _wrap return func(self, *args, **kwargs) TypeError: set_heater() got an unexpected keyword argument 'heater'

iromeo commented 2 years ago

@AleksandrBoyarshinov Thx a lot! I fixed an error in the heater command.

Please check again: 1) Update project:

cd python-miio-iromeo
git pull

2) Re-install library:

poetry install

3) Check heater:

miiocli airhumidifierjsq002 --ip <my ip> --token <my token> set_heater true
miiocli airhumidifierjsq002 --ip <my ip> --token <my token> set_heater false
AleksandrBoyarshinov commented 2 years ago

@iromeo

I checked, now everything works.

miiocli airhumidifierjsq002 --ip --token set_heater false Turning off water heater [0]

miiocli airhumidifierjsq002 --ip --token set_heater true Turning on water heater [1]

MJeka commented 2 years ago

Hi. Can you merge 1171_jsq002_support https://github.com/iromeo/python-miio.git branch with the master branch which adds support shuii.humidifier.jsq002?

--branch features/1171_jsq002_support https://github.com/iromeo/python-miio.git