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

Xiaomi Vacuum - resume clean-up after pause #471

Closed
pszafer opened this issue Jan 31, 2019 · 15 comments
Closed

Xiaomi Vacuum - resume clean-up after pause #471

pszafer opened this issue Jan 31, 2019 · 15 comments

Comments

@pszafer
Copy link

pszafer commented Jan 31, 2019

Hello,

Is it possible somehow to resume zone clean up and regular clean up?
This task is possible from Mi Home app.
I can send pause command, but with start command vacuum wants to clean everything.

@rytilahti
Copy link
Owner

This would need to know what command is being used to continue the cleaning after a pause, either by checking what miio (javascript) does if it supports this, or analyzing the traffic to see what the app does.

@pszafer
Copy link
Author

pszafer commented Feb 1, 2019

I sniffed the command:

resume_zoned_clean

so if last cleaning state was Zoned cleaning && paused:

mirobo raw-command resume_zoned_clean

I guess it is more a job for home assistant to remember state before paused...

@rytilahti
Copy link
Owner

Ok, what happens if you try to resume the cleaning with that command when it has been paused during a normal cleanup? Could you also check what does it send to resume from a regular pause?

@pszafer
Copy link
Author

pszafer commented Feb 1, 2019

During regular cleanup this command do nothing.

To resume from a regular cleanup it just send app_start, but there is some timeout I think because once it started fresh cleanup after pause...

I'm not sure how Mi Home app knows that vacuum is paused from zone clean up, but I think it is if "in_cleaning" == 2 then it is zone clean up.
At least that is what I found

This is full info sent to app during paused in zone clean up:

ver":2,"msg_seq":6023,"state":2,"battery":100,"clean_time":9,"clean_area":122500,"error_code":0,"map_present":1,"in_cleaning":2,"in_returning":0,"in_fresh_state":0,"lab_status":1,"fan_power":60,"dnd_enabled":0}]

This is how it looks like when vacuum is paused:

ver":2,"msg_seq":6707,"state":10,"battery":99,"clean_time":9,"clean_area":122500,"error_code":0,"map_present":1,"in_cleaning":1,"in_returning":0,"in_fresh_state":0,"lab_status":1,"fan_power":60,"dnd_enabled":0}]

One thing, MI Home app after restart doesn't know that vacuum is resuming clean up if you press clean.

@rytilahti
Copy link
Owner

Uhh, that's ugly.. So from the looks of it they reused the in_cleaning indeed for that, while swapping the state from "Paused" (code 10) to "Charger disconnected" (code 2).

I'm all ears if you have a proposed way to handle exposing this, my proposal:

  1. Add a new, custom state code when the state is 2 and the in_cleaning is 2.
  2. Add unpause(), which queries the current state and calls resume_zoned_clean when in_cleaning = 2, otherwise app_start as usual.
  3. Additionally, maybe add a toggle() which toggles the state automatically (after doing the checks), which can then be used directly by homeassistant.

@pszafer
Copy link
Author

pszafer commented Feb 2, 2019

So, tested it more.
Almost sure, that they are using in_cleaning == 2 for zone cleanup.
But state can be 10 as well if in zone clean up. See below (this is another pause during zone clean up):

ver":2,"msg_seq":1211,"state":10,"battery":100,"clean_time":19,"clean_area":0,"error_code":0,"map_present":1,"in_cleaning":2,"in_returning":0,"in_fresh_state":0,"lab_status":1,"fan_power":60,"dnd_enabled":0}]

So for me it is like this:

  • in_cleaning: 2 - zone clean up
  • state: 10 and send command app_state - resume from cleaning
  • state: 2 and send command app_state - start new regular clean up.

But I cannot figure timeout for this... as if app is open it always know that vacuum is paused. If I open another instance of Mi Home, then it gets state: 10, but doesn't know that vacuum was paused. Maybe they don't care resume regular clean up vs regular clean up.

