Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Viomi V2 discoverable, not responding #597

Closed
BackSlasher opened this issue Dec 13, 2019 · 52 comments
Closed

Viomi V2 discoverable, not responding #597

BackSlasher opened this issue Dec 13, 2019 · 52 comments
Labels

Comments

@BackSlasher
Copy link

Firstly, thank you very much for creating this!
I have a Viomi V2 running with the Mi Home app, trying to get it to do stuff using python-miio

I extracted the token by running version Mi Home v5.4.54 on an emulator.
mirobo -d discover --handshake 1:
https://gist.github.com/BackSlasher/aa47b96c9b26bde9f67cdbf7ebe39056

However, running any command (e.g. home) seems to be ignored:
mirobo -d --ip 192.168.0.9 --token XXX home
https://gist.github.com/BackSlasher/1239ff641a0c5feddc1e6aeae654e844

This is my first Viomi device, and I'm not sure what I'm missing.
What can I collect to troubleshoot further?
Thanks!

@0sk4r
Copy link

0sk4r commented Dec 13, 2019

I also have a Viomi V2 Pro(similar model to Xiaomi styj02ym) connected to Mi Home. I got "Error: No response from the device" error message.

I extract tokens from logs of Mi Home 5.4.49 app running on BlueStacks.

SmartHome 269:[DEBUG]-12-13 23:50:44.942 processResult in result
{"code":0,"message":"ok","result": 
{"list: [{"did":"309012659", "token":"XXXXX", "longitude":"0.00000000", "latitude":"0.00000000", "name":"Viomi Cleaning  Robot", "pid":"0", "localip":"192.168.1.225", "mac":"XXXX", "ssid":"XXXX", "bssid":"XXXX", "parent_id":"", "parent_model":"", "show_mode":1, "model":"viomi.vacuum.v6", "adminFlag":1, "shareFlag":0, "permitLevel":16, "isOnline":true, "desc":"Urządzenie w trybie online ", "extra":{"isSetPincode":0, "fw_version":"3.5.3_0030", "needVerifyCode":0, "isPasswordEncrypt":0}, "uid":1773537580,"pd_id":66708, "password":"", "p2p_id":"", "rssi":0,"family_id":0,"reset_flag":0}], "virtualModels":[{"model":"zhimi.airpurifier.m1", "state":0, "url":""},{"model":"yunmi.waterpurifier.v2","state":0,"url":""},{"model":"zimi.powerstrip.v2","state":0,"url":""}]}}

mirobo -d discover --handshake 1

INFO:miio.vacuum_cli:Debug mode active
INFO:miio.device:Sending discovery to <broadcast> with timeout of 5s..
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\x12k(\xb3]\xf4\x18\xb1' (total 16)
        value = Container:
            length = 32
            unknown = 0
            device_id = b'\x12k(\xb3' (total 4)
            ts = 2019-12-13 23:03:13
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
INFO:miio.device:  IP 192.168.1.225 (ID: 126b28b3) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.device:Discovery done

Running any command with previously extracted token ends with error Error: No response from the device : https://gist.github.com/0sk4r/5e9b25a13bc93c86a603f482e0394d40

I also try to use mirobo after vacuum WiFi reset and direct connect to robot wifi. mirobo discovery return token. No other commands were working.

I think changes introduced in this PR #576 should be also working for Viomi V2 Pro because this is the same product in different brands.

@BackSlasher
Copy link
Author

BackSlasher commented Dec 14, 2019

Nice thinking @0sk4r! Sadly, it didn't work for me, BUT it produced a more meaningful error!

EDIT: Nope, this is the same result without the change :(

Repro:

virtualenv /tmp/blaa --system-site-packages
cd /tmp/blaa
bin/pip install git+https://github.com/rytilahti/python-miio

Actual hunting:

$ bin/mirobo discover
INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
WARNING:miio.discovery:Found unsupported device viomi-vacuum-v6_miio277939356._miio._udp.local. at 192.168.0.9, please report to developers
$ bin/mirobo discover --handshake 1
INFO:miio.device:Sending discovery to <broadcast> with timeout of 5s..
INFO:miio.device:  IP 192.168.0.9 (ID: 1091049c) - token: b'ffffffffffffffffffffffffffffffff'
INFO:miio.device:Discovery done

Not sure if we should change some config to explain to miio what to do with this vacuum.

@BackSlasher
Copy link
Author

Retrying again without system packages and explicit master version didn't help:

virtualenv /tmp/bli
cd /tmp/bli
bin/pip install git+https://github.com/rytilahti/python-miio@master
...

@polysa
Copy link

polysa commented Jan 10, 2020

Hello Guys

Did you managed to make it work?

@rytilahti
Copy link
Owner

That device uses a different protocol than the rockrobo ones, so mirobo tool cannot currently be used with it. If someone wants to extend it to support the viomi ones, please feel to make a PR for it. For the time being miiocli viomivacuum can be used for basic controls.

In order to use this in homeassistant, the homeassistant integration needs to be updated to allow defining which protocol to use (rockrobo or viomi). Feel free to make a PR in homeassitant's repository for that, too!

@oktonion
Copy link

oktonion commented Jan 10, 2020

@rytilahti
miiocli viomivacuum seems to not work either

miiocli viomivacuum --ip 192.168.0.9 --token xxx info
ERROR:miio.device:Got error when receiving: timed out
Error: No response from the device

However it responds to ping ( 43 ms).

firmware is 3.5.3_0045

@rytilahti
Copy link
Owner

The token is most likely wrong then, did you extract it from your mobile device after the initial provisioning?

@BackSlasher
Copy link
Author

I personally can't confirm whether it's wrong or right. However, I extracted it from a mobile emulator after logging in to my account

@oktonion
Copy link

oktonion commented Jan 12, 2020

The token is most likely wrong then, did you extract it from your mobile device after the initial provisioning?

The token is right.
It is same for:

  1. Mi Home modded application on android.
  2. iPhone backup, from decrypted ZTOKEN in 4169293468_mihome.sqlite base.
  3. iPhone backup, with miio-extract-tokens from 4169293468_mihome.sqlite base.

What else could I do?

@silentkiller88
Copy link

The token is most likely wrong then, did you extract it from your mobile device after the initial provisioning?

The token is right.
It is same for:

  1. Mi Home modded application on android.
  2. iPhone backup, from decrypted ZTOKEN in 4169293468_mihome.sqlite base.
  3. iPhone backup, with miio-extract-tokens from 4169293468_mihome.sqlite base.

What else could I do?

It might be the same issue as this one: #550 (comment)

If you turn off the device and turn it on again, are you able to run miiocli viomivacuum --ip 192.168.0.9 --token xxx info ?
Or: If you increase the retry_count in device.py from 3 to 20, are you able to run miiocli viomivacuum --ip 192.168.0.9 --token xxx info?

@oktonion
Copy link

"Have you tried turn it off and on again?" method worked for me with combination of retry_count=20 in device.py and self._timeout=0.5, timeout=0.5. Also helped to remove the device from docking station and connect to it with MiHome App again.
It is so unstable and buggy but it works from time to time.
@silentkiller88 many thanks!

@silentkiller88
Copy link

silentkiller88 commented Jan 16, 2020

"Have you tried turn it off and on again?" method worked for me with combination of retry_count=20 in device.py and self._timeout=0.5, timeout=0.5. Also helped to remove the device from docking station and connect to it with MiHome App again.
It is so unstable and buggy but it works from time to time.
@silentkiller88 many thanks!

@rytilahti I think that for the viomi v2 as well as the styj02ym have the same problem (same hardware). The issue is that the software needs a lot of retries before it gets a valid response from the robot.
Do you want me to create a new issue for this? I think that this issue says it all (discoverable but not responding)

@rytilahti
Copy link
Owner

@silentkiller88 my understanding of the problem is that the device does not respond to request using an already used (or lower than the "current") msgid; this needs to be fixed in miiocli, feel free to open a PR for it.

For API users this should not be a problem as the id is automatically incremented in the background, it is just that miiocli is not saving the most recently used id for next invocation.

@BackSlasher
Copy link
Author

I'm still not getting any luck, but I'm not sure my token was legit, because I got it from an emulator running mihome 5.4.54.
Will try with a real phone.

However, I'm encouraged by you succeeding, because it means Viomi isn't inherently uncooperative with miio :)

@BackSlasher
Copy link
Author

I ran tcpdump on my router and redirected to wireshark so I can see how the app is communicating, hopefully confirming my token.
However, I found that the app was communicating from the outside (packets were coming from an IP in Singapore) and with a different port (35764)
I'm attaching some pcaps so you can see if they make any sense:
From the app: vimoi-fromapp.zip
From the Python lib:
viomi-frompython.zip

I tried decoding the messages by running this:

from miio.miioprotocol import Message
import codecs
str="21310020000000001091049c5e221c923938f4a7e559812246d0108b856b134f"
# str="213100f0000000001091049c5e221ca2e3e0ceb2f4c9f8babe94999157efddb6ae99e0b14b6b76216d6ceb900bd943cd57c00f9bc67addb710ca3082696baa11b21d92ae6987bd8de058ac0328add82d4f7f96e08957bf67e4d0a14f8d256c6f6141682826a471c1aa46468b80530e7712c9d012b7d33da09fc596153373acdb2aa8fdcc058140ca9daed1f8b462d00da6b26063450a84f720c3c02f39a871907d2427585eb8e79909c9529fc6ad6602661866037d032695778fbe528378d6af12c2585f1064f13483dd5c794139fb4dc3f64695f7d80509507db93f29b5fd3fe613e4d250348a1dd36523023c8d678d"
codecs.decode(str, "hex")
token=b"5736417473416662386c63683136716c"
Message.parse(codecs.decode(str, "hex"), token=token)

The short message parses successfully, but the long one insists I have the wrong checksum:

wrong checksum, read b'e3e0ceb2f4c9f8babe94999157efddb6', computed b'8bda6dc83a8231eb8245c80bc6ac9b31'

I'm aware my token is there, and if anyone wants to remote control my vacuum, idgaf. I'll re-pair it in a bit.

What do you pros make of it?

@BackSlasher
Copy link
Author

Generated a new token with the bluestacks method (here) and with the same disappointing results.

@BackSlasher
Copy link
Author

Did some more testing. The bluestacks token seems legit, but no go.

info sometimes works:

$ venv/bin/mirobo --ip 192.168.0.9 --token REDACTED info
viomi.vacuum.v6 v3.5.3_0030 (50:EC:50:EE:A6:F3) @ 192.168.0.9 - token: REDACTED

running inspect on the NPM version works:

~/projects/python-miio$ /tmp/blu/node_modules/.bin/miio inspect 192.168.0.9
 INFO  Attempting to inspect 192.168.0.9

Device ID: 277939356
Model info: viomi.vacuum.v6
Address: 192.168.0.9
Token: REDACTED via stored token
Support: At least generic

Type info: miio
Capabilities: 

Firmware version: 3.5.3_0030
Hardware version: Linux

WiFi: REDACTED RSSI: 

Remote access (Mi Home App): Maybe

However, running home on sound --test never works:

~/projects/python-miio$ venv/bin/mirobo --ip 192.168.0.9 --token REDACTED home
ERROR:miio.miioprotocol:Unable to discover a device at address 192.168.0.9
Error: Unable to discover the device 192.168.0.9
~/projects/python-miio$ venv/bin/mirobo --ip 192.168.0.9 --token REDACTED home
ERROR:miio.miioprotocol:Got error when receiving: timed out
Error: No response from the device

Will be happy to provide whatever dumps can further help - tcpdumps, debug prints etc.

@polysa
Copy link

polysa commented Jan 18, 2020

Ok so I followed this guide

I successfully added the Viomi V2 Pro to Home Assistant.

In order to get the Token I used a Russian hacked MI Home app for android. Let me know if you need the link.

@BackSlasher
Copy link
Author

@polysa that'd be great.
Could you also provide please:

  1. The relevant bit from your configuration.yaml
  2. Your vacuum's firmware version (I got it from the npm lib miio)
  3. What order did you do things (e.g. did you remove the vacuum from mii home and add it using the Russian app, did you use an emulator etc)

Thanks!

@polysa
Copy link

polysa commented Jan 19, 2020

@BackSlasher Here we go:

Direct link to apk
Source website
custom_components for Home Assistant

My conficuration.yaml:

# Xiaomi Vacuume
vacuum:
  - platform: miio2
    host: 192.168.*.*
    token: Your-token
    name: Viomi

firmware Version: 3.5.3_0030

Steps:
Uninstall the MI Home
Install the modified RU Version
Login Normally
Your Viomi should be listed
Go-to your Vacuum -> Three dots on the top right -> Additional Settings -> Network Info -> Token

@BackSlasher
Copy link
Author

Are you sure about this platform? I got this error when trying to use miio2:

Jan 19 09:52:16 venus hass[20259]: 2020-01-19 09:52:16 ERROR (MainThread) [homeassistant.config] Platform error: vacuum - Integration 'miio2' not found.
Jan 19 09:52:16 venus hass[20259]: 2020-01-19 09:52:16 INFO (MainThread) [homeassistant.setup] Setting up vacuum

@polysa
Copy link

polysa commented Jan 19, 2020

@BackSlasher
Copy link
Author

Looks promising! Will check once I'm home, thanks :D

@BackSlasher
Copy link
Author

@polysa works! It doesn't support everything (e.g. I can't get the room map) but "start" and "return to base" work.
@rytilahti I completely appreciate if this is out of your scope, but it might be interesting to understand the difference that nqkdev/home-assistant-vacuum-styj02ym applies when communicating and "merge" it to your lib.
We can close this, I think.

@polysa
Copy link

polysa commented Jan 20, 2020

@BackSlasher

You can send commands to change mode or to clean a particular room.
We can work together to create a custom card in HA so we can control the Vacuum and pass correct settings. If you are available please let me know.

@rytilahti
Copy link
Owner

@BackSlasher that's not out of scope, so no worries. The (most?) of the communication parts are already contained in this library, it is merely that the homeassistant integration has to be updated accordingly to select the model to use for communication. Or that is my current understanding at the moment, I haven't really dug into the code to see if something else needs to be implemented in this library. If there is a need to extend the support, PRs are more than welcome to do so :-)

