Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support device model zhimi.fan.sa1 #15

Closed
zhumuht opened this issue Jun 23, 2018 · 58 comments
Closed

Support device model zhimi.fan.sa1 #15

zhumuht opened this issue Jun 23, 2018 · 58 comments

Comments

@zhumuht
Copy link
Contributor

zhumuht commented Jun 23, 2018

Update for fan.xiaomi_smart_fan fails
下午9:48 custom_components/fan/xiaomi_miio_fan.py (ERROR)
unable to parse json '{"result":[null,null,120,468,0,"on","on",null,"on",100,74,"off",2get_down],"id":515}': Expecting ',' delimiter: line 1 column 66 (char 65)
下午9:48 /srv/homeassistant/lib64/python3.6/site-packages/miio/protocol.py (ERROR)

fan:
  - platform: xiaomi_miio_fan
    name: Xiaomi Smart Fan
    host: xxx.xxx.xxx.xx
    token: xxxxxxxxxxxxxxxxxxxxx
    model: zhimi.fan.v3

if not set model, log is:

Log Details (ERROR)
Sat Jun 23 2018 23:24:26 GMT+0800 (CST)

Unsupported device found! Please create an issue at https://github.com/syssi/xiaomi_fan/issues 
and provide the following data: zhimi.fan.sa1
@syssi
Copy link
Owner

syssi commented Jun 23, 2018

Did you block the internet access of the fan?

@zhumuht
Copy link
Contributor Author

zhumuht commented Jun 23, 2018

network is ok. maybe it is new xiaomi fan model.

https://item.mi.com/1182100014.html

_LOGGER.info("%s %s %s detected",
model,
device_info.firmware_version,
device_info.hardware_version)

log out:

zhimi.fan.sa1 1.2.9 ESP32 detected

@syssi
Copy link
Owner

syssi commented Jun 23, 2018

This model is new to me. Do you like to provide some support to get your fan integrated?

@TribuneX
Copy link

TribuneX commented Jul 4, 2018

I am having the same issue with my Xiaomi fan. I just tried to connect it to your custom component. I would be happy to support in extending this component for the new model. Which Information do you need?

@syssi
Copy link
Owner

syssi commented Jul 6, 2018

@TribuneX Could you provide the response/output of:

./mirobo --ip 192.168.132.35 --token 2a65c6b7d2351b9cda2ecfd6de6baf00 raw_command get_prop "['led', 'bat_state','temp_dec','humidity','angle','speed','poweroff_time','power','ac_power','battery','angle_enable','speed_level','natural_level','child_lock','buzzer','led_b','use_time','bat_charge','button_pressed']"

@syssi syssi changed the title Home Assistant 0.72.0 can't use Support device model zhimi.fan.sa1 Jul 6, 2018
@TribuneX
Copy link

TribuneX commented Jul 6, 2018

I changed the command to the IP of my fan and the correct token, but I got this:

Sending cmd get_prop with params ['led', 'bat_state', 'temp_dec', 'humidity', 'angle', 'speed', 'poweroff_time', 'power', 'ac_power', 'battery', 'angle_enable', 'speed_level', 'natural_level', 'child_lock', 'buzzer', 'led_b', 'use_time', 'bat_charge', 'button_pressed']
ERROR:miio.device:Got error when receiving: timed out
Error: No response from the device

I am executing this from my homeassistant docker container with mirobo at /usr/bin/mirobo. I can ping the device from within the container, so I assume miroboshould also work?

@kikamoo
Copy link

kikamoo commented Jul 9, 2018

Sending cmd get_prop with params ['led', 'angle', 'speed', 'poweroff_time', 'power', 'ac_power', 'angle_enable', 'speed_level', 'natural_level', 'child_lock', 'buzzer', 'led_b', 'use_time'] [0, 120, 277, 0, 'on', 'on', 'off', 1, 2, 'off', 0, 0, 2318]

Above params have values, others except 'button_pressed' return word, 'None'.
if I add 'button_pressed' with another params it returns error.

@TribuneX
Copy link

@syssi Can we further support you on this issue?

@syssi
Copy link
Owner

syssi commented Jul 25, 2018

@kikamoo There is no property called temp_dec or temperature?

@syssi
Copy link
Owner

syssi commented Jul 25, 2018

Some progress: rytilahti/python-miio#354 ;-)

@syssi
Copy link
Owner

syssi commented Jul 25, 2018

@kikamoo Could you provide some values of get_prop ['buzzer']? Your example contains a 0. In general the buzzer value is on or off.

@kikamoo
Copy link

kikamoo commented Jul 25, 2018

@syssi There's no hardware for temperature, that's what I heard.
Regarding 'buzzer' it returns [0] or [2] (Notification sound off / on respectively)
I don't know why 2 not 1
Sending cmd get_prop with params ['temp_dec'] [None]
Sending cmd get_prop with params ['temperature'] [None]
Sending cmd get_prop with params ['buzzer'] [0]