So about your proposal:

  1. Add a new custom state in_zone_cleanup which query if ((state == 2 or state == 3 or state == 10 or state == 17) and in_cleaning == 2). Then from state we know if it is working or paused, but in_zone_cleanup wouldn't make the mess for state 17.
  2. Ok, but I'd call it play_unpause() because of third option below.
  3. For now homeassistant has three buttons play/pause/stop. I'd change only play/start function, so for play I'd make only one change to call play_unpause() instead of self._vacuum.start. I think it would be pretty logical and it's gonna work similar as hardware buttons on vacuum and mihome app.

@rytilahti
Copy link
Owner

But state can be 10 as well if in zone clean up.

Yeah, I think all states all also valid in the zone clean up mode. in_cleaning did not use to work in earlier firmwares (or maybe it really indicates the mode of the cleaning? So one for each regular, spot and zone?), so that's why the state itself is used in the code.

* state: 10 and send command `app_state` - resume from cleaning

My gen1 does not have app_state command, although I think more recent versions do support zone cleaning..

I created a preliminary PR to add the resume command as well as a small helper which first checks the state and runs either resume or start depending on it.

3\. For now homeassistant has three buttons play/pause/stop.

Vacuum platform provides also start_pause (https://www.home-assistant.io/components/vacuum/#service-vacuumstart_pause) which toggles the mode. This is currently not implemented, if wanted, maybe we can add a shortcut toggle() to do exactly that if needed.

rytilahti added a commit that referenced this issue Feb 3, 2019
First take on fixing #471. resume_or_start() can be used to either unpause
or start a new cleanup depending on the state of the vacuum.
rytilahti added a commit that referenced this issue Feb 3, 2019
First take on fixing #471. resume_or_start() can be used to either unpause
or start a new cleanup depending on the state of the vacuum.
@pszafer
Copy link
Author

pszafer commented Feb 3, 2019

My gen1 does not have app_state command, although I think more recent versions do support zone cleaning..

My friend has gen1 vacuum and it supports zone cleaning. I guess they added it with some firmware update.

Vacuum platform provides also start_pause (https://www.home-assistant.io/components/vacuum/#service-vacuumstart_pause) which toggles the mode. This is currently not implemented, if wanted, maybe we can add a shortcut toggle() to do exactly that if needed.

Xiaomii Vacuum component is derived from StateVacuumDevice and this class doesn't have start_pause action.

class MiroboVacuum(StateVacuumDevice):

https://github.com/home-assistant/home-assistant/blob/74cdf7c34708d5dc701ca1bf05ee375685a02541/homeassistant/components/vacuum/__init__.py#L334

@rytilahti
Copy link
Owner

My friend has gen1 vacuum and it supports zone cleaning. I guess they added it with some firmware update.

Yeah, mine supports app_zoned_clean, so the support is presumably there. Maybe app_state was added even later on then.

Xiaomii Vacuum component is derived from StateVacuumDevice and this class doesn't have start_pause action.

Good catch!

rytilahti added a commit that referenced this issue Feb 26, 2019
First take on fixing #471. resume_or_start() can be used to either unpause
or start a new cleanup depending on the state of the vacuum.
@Markkuuss
Copy link

Markkuuss commented Dec 20, 2019

I sniffed the command:

resume_zoned_clean

@pszafer can you tell me jow you sniffed out that command? I need another command for the roborock's water supply.

@pszafer
Copy link
Author

pszafer commented Dec 20, 2019

I guess I used Wireshark on phone or tcpdump on router. I don't remember now because it was so long ago, but tshark would work I think

@Markkuuss
Copy link

And then what? The command won't be in plain text in the log. How can the command be read out of the hex data? Do you remember that?

@rezmus
Copy link

rezmus commented Dec 20, 2019

@Markkuuss which command do you need?

@Markkuuss
Copy link

Markkuuss commented Dec 20, 2019

These both here:
#517 (comment)

get_water_box_custom_mode
set_water_box_custom_mode [200-203] # strength

:-) Thank you, @rezmus !

@rytilahti
Copy link
Owner

I think this should be working now, #763 fixed a corner case when the vacuum has errored. Please reopen, if this is still a problem.

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

No branches or pull requests

4 participants