@BackSlasher
Copy link
Author

@polysa what I'm struggling to do currently is to get a lit of the rooms. I can't seem to use "send_command" to run get_room_mapping successfully.

@BackSlasher
Copy link
Author

@rytilahti great. I'm not sure what exactly is the difference, but the python-miio provider doesn't seem to work at all and miio2 worked from the first second. I'll dig around after I find out how to get a list of rooms :)

@polysa
Copy link

polysa commented Jan 21, 2020

@BackSlasher

all Supported commands can be found: rytilahti/python-miio#550 (comment)
Some of the parameters is documented here
rytilahti/python-miio@57c1009

I managed to send clean command for particular rooms. But I tested the numbers manually.

@BackSlasher
Copy link
Author

Good stuff! Did you manage to run arbitrary commands via home assistant, e.g.

curl -X POST -H "Authorization: Bearer REDACTED" -H "Content-Type: application/json" https://HASS:8123/api/services/vacuum/send_command -d '{"entity_id": "NAME", "command": "get_prop", "params": ["cur_mapid"]}'

?

Your links seem very insightful, will go through them later :)

@polysa
Copy link

polysa commented Jan 21, 2020

@BackSlasher actually no I just run some commands from Developer Tools / Services and setup basic automatons to Vacuum / mob my flat.