@syssi
Copy link
Owner

syssi commented Jul 26, 2018

Could you try to toggle the buzzer by set_buzzer ['on'] / set_buzzer ['off']? Does the device/method accept the on/off parameter? If not please try set_buzzer [0] / set_buzzer [2]

@kikamoo
Copy link

kikamoo commented Jul 26, 2018

Sending cmd set_buzzer with params ['off'] Error: {'message': 'invalid arg', 'code': -5001}
Sending cmd set_buzzer with params ['on'] Error: {'code': -5001, 'message': 'invalid arg'}

Sending cmd set_buzzer with params [0] ['ok']
Sending cmd set_buzzer with params [2] ['ok']
Sending cmd set_buzzer with params [1] ['ok']
Sending cmd set_buzzer with params [3] Error: {'message': 'invalid arg', 'code': -5001}

sending [1] or [2] turns the Notification sound ON,
[0] turns it OFF
I hope it would be helpful.

@syssi
Copy link
Owner

syssi commented Jul 26, 2018

Is the value 1 another audio volume as 2? :-)

@kikamoo
Copy link

kikamoo commented Jul 26, 2018

I could not figure it out.
When I sending [1] or [2], I just can hear the same beep sound.
And I can check the Notification sound changed to ON in MI home app.

@syssi
Copy link
Owner

syssi commented Jul 26, 2018

Alright! :-)

@ghost
Copy link

ghost commented Jul 31, 2018

When will zhimi.fan.sa1 model support be available?

@syssi
Copy link
Owner

syssi commented Jul 31, 2018

@jjongyeonglee Do you like to provide some support? There is some testing needed of the underlying library. Python skills required.

@bmwcar
Copy link

bmwcar commented Aug 1, 2018

halo sir ,i have this zhimi.fan.sa1 too.I really hope u support this fan in Hass,.You've worked hard and im so sorry i dont know the phthon. Maybe i can help u test the code in the fan.

@laynexx
Copy link

laynexx commented Aug 2, 2018

https://github.com/YinHangCode/homebridge-mi-fan can support zhimi.fan.sa1 in hb, I don't know if that does you any good.Very hope ha will be able to support SA1 as soon as possible!

@pustefix8965
Copy link

@syssi I can help with the testing, what do I need to do?

@syssi
Copy link
Owner

syssi commented Aug 3, 2018

Please install this development version of python-miio:

pip3 install https://github.com/syssi/python-miio/archive/feature/xiaomi-fan-sa1.zip -U

A new device (fansa1) will be available via miiocli now:

miiocli fansa1
Usage: miiocli fansa1 [OPTIONS] COMMAND [ARGS]...

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

Commands:                                                                                                                                                                                                                                                                                                                                                                 
  delay_off           Set delay off seconds.                                                                                                                                                                                                                                                                                                                              
  info                Get miIO protocol information from the...                                                                                                                                                                                                                                                                                                           
  off                 Power off.                                                                                                                                                                                                                                                                                                                                          
  on                  Power on.                                                                                                                                                                                                                                                                                                                                           
  raw_command         Send a raw command to the device.                                                                                                                                                                                                                                                                                                                   
  set_angle           Set the oscillation angle.                                                                                                                                                                                                                                                                                                                          
  set_buzzer          Set buzzer on/off.                                                                                                                                                                                                                                                                                                                                  
  set_child_lock      Set child lock on/off.                                                                                                                                                                                                                                                                                                                              
  set_direct_speed    Set speed of the direct mode.                                                                                                                                                                                                                                                                                                                       
  set_led             Turn led on/off.                                                                                                                                                                                                                                                                                                                                    
  set_led_brightness  Set led brightness.                                                                                                                                                                                                                                                                                                                                 
  set_natural_speed   Set natural level.                                                                                                                                                                                                                                                                                                                                  
  set_oscillate       Set oscillate on/off.                                                                                                                                                                                                                                                                                                                               
  set_rotate          Rotate the fan by -5/+5 degrees left/right.                                                                                                                                                                                                                                                                                                         
  status              Retrieve properties.

Please execute every command once and provide some feedback. Does it work properly? Do you receive an error? What's the output of the "status" method? Thanks a lot! As fat as the device is properly tested it can be merged and the Home Assistant counterpart can be implemented.

@pustefix8965
Copy link

Commands that work:
delay_off 10, off, on, set_angle 60, set_child_lock 1, set_direct_speed 88, set_led_brightness dim, set_natural_speed 88, set_rotate left.

Commands that failed:
info
ERROR:miio.device:Unable to discover a device at address 192.168.1.123 Error: Unable to discover the device 192.168.1.123
set_buzzer 0
Turning off buzzer Error: {'code': -5001, 'message': 'invalid arg'}
set_led 1
Turning on LED Error: {'code': -5000, 'message': 'method not found'}

