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

Add support for the Xiaomi Mija Robot Vacuum 1T (dreame.vacuum.p2041) #51

Merged
merged 5 commits into from
Jul 1, 2021

Conversation

thiete
Copy link

@thiete thiete commented Jun 30, 2021

I just got this robot. The miot command set is almost identical to dreame.vacuum.p2008. Everything seems to work.

I also wanted room cleaning functionality. I have added a room_clean action for the vacuum which calls the cleaning command with the appropriate parameters to initiate targeted cleaning. The custom action definition for room cleaning in the homebridge config has to be something like:

{
"action": "room_clean",
"name": "Clean Kitchen",
"params": [
18,
"{"selects": [[4,1,1,2,1]]}"
]
}

The first parameter of 18 is passed to piid 1 and indicates room cleaning (19 would be area cleaning).
The value in the double square brackets, passed to piid 10, is then:
[[room_id, number of cleaning repetitions, vacuum power, mopping water flow, index]]
I believe multiple rooms to be cleaned can also be selected.
I got this command format from the discussion here: rytilahti/python-miio#870 (comment)

In my case the room IDs were simply 1,2,3,4 and I figured out which room they correspond to manually.

@merdok
Copy link
Owner

merdok commented Jul 1, 2021

Thanks! From what I can see everything looks clean and good! Will merge it later!
Also thanks for explaining how the room cleaning works, I was wondering that myself how the passed parameters should look like. Thou I think they look different for other devices, anyway I think I will include that info in the README.

@merdok merdok merged commit 4f6f1d2 into merdok:main Jul 1, 2021
@merdok
Copy link
Owner

merdok commented Jul 1, 2021

One more question how do you know that the room clean has two parameters? Since in the spec there is only one parameter described, only 10...

@thiete
Copy link
Author

thiete commented Jul 2, 2021

need2buy posted a comment here with some code attached. This included the function room_id_cleanup below:

    # @command(click.argument("coords", type=str, ""))
    def room_id_cleanup(self, rooms, repeats,clean_mode,mop_mode) -> None:
        """Start room-id cleaning."""
        # clean_mode = 3
        # mop_mode = 3
        cleanlist = []
        for sublist in rooms:
            if len(sublist) > 1:
                repeats = sublist[1]
            if len(sublist) > 2:
                clean_mode = sublist[2]
            if len(sublist) > 3:
                mop_mode = sublist[3]    
            cleanlist.append([ ord(sublist[0].upper()) - 64, repeats, clean_mode, mop_mode, rooms.index(sublist) + 1 ])
        payload = [{"piid": 1, "value": 18}, {"piid": 10, "value": "{\"selects\": " + str(cleanlist).replace(' ','') + "}"  }]
        return self.call_action(4, 1, payload)

I have no idea myself how the guys over at python_miot figured out the command format.

@merdok
Copy link
Owner

merdok commented Jul 4, 2021

Just as a small update, in the upcoming update i removed the ROOM_CLEAN action and instead i have added the room clean parameters to the START_CLEAN action which has the same id. I think there is no need to split it in two actions. You will need to adjust your config then when the update is out!

@thiete
Copy link
Author

thiete commented Jul 4, 2021

Thanks for cleaning up the specification for the 1T! I see I missed a few differences.
It seems the start clean action is back to how it was without the mysterious 1 parameter, but your comment implies it may be a typo?

this.addAction(RobotCleanerActions.START_CLEAN, 4, 1, [10]); // 1 parameter is not in the spec, from where comes the parameters?

I don’t mind keeping a fork of this with the action added if it’s just a hack for the one device model. It does seem like room cleaning is a desirable feature and it would be nice to see it added in a more general implementation, but it’s always going to be a bit of hassle for the user to figure out the room ids etc.
I would ultimately want to replicate the behaviour of the homebridge-Xiaomi-roborock-vacuum plug-in where you can select multiple rooms and then then the cleaning gets triggered after a small delay with the selected rooms. Not sure I have the bandwidth to implement it if I’m honest. Quite simple logic, but I would have to define some stateful “custom actions”.

@merdok
Copy link
Owner

merdok commented Jul 5, 2021

Ahhh, that is my mistake. I do not know how this slipped through. Of course I wanted to add the 1 parameter there but somehow I forgot... Will correct that in the next update!

So the action will be START_CLEAN but with the two parameters 1 and 10.

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

Successfully merging this pull request may close these issues.

2 participants