Choosing the program is easy:
command: set_mode
params: 1 -> mob/vacuum 0 -> just vacuum

@polysa
Copy link

polysa commented Jan 22, 2020

@BackSlasher

for the map maybe this can help.

@MacieIKS
Copy link

MacieIKS commented Feb 5, 2020

Hi,
I encountered a problem, let me describe. Token was extracted using Android modded (RU) MiHome app 5.6.50. Further test on fresh Raspbian.

Results:
Using "mirobo" Viomi V2 Pro is classfied as "v6" version, where I saw somewhere it's clone Xiaomi STYJ02YM is classfied as viomi.vacuum.v7.

pi@raspberrypi:~ $ mirobo discover
INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
WARNING:miio.discovery:Found unsupported device viomi-vacuum-v6_miio309159813._miio._udp.local. at 192.168.0.42, please report to developers
pi@raspberrypi:~ $ mirobo --ip 192.168.0.42 --token xxxx status
ERROR:miio.miioprotocol:Got error when receiving: timed out
Error: No response from the device

Using "miiocli" I was able to get data.

pi@raspberrypi:~ $ miiocli viomivacuum --ip 192.168.0.42 --token xxxx status
State: ViomiVacuumState.Idle
Mode: 0
Error: None
Battery: 42
Fan speed: ViomiVacuumSpeed.Silent
Box type: 1
Mop type: 0
Clean time: 0:00:00
Clean area: 0
Water level: 11
Remember map: True
Has map: True
Has new map: False
Mop mode: ViomiMopMode.Off

I was able to start / stop also, however after 10-15 mins something breaks and I am not able to fetch data anymore until I manualy powercycle Viomi.

pi@raspberrypi:~ $ miiocli viomivacuum --ip 192.168.0.42 --token xxxx info
ERROR:miio.miioprotocol:Got error when receiving: timed out
Error: No response from the device

Any ideas what this can be? Appreciate if someone could help me with this topic / integration, I can provide outputs which are needed. My target is to run it on Domoticz :).

Thank you,
Cheers

@rytilahti
Copy link
Owner

See my earlier response above: #597 (comment) . If you are using miiocli from domoticz, the issue is repeated use of msgids in that tool.

@NazarKosteckij
Copy link

I suppose that thre is a different password.
Does enyone know where the documentation can be found

@BackSlasher
Copy link
Author

@polysa coming back to this, did you find a way to clean a specific room?
Tried copying from #550, but the best I could come up with is miio protocol call IPISHERE set_mode_withroom '[0, 1, 1, 4]' to clean room 4, which prints

 INFO  Got result:
[
  "ok"
]

and causes the vacuum to leave the dock and immediately return

@polysa
Copy link

polysa commented Apr 11, 2020

@BackSlasher

Here is a script am using for cleaning my dinning room:

`vacuum_dinningroom:
alias: Clean Dinning Room
sequence:

  • data:
    command: set_mode_withroom
    params:
    • 0
    • 1
    • 1
    • 11
      entity_id: vacuum.viomi
      service: vacuum.send_command`

I had to test manually the code for each room. My rooms start from number 10 and up.

The latest firmware update that support multi level floor maps make the Viomi unusable and I can't find a way to roll back :(

@BackSlasher
Copy link
Author

Don't install latest firmware, gotcha :)
Will iterate over room numbers. So far the Vacuum is still leaving and immediately returns :)

@polysa
Copy link

polysa commented Apr 12, 2020

Don't install latest firmware, gotcha :)
Will iterate over room numbers. So far the Vacuum is still leaving and immediately returns :)

The process to identify the rooms was:

  1. make sure not to rename the rooms in the app.
  2. My dinning room was labeled 1 in the app. so I in HA is 11

room 2 will be 12 and so on. I am not sure about the pattern here but it is working for me.

Stay away from firmware 3.5.8_0033 I will let you know once I recieve the new bug free firmware.

@BackSlasher
Copy link
Author

BackSlasher commented Apr 12, 2020

I figured this would be my process. I didn't rename rooms, just merged them, but I see some weird inconsistencies (I think that room 11 in the API is "room4" in UI.
However it seems room 15 is room5, so there is still a lot of mystery :)

EDIT: room 15 in API is actually room8 in UI. Amazing

image

@polysa
Copy link

polysa commented Apr 12, 2020

Ok just remembered you need to send the vacuum to dock before each test. So if you send using command from dock to room 1(11) you need to dock before send it to room 2 (12).