@pustefix8965
Copy link

Also failed:
set_oscillate 0
Traceback (most recent call last): File "C:\Users\koktong\AppData\Local\Programs\Python\Python36\Scripts\miiocli-script.py", line 11, in <module> load_entry_point('python-miio==0.4.0', 'console_scripts', 'miiocli')() File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\cli.py", line 43, in create_cli return cli(auto_envvar_prefix="MIIO") File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\click_common.py", line 54, in __call__ return self.main(*args, **kwargs) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 697, in main rv = self.invoke(ctx) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 535, in invoke return callback(*args, **kwargs) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\click_common.py", line 257, in wrap msg = msg_fmt(**kwargs) TypeError: <lambda>() got an unexpected keyword argument 'oscillate'
status
ERROR:miio.fan:Count (13) of requested properties does not match the count (1) of received values. Traceback (most recent call last): File "C:\Users\koktong\AppData\Local\Programs\Python\Python36\Scripts\miiocli-script.py", line 11, in <module> load_entry_point('python-miio==0.4.0', 'console_scripts', 'miiocli')() File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\cli.py", line 43, in create_cli return cli(auto_envvar_prefix="MIIO") File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\click_common.py", line 54, in __call__ return self.main(*args, **kwargs) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 697, in main rv = self.invoke(ctx) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\click\core.py", line 535, in invoke return callback(*args, **kwargs) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\click_common.py", line 267, in wrap result_msg = result_msg_fmt.format(**kwargs) File "c:\users\koktong\appdata\local\programs\python\python36\lib\site-packages\miio\fan.py", line 83, in power return self.data["power"] KeyError: 'power'

@pustefix8965
Copy link

Didn't try "raw_command", don't know what are valid command.

@syssi
Copy link
Owner

syssi commented Aug 3, 2018

raw_command is a generic method and doesnt needs to be tested. Could you execute the "info" command again? This is also a generic method and should work out of the box.

@pustefix8965
Copy link

OK, "info" command is working too.

@pustefix8965
Copy link

@syssi Is it possible to check in the current code for support of fansa1 in this repo? I really only need to turn the fan on and off for automation.

@syssi
Copy link
Owner

syssi commented Aug 5, 2018

@reymtv Please open a new issue for this model!

@syssi
Copy link
Owner

syssi commented Aug 5, 2018

@pustefix8965 Could you provide the output of:

miiocli -d status

# and

miiocli -d raw_commaind get_prop "['led', 'angle', 'speed', 'poweroff_time', 'power', 'ac_power', 'angle_enable', 'speed_level', 'natural_level', 'child_lock', 'buzzer', 'led_b', 'use_time']"

Both commands should return the same values. You've reported status as broken.

@pustefix8965
Copy link

-d status
INFO:miio.cli:Debug mode active DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b'' DEBUG:miio.device:Got a response: Container: data = Container: data = b'' (total 0) value = b'' (total 0) offset1 = 32 offset2 = 32 length = 0 header = Container: data = b'!1\x00 \x00\x00\x00\x00\x04N\x8a\x80\x00\x10\xfc\xdd' (total 16) value = Container: length = 32 unknown = 0 device_id = b'\x04N\x8a\x80' (total 4) ts = 1970-01-13 21:15:09 offset1 = 0 offset2 = 16 length = 16 checksum = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' (total 16) DEBUG:miio.device:Discovered 044e8a80 with ts: 1970-01-13 21:15:09, token: b'00000000000000000000000000000000' DEBUG:miio.device:192.168.1.123:54321 >>: {'id': 1, 'method': 'get_prop', 'params': ['led', 'angle', 'speed', 'poweroff_time', 'power', 'ac_power', 'angle_enable', 'speed_level', 'natural_level', 'child_lock', 'buzzer', 'led_b', 'use_time']} DEBUG:miio.device:192.168.1.123:54321 (ts: 1970-01-13 21:15:10, id: 1) << {'result': ['null'], 'id': 1}
followed by the python errors I've seen earlier.

@pustefix8965
Copy link

pustefix8965 commented Aug 6, 2018

