PiotrMachowski / Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor

This custom integration provides a way to present a live view of a map for Xiaomi (Roborock/Viomi/Roidmi/Dreame) vacuums without a need for rooting.
MIT License
1.17k stars 124 forks source link

Add Lydsto W2 path support #419

Open Cheerpipe opened 1 year ago

Cheerpipe commented 1 year ago

Description

Xiaomi Map Extractor shows Lydsto W2 map and current position but not the vacuum path.

Vacuum path is shown in Xiaomi Home.

map_data_zhimi.vacuum.w2.gz

Solution

I want Xiaomi Extractor show vacuum path as in Xiaomi Home App...if possible.

Alternatives

No response

Context

No response

PiotrMachowski commented 1 year ago

Can you show your config of Map Extractor?

Cheerpipe commented 1 year ago

Can you show your config of Map Extractor?

Thanks for your blazing fast response.

Sure:

camera:      
 - platform: xiaomi_cloud_map_extractor
   name: Lydsto W2 Roidmi
   host: 0.0.0.0
   token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   scan_interval: 5
   username: XXXXXXXXXXX
   password: XXXXXXXXXXX
   draw: ['all']
   country: us
   force_api: roidmi # not really necessary
   attributes:
     - calibration_points
   map_transformation:
    rotate: 90
   store_map_raw: true
   store_map_path: "/config"

I also tried with force_api xiaomi, viomi and dreame. Map is shown only with auto or dreame. I can also view vacuum current position in realtime in the map.

PiotrMachowski commented 1 year ago

I have checked your map data and it doesn't contain path nor vacuum position. It's possible that they are downloaded in a separate request to the Cloud.

You can inspect the data by yourself - roidmi maps can be opened with any text editor (after unpacking gz) as all map data is available in JSON format at the end of the file

Cheerpipe commented 1 year ago

I have checked your map data and it doesn't contain path nor vacuum position. It's possible that they are downloaded in a separate request to the Cloud.

You can inspect the data by yourself - roidmi maps can be opened with any text editor (after unpacking gz) as all map data is available in JSON format at the end of the file

Xiaomi Map Extractor is reporting the vacuum position i real time while it is working, If this data isn't in the map file, ¿Where may be this data coming from?

PiotrMachowski commented 1 year ago

You are right, it is there, I have just missed it

Cheerpipe commented 1 year ago

Does this looks like a path?

96929965.zip

PiotrMachowski commented 1 year ago

Yes, path is created from a list of pairs. In roidmi vacuums Map Extractor at this moment expects following structure in map data (path is taken from posArray):

path

Cheerpipe commented 1 year ago

Xiaomi Home is grabbing this file from this API https://us.api.io.mi.com/app/v2/home/get_interim_file_url posting this data:

{"obj_name":"<account user id>/<device id>/<UID>"}" PD: I have no idea what is this UID or where to get this :(

Any chance to add a feature to grab the path from an external file like the one i posted above or this kind of solutions are out of the scope of Xiaomi Map extractor?

PiotrMachowski commented 1 year ago

I think it might be pathId from map data. Or is it in a different format (e.g. UUID - 123e4567-e89b-12d3-a456-426614174000)?

It might be possible to get add this feature to Map Extractor

Cheerpipe commented 1 year ago

I trying to figure it out where to get the UID param. I also thought it may be the pathId but i was wrong :(.

The UID param is a number value with eight digits.

UID is also used by the siid 11 aiid 2 as the input param:

{"StartPos":0,"PathID":0,"UID":"12345678"}"]}}


i Start thinking UID may be optional. Will try to fire some request to the api and report back.

PiotrMachowski commented 1 year ago

You can try to get UID using Tokens Extractor from this PR. It is not merged yet, but it should be soon

Cheerpipe commented 1 year ago

You can try to get UID using Tokens Extractor from this PR. It is not merged yet, but it should be soon

The UID returned by the script is the Owner ID, not the "magic number" that returns the path file


I just saw you are already using /v2/home/get_interim_file_url API to get the map file :D and noted the magic number param is just the map id and when using 0 it gets the URL for the map file, and when using the magic number (96929965) i get the URL for the path file.

So the only real question is where to get the mapid that returns the path file url. Xiaomi Home is using this "magic number" but i get nothing in the debuguer about how it get it. It just exists. Only answer is this number is not obtained using the api but contained inside another file.


Maybe we may try a first version where the map_id for the path data is manually configured in Home Assistant. It may works this way.

1.- Add an an configuration key like: "path_map_id": 2.- Get the path_map_file debugging Xiaomi Home. It is easy, just filter the log output using "/v2/home/get_interim_file_url" filter and look for a line with something like this [data:{"obj_name":"XXXXXXXX/XXXXXXXX/YYYYYY"}] where YYYYYY is not 0. YYYYYY will be the path_map_id. 3.- Every time you get the map file using get_map_url(self, map_name: str) with the correct map id (or zero), do another request but using the configured path_map_id. The obtained URL will return the file i posted above with path data.

It should works until i figure it out how to get the path map id using the API.

PD: The path map id changes every time i relog into Xiaomi Home

PiotrMachowski commented 1 year ago

Well, to incorporate such changes I'd have to make some major refactor. Additionally I want to finish my current work on the Map Card, so you should have plenty of time to do some research.

Cheerpipe commented 1 year ago

Thanks

Will do my best

PiotrMachowski commented 1 year ago

@rezmus do you have some info about this model and a way it provides the path?

rezmus commented 1 year ago

last param of obj_name is data index. my blind guess is that this is more or less random generated by device plugin. then sent to robot via action 11/2 which is order to upload path data to cloud with index used.

below link to device plugin in human readable form (before webpack/minify). there should be all info you need. if you still have problems i can take a look, but need device shared to my account (much easier when you see data flow).

https://we.tl/t-S7JzBSs3fL