@BackSlasher
Copy link
Author

BackSlasher commented Apr 12, 2020

Yeah, I'm on that. I think the UI is reusing the lowest roomid, but API is not. So due to massive re-editing to the rooms I did, the numbers don't match.

11 = room4
15 = room8
18 = room3
19 = X
20 = X
21 = X
22 = room0

This is my mapping so far. Exciting, I know.

EDIT: Done with mapping! Good stuff :)

@polysa
Copy link

polysa commented Apr 12, 2020

Perfect. They only think I am missing from my setup in HA is the live map. Probably I will start working on that now I'm stuck home.

@BackSlasher
Copy link
Author

Nothing better to do now than obsess on home automation :)

@BackSlasher
Copy link
Author

BTW, I think a map would be really hard, unless you're rooted. I'm afraid of rooting my device since I can't seem to make my adb port work.

@crazykiwi2003
Copy link

See my earlier response above: #597 (comment) . If you are using miiocli from domoticz, the issue is repeated use of msgids in that tool.

@BackSlasher @polysa : it seems like almost everything is working for you!? I am stuck with the message ID bug - how did you fix that problem?

@BackSlasher
Copy link
Author

@crazykiwi2003 I verified my token using the npm version of miio, and using it to issue commands to the device.
The Python one I'm only using in conjunction with homeassistant using the miio2 solution mentioned in #597 (comment)
Once you have an integration with HASS properly working, you can use the service there (vacuum.send_command to send stuff to the vacuum with a lesser chance of msgid conflict.
The downside to using the service is that you don't get to see the response - only observe the vacuum and see if it's doing anything interesting.
Here is a command you can use to see if the basic communication to the vacuum is working

miio protocol call IPIPIPIPIP get_prop '["mode"]'

For me, it returns

 INFO  Attempting to call get_prop on IPIPIPIPIP

 INFO  Device found, making call

 INFO  Got result:
[
  0
]

@bordino
Copy link

bordino commented Apr 13, 2020

Hello
I have a viomi v2 pro and I installed the update yesterday 3.5.8_0034 everything went well except that there is no longer washing in Y, it washes only in S.
How to put the wash back in Y, please?

Firmware 3.5.8_0034
E60FC0FD-EB82-4FD9-8545-30737F59DE51

Firmware 3.5.3_0030
CB898838-3A12-4362-9AF3-43042FB88E33

Best regards

@polysa
Copy link

polysa commented Apr 13, 2020

You can't. this is a bug. Please this topic is for Home Assistant integration with python-miio. Contact Viomi from Facebook.

@bordino
Copy link

bordino commented Apr 13, 2020

You can't. this is a bug. Please this topic is for Home Assistant integration with python-miio. Contact Viomi from Facebook.

okay i'm sorry, thanks. their facebook is "viomi tech", please?

@polysa
Copy link

polysa commented Apr 13, 2020

You can't. this is a bug. Please this topic is for Home Assistant integration with python-miio. Contact Viomi from Facebook.

okay i'm sorry, thanks. their facebook is "viomi tech", please?

Yes correct

@BackSlasher
Copy link
Author

Closing this, because I got my answers. @polysa please CC me when you have interesting progress :)

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

No branches or pull requests

10 participants