-d raw_command
INFO:miio.cli:Debug mode active Running command raw_command DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b'' DEBUG:miio.device:Got a response: Container: data = Container: data = b'' (total 0) value = b'' (total 0) offset1 = 32 offset2 = 32 length = 0 header = Container: data = b'!1\x00 \x00\x00\x00\x00\x04N\x8a\x80\x00\x10\xfc\xca' (total 16) value = Container: length = 32 unknown = 0 device_id = b'\x04N\x8a\x80' (total 4) ts = 1970-01-13 21:14:50 offset1 = 0 offset2 = 16 length = 16 checksum = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' (total 16) DEBUG:miio.device:Discovered 044e8a80 with ts: 1970-01-13 21:14:50, token: b'00000000000000000000000000000000' DEBUG:miio.device:192.168.1.123:54321 >>: {'id': 1, 'method': 'get_prop', 'params': ['led', 'angle', 'speed', 'poweroff_time', 'power', 'ac_power', 'angle_enable', 'speed_level', 'natural_level', 'child_lock', 'buzzer', 'led_b', 'use_time']} DEBUG:miio.device:192.168.1.123:54321 (ts: 1970-01-13 21:14:51, id: 1) << {'result': ['null'], 'id': 1} ['null']
No python errors.

@syssi
Copy link
Owner

syssi commented Aug 6, 2018

Please try to reduce the number of requested properties. Can you provide a working set of properties?

@syssi
Copy link
Owner

syssi commented Aug 6, 2018

# f.e.
miiocli raw_commaind get_prop "['led']"
miiocli raw_commaind get_prop "['led', 'angle']"
miiocli raw_commaind get_prop "['led', 'angle', 'speed']"
miiocli raw_commaind get_prop "['led', 'angle', 'speed', 'poweroff_time']"

@pustefix8965
Copy link

pustefix8965 commented Aug 6, 2018

Just 'led' alone is also returning ['null']. I can get angle, return [90] and also child_lock return ['off']. But if I get both angle and child_lock, I only get return of [90].

@syssi
Copy link
Owner

syssi commented Aug 6, 2018

Please remove "led" and try the other :-)

@pustefix8965
Copy link

OK, only "led" is not working, the rest are fine. As mentioned before, I am only able to get one property at a time.

@syssi
Copy link
Owner

syssi commented Aug 6, 2018

@pustefix8965 Which model do you own? Could you provide the output of "info"? The firmware version would be interesting.

@pustefix8965
Copy link

Model: zhimi.fan.sa1 Hardware version: ESP32 Firmware version: 1.3.1

@MimbaMonkeyHouse
Copy link

Are you guys managing to advance on this? Just got this fan and would be happy to help with testing!

@syssi
Copy link
Owner

syssi commented Aug 9, 2018

I will update the implementation tonight and will be happy about some more testing afterwards.

@syssi
Copy link
Owner

syssi commented Aug 9, 2018

I've pushed some fixes: pip3 install https://github.com/syssi/python-miio/archive/feature/xiaomi-fan-sa1.zip -U

I've removed the "led" property. If the status call still doesn't work I will limit the number of properties per request (to a single property). The set_buzzer and set_oscillate method should work now. Please give it a try!

@pustefix8965
Copy link

Just tested, set_buzzer & set_oscillate are working. The status is still returning error.

@syssi
Copy link
Owner

syssi commented Aug 10, 2018

The status call should be fixed now. Please try again! :-)

@pustefix8965
Copy link

New error for status:
python36\lib\site-packages\miio\click_common.py", line 267, in wrap result_msg = result_msg_fmt.format(**kwargs) AttributeError: 'FanStatus' object has no attribute 'natural_level'

@syssi
Copy link
Owner

syssi commented Aug 10, 2018

@pustefix8965 Fixed!

@pustefix8965
Copy link

I am still having the same error about natural_level, I've done the pip3 install a few times just to be sure.

@syssi
Copy link
Owner

syssi commented Aug 11, 2018

I found and fixed another issue. Try again!

@pustefix8965
Copy link

New error: AttributeError: 'FanStatus' object has no attribute 'poweroff_time'

@syssi
Copy link
Owner

syssi commented Aug 11, 2018

Okay. Another one. I will fix it tonight.

@syssi
Copy link
Owner

syssi commented Aug 11, 2018

Fixed.

@pustefix8965
Copy link

One more fix and we are good, line 271 fan.py: "Power-off time: {result.delay_off_countdown}\n"

@pustefix8965
Copy link

My output after the fix:
Power: on Battery: None % AC power: True Temperature: None °C Humidity: None % LED: None LED brightness: LedBrightness.Bright Buzzer: True Child lock: False Speed: 759 Natural speed: 0 Direct speed: 74 Oscillate: True Power-off time: 0 Angle: 90

@syssi
Copy link
Owner

syssi commented Aug 11, 2018

I will update the Home Assistant component now.

@pustefix8965
Copy link

@syssi Please also update your link for retrieving the access token. The current link is for getting the Xiaomi Gateway key, the correct link should be https://www.home-assistant.io/components/vacuum.xiaomi_miio/#retrieving-the-access-token

@syssi syssi closed this as completed in c2ecd51 Aug 11, 2018
@syssi
Copy link
Owner

syssi commented Aug 11, 2018

I've updated the custom component. Please update the custom component and make sure HA is using the latest revision of python-miio (./hass --skip-pip). Does it work out of the box?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants