rytilahti / python-miio

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

Add support for Dreame D9 Robot Vacuum (dreame.vacuum.p2009) #870

Closed bigdx closed 1 year ago

bigdx commented 3 years ago

The Dreame D9 Robot Vacuum is launched in Europe and has some interesting specs and feature.

Device information:

Additional context As there is already the miot-spec out there (http://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:vacuum:0000A006:dreame-p2009:1) it should be possible to add support?! As I am new to this, I have no Idea where to start, but would like to contribute (when my robot arrives ^^)

rytilahti commented 3 years ago

I wouldn't be surprised if this shares similarities with p2008 (WIP PR #683) or some other dreame vacuums (#812).

bigdx commented 3 years ago

I wouldn't be surprised if this shares similarities with p2008 (WIP PR #683) or some other dreame vacuums (#812).

That would be great! And if I havent missed some critical point, it seems not THAT hard to get this done. By getting the commands from miot-spec you can write py-functions to controll the bot ... and hide that behind a nice UI ;-)

Slightly off-topic, but does the bot have to be conected to the internet to receive those "locale" commands?

rytilahti commented 3 years ago

That would be great! And if I havent missed some critical point, it seems not THAT hard to get this done. By getting the commands from miot-spec you can write py-functions to controll the bot ... and hide that behind a nice UI ;-)

Yes, there is a script in devtools directory for that purpose. It takes a miot-spec json as input and generates a template that can be used to add support for new devices. It is still heavily work in progress, as is the whole architecture to support miot devices in a future-proofed way.

Slightly off-topic, but does the bot have to be conected to the internet to receive those "locale" commands?

No idea, sorry. It really depends on the device, but at the moment I cannot recall issues regarding to blocking the internet access, outside https://python-miio.readthedocs.io/en/latest/troubleshooting.html#intermittent-connection-issues-timeouts-xiaomi-vacuum .

JLink-1 commented 3 years ago

Hi guys,

is there already something new regarding this robot? I got this model last week and would like to implement it into home assistant.

bigdx commented 3 years ago

Hi guys,

is there already something new regarding this robot? I got this model last week and would like to implement it into home assistant.

Caused by (the pandemic- and the holiday-caused ^^) lockdown I had not much time yet. I tried to capture the commands of the App with wireshark, but had no luck. I guess a stupid little issue but my brain was just to lazy from all the eating to see it ;-) Would be nice if someone could try that too.

Yes, there is a script in devtools directory for that purpose. It takes a miot-spec json as input and generates a template that can be used to add support for new devices. It is still heavily work in progress, as is the whole architecture to support miot devices in a future-proofed way.

As soon as possible i'll try that.

No idea, sorry. It really depends on the device, but at the moment I cannot recall issues regarding to blocking the internet access, outside https://python-miio.readthedocs.io/en/latest/troubleshooting.html#intermittent-connection-issues-timeouts-xiaomi-vacuum .

Sounds promising. Strange, I searched like crazy for such informations but no luck. Thats why I like to "ask" stuff, humans are much better search-engines ;-)

patrik-dev commented 3 years ago

Any news at this issue? I have a d9 too and it would be very nice if I could control it with oh and Alexa :)

GizmoLibre commented 3 years ago

I have a Dreame D9 and it does work with Home Assistant. Just follow a post from Hyyd1e here for support for F9, apparently this works for D9 too - https://community.home-assistant.io/t/support-for-xiaomi-dream-f9-mop-vacuum/220858/14 dreame d9

spider54 commented 3 years ago

Hello, I managed to add my D9 vacuum cleaner in HA, but I cannot recover the card to order the vacuum cleaner by zone or by room. have you succeeded? thank you

GizmoLibre commented 3 years ago

Hi. Unfortuanely, no, i haven't. It seems kinda tricky to set up, it involves extracting the coordinates for rooms or zones, and making the scripts to incorporate them in the card. I was trying to read up on the procedure for Xiaomi Mijia 1C which is similar to Dreame D9, but i didn't have the time to actually do it. You can find the discussion here https://community.home-assistant.io/t/xiaomi-mijia-1c-sweeping-vacuum-cleaner-white-stytj01zhm/185089/95 , let me know if you succeed.

marcelrv commented 3 years ago

If the format is similar to the roborock models you can use this tool to extract coordinates from the map

https://community.openhab.org/t/xiaomi-vacuum-map-viewer-to-find-coordinates-for-zone-cleaning/103500

spider54 commented 3 years ago

Thank you, I use for my Roborock S5, and it works very well. https://github.com/PiotrMachowski/Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor but it does not work with my Dreame D9. How can I use Marcel Verpaalen's software with Home Assistant? How to get the rrmap? from Xiaomi Home?

pergolafabio commented 3 years ago

To extract coordinates, you need to download that customized xiaomi .apk, it will create a log file on android with the coordinates, from there you can use them in your scripts... It's discussed on the community forums

spider54 commented 3 years ago

Thanks pergolafabio, where can I download this apk?

pergolafabio commented 3 years ago

There was link posted on the forums, let me know if you can't find it, I have it also local...

spider54 commented 3 years ago

Difficult to find without knowing the exact name of the file! If you have a link, thank you.

Chrischi- commented 3 years ago

MiHome_6.1.700_63410_vevs.apk or google „kapiba mihome“.

The file will surely infringe some copyright and so I didn't want to post the direct link.

spider54 commented 3 years ago

Thanks, great, I found it.

spider54 commented 3 years ago

Hello, I installed the apk but I don't see how to recover the card !!

pergolafabio commented 3 years ago

It's not possible to extract map , only coordinates that are in a log file

spider54 commented 3 years ago

And how do we get the coordinates? Where is this log file?

pergolafabio commented 3 years ago

Look here, you need to manually create the folder first, then start a normal clean, it will create a file then... Then stop the clean, and then just start with your coordinate cleaning...

https://community.home-assistant.io/t/xiaomi-mijia-1c-sweeping-vacuum-cleaner-white-stytj01zhm/185089/118?u=pergola.fabio

spider54 commented 3 years ago

Thank you pergolafabio, I had to create the 3 directories as indicated, I got a file, but I don't really see any coordinates.

GizmoLibre commented 3 years ago

Same for me, i cannot find them with the log file method. Nothing in there resembles to the coordinates as for the other Xiaomi vacuums, so i guess Dreame D9 shows them in a like a different value or something. Also, even if i found and extracted them, i cannot use them anyway, since the vacuum.send_command is giving me "failed to call service". So using it with the F9 method i linked only gets you so far. Someone with the higher knowledge and D9 needs to work on this, if we want to make zone cleaning and live maps available.

spider54 commented 3 years ago

thank you, I came to the same conclusion.

rezmus commented 3 years ago

search for something like this

"siid":4,"aiid":1,"in":[{"piid":1,"value":19},{"piid":10,"value":X}]

X contains json with areas. i'm pretty sure d9 uses same cmd for room/zone clean as f9.

spider54 commented 3 years ago

Thank you for your help. An extract of my file compared to your indication, but I do not see what to recover! 2021-02-06 13:51:53 -> {"id":4531,"method":"action","params":{"did":"382836526","siid":6,"aiid":1,"in":[{"piid":2,"value":"{\"req_type\":1,\"frame_type\":\"I\"}"}]}} 2021-02-06 13:52:06 -> {"id":4534,"method":"action","params":{"did":"382836526","siid":4,"aiid":1,"in":[{"piid":1,"value":18},{"piid":10,"value":"{\"selects\":[[5,1,0,2,1]]}"}]}}

pergolafabio commented 3 years ago

Are you starting a room cleaning? Or are you drawing an rectangle? Room cleaning commands are not supported yet i think

rezmus commented 3 years ago

1/18 is room clean which uses array of selects (rooms) in this format

var selectInfo = [];

for (var areaId in selectAreas) {
  var _item = selectAreas[areaId];

  if (_item) {
    var newData = [parseInt(_item), _this.state.selectNum, _this.state.cleaningMode, _this.state.mopMode, Number(areaId) + 1];
    selectInfo.push(newData);
  }
}

var selectData = {
  "selects": selectInfo
};

1/19 is zone/area clean.

spider54 commented 3 years ago

pergolafabio I do a room cleaning. Thank rezmus I did not understand everything, I am a beginner. In the example I set, the part number is 18, is that it?

need2buy commented 3 years ago

Same for me, i cannot find them with the log file method. Nothing in there resembles to the coordinates as for the other Xiaomi vacuums, so i guess Dreame D9 shows them in a like a different value or something. Also, even if i found and extracted them, i cannot use them anyway, since the vacuum.send_command is giving me "failed to call service". So using it with the F9 method i linked only gets you so far. Someone with the higher knowledge and D9 needs to work on this, if we want to make zone cleaning and live maps available.

same experience. It seems vacuum.send_command does not work correctly Dreame D9.

rezmus commented 3 years ago

are you using f9 integration? zone cleaning in f9/d9 has different command than 1c.

GizmoLibre commented 3 years ago

In my case, I tried it both, with xiaomi_vacuum.vacuum_clean_zone and vacuum.send_command. First one says: Failed to call service xiaomi_vacuum/vacuum_clean_zone. 'DreameVacuum' object has no attribute 'zone_cleanup'. So i guess the dreamevacuum.py (the one we replaced with one suited for F9) inside config\custom_components\xiaomi_vacuum needs to be updated with the proper code or something, i really have no experience in this area.

pergolafabio commented 3 years ago

9are you guys actually using the custom component for zone cleaning? because there is one specific for D9 and F9

pergolafabio commented 3 years ago

i believe this one for D9 : https://github.com/Concentricc/xiaomi_vacuum and this one for F9 (using myself) : https://github.com/microfrost1/xiaomi_vacuum

pergolafabio commented 3 years ago

i am using this command for F9, works perfect

dreame_clean:
  alias: Boven stofzuigen
  sequence:
  - service: xiaomi_vacuum.vacuum_clean_zone
    data:
      entity_id: vacuum.dreame
      zone: -1951,-6352,10160,2788
      repeats: 1
rezmus commented 3 years ago

don't use 1c integration. d9/f9 has same command for zone/room cleanup. use f9 if you can't find d9.

need2buy commented 3 years ago

Thanks pergolafabio. Your suggestion works like a champ. Now i am working to get the coordinates maps out.

GizmoLibre commented 3 years ago

Yaaay, success. Thanks pergolafabio, you are the champ. The problem was indeed that i was using the wrong custom component, the one by Concentricc is actually not suitable for D9, but the microfrost1 works (i was using Concentricc), so no more issues with xiaomi_vacuum.vacuum_clean_zone.

I also managed to dig out the coordinates, they are tough to find. In the log, search for the word areas . My entry in the log looked like this after i drew a zoned clean rectangle for my kitchen in the cracked Mi Home app:

2021-02-10 05:53:00 -> {"id":5960,"method":"action","params":{"did":"382834556","siid":4,"aiid":1,"in":[{"piid":1,"value":19},{"piid":10,"value":"{\"areas\":[[-1117,3105,1235,8338,1,0,2]]}"}]}}

So, you take only that four points that i bolded, i have no clue what the next three ones are. Worked like a charm, cleaned the kitchen going all the way near the walls, like it would do from the regular Mi Home app, so i am happy.

Next thing to do, we need to find out how to make multiple zoned cleans work. For example, what i do from the Mi Home app is that i pick Room, select Kitchen first, and Living Room second, so the vacuum goes in that order of cleaning, before returing to the dock.

I would also like the map functionality to work, like the people use xiaomi_vacuum_map_card for the other models, that is very nice option to have, having a map in HA, so you can see where the robot is. Maybe too much to ask, but at least we made progress for zone cleaning to work :) Thanks again.

spider54 commented 3 years ago

thank you for your feedback, I'm trying this evening.

pergolafabio commented 3 years ago

@GizmoLibre indeed room cleaning + map extracting is a nice plus, maybe for later

what i do if i want to clean multiple zones, i make a script to clean 2 zones, with a delay between it... the delay is the amount of time that should be suffecient for zone 1

allthough fot the official vacuum you can define a lists of zones... i dont know if that works too for this custom, i never tried it...

https://www.home-assistant.io/integrations/xiaomi_miio/#service-xiaomi_miiovacuum_clean_zone

let us know :)

rezmus commented 3 years ago

d9/f9 support multiple zones.

{"areas":[[zone1],[zone2],[zone3]]}

each zone record is [x1,y1,x2,y2,zone_number,clean_mode,mop_mode]

pergolafabio commented 3 years ago

perfect

btw, did anyone already recieved a firmware for this daughter brand of xiaomi? seems 1C is getting updates, and dreame f9/d9 not?

rezmus commented 3 years ago

f9 had already 2 updates (3.5.8_1039) and d9 had 1 (3.5.8_1072).

pergolafabio commented 3 years ago

ah ok, i already have indeed 3.5.8 1039 , but that was from 2 months ago? i dont know the history since i have it like 2 months but now seems 1C is getting again new firmwares , are they not the same?

rezmus commented 3 years ago

last update for f9 was in november. don't expect updates every month. 1c got new fw 1096 (backporting room clean from f9) after 9 months since previous 1059.

GizmoLibre commented 3 years ago

I will try to play with multiple zones, gonna report back. Yea, we had one firmware update 3.5.8_1072 on December 28th for the D9, the next one that brings multiple floor maps is coming this month, according to a representative on Ozbargain website.

pergolafabio commented 3 years ago

ok, good to know

i am not that happy with F9, probaly since there is no camera, sometimes its just not able to find a zone, if i want to clean another room, while the path is quite easy my S50 works way better probably the D9 too

need2buy commented 3 years ago

Couple of services do not work when I tried to use them

service: vacuum.start_pause >>>> not working so we can't resume the zone clean service: vacuum.start >>>> will abort the current zone clean and start a full clean service: vacuum.send_command >>> does not work

Many more, but I see these should be working so we could use this integration more effectively.

need2buy commented 3 years ago

Couple of services do not work when I tried to use them

service: vacuum.start_pause >>>> not working so we can't resume the zone clean service: vacuum.start >>>> will abort the current zone clean and start a full clean service: vacuum.send_command >>> does not work

Many more, but I see these should be working so we could use this integration more effectively.

spider54 commented 3 years ago

My D9 is now working fine by zone, thank you.