Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor icon indicating copy to clipboard operation
Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor copied to clipboard

Introduce Dreame map refresh

Open auanasgheps opened this issue 2 years ago • 82 comments

Description

The current implementation for Dreame vacuums is not able to refresh the map on its own, but relies on the mobile app to do so.

This is the detailed behaviour.

  • The HA Map card will never update unless you open the mobile app.
  • Once the user opens the mobile app, the HA Map will update once.
  • Even if you keep the app open, the HA Map doesn't refresh even if the app does update.
  • To trigger a refresh, you have to exit the vacuum on the app and re-enter again to trigger another single refresh.

Unfortunately it means we are still heavily dependent by the mobile app.

I have grabbed the Mobile app's log to see what commands are send to the vacuum. I see a lot of calls regarding "get_properties" and these are MioT commands.

I can share the logs privately with you if you provide an email address.

Solution

When vacuum operations are started, implement a logic similar to the one in the app, so we can get the map refreshed independently.

Alternatives

No response

Context

Other non-Dreame vacuums are able to refresh the map without relying on the app.

auanasgheps avatar Jun 01 '22 13:06 auanasgheps

Sure, you can send me log files. piotr.machowski.dev [at] gmail.com

PiotrMachowski avatar Jun 01 '22 13:06 PiotrMachowski

I have the exact same issue with my Z10 Pro. I think the app sends map-req or some other action for device to update the map on the cloud. I can provide more information if you need to.

Tasshack avatar Jun 04 '22 03:06 Tasshack

I could also provide logs from a Dreame D9. I let it clean one room while watching the app and retrieved the logs. Should I send them via mail? Is there anything to remove from the logs beside the serial number?

The logs contain some undocumented PIIDs. There were no update-map actions and only some map-req actions at the beginning. The mult-map-state was request via get_properties very often. The mult-map-info sometimes (which seems to return an object).

By the way: maybe you could put the link to vevs Mi Home App into a 'Development' section of the Readme. It took me a while to find out how to get logs from the app. (or a pinned issue)

SpiGAndromeda avatar Jun 05 '22 17:06 SpiGAndromeda

@SpiGAndromeda sure, you can send them. The problem is that I don't have a Dreame vacuum, so I'm unable to test anything :/

PiotrMachowski avatar Jun 05 '22 18:06 PiotrMachowski

I can test if for you. :) We can discuss the communication way via mail if you want.

SpiGAndromeda avatar Jun 05 '22 18:06 SpiGAndromeda

@SpiGAndromeda I think that the best way of communication would be HA forum, I can make a group conversation here to add everyone else as well https://community.home-assistant.io/u/3_14

PiotrMachowski avatar Jun 05 '22 18:06 PiotrMachowski

Perfect. My username is the same like here.

SpiGAndromeda avatar Jun 05 '22 20:06 SpiGAndromeda

Allright! My username in HA forum is the same, auanasgheps.

auanasgheps avatar Jun 05 '22 22:06 auanasgheps

I fixed the map refresh problem by calling map-req action periodically with an automation while robot is cleaning the house. I don't know this is the right solution, but it works good for now.

Tasshack avatar Jun 07 '22 08:06 Tasshack

Thanks for the update @Tasshack, can you provide more details?

auanasgheps avatar Jun 07 '22 08:06 auanasgheps

Gen2 Dreame robots (L10, Z10, W10) works different from the Gen1 like D9. New robots does not send map periodically to the cloud automatically. I have checked the valetudo firmware, found out that you need to send map-req action to trigger the map upload to cloud and that is how currently valetudo gets the map from the device.

https://github.com/Hypfer/Valetudo/blob/84de0ef9d869f5150c504fa13bcd49956c71bf4c/backend/lib/robots/dreame/DreameValetudoRobot.js#L54

I have custom miiot integration installed on my hass and that is how i send the map-req to the device currently.

service: xiaomi_miot.call_action
target:
  entity_id: vacuum.dreame.p2028
data:      
  siid: 6
  aiid: 1
  params:
    - piid: 2
      value: '{"frame_type":"I"}'

Tasshack avatar Jun 07 '22 09:06 Tasshack

@auanasgheps hmmm, this was my suggestion when you sent me your logs, but it didn't work for you, right?

PiotrMachowski avatar Jun 07 '22 09:06 PiotrMachowski

@auanasgheps can you share the logs with me as well to ayigittopcu [at] gmail.com?

Tasshack avatar Jun 07 '22 09:06 Tasshack

@PiotrMachowski my username in comminity is also same with here, can you add me to the conversation from there too.

Tasshack avatar Jun 07 '22 09:06 Tasshack

My query was slightly different:

service: xiaomi_miot.call_action
data:
  entity_id: vacuum.battista
  siid: 6
  aiid: 1
  params:
  piid: 2
    value: '{"req_type":1,"frame_type":"I","force_type":1}'

I can confirm that the new query by @Tasshack works, the map gets updated just after a second the command is sent! That's great!

So shall we implement this call (or the template to do so, not all Dreame need it according to Tasshack) every time the maps needs an update?

auanasgheps avatar Jun 07 '22 09:06 auanasgheps

By the way i am trying to develop a custom integration (forked from D9 intregration) specific to those GEN2 robots but most of their new features that introduced on latest firmware are not documented at all. Even valetudo does not implemeted some of those features since it is not currently supported on latest firmware. I am struggling to find the specific siid/piid values with their extra parameter information to send to robot. For example; app can send cleaning room order to robot to store and when you press start even from the button, robot cleans whole house with that room order, but i couldn't find the aiid/piid values to do it from the integration. The main problem is most of the developers still does not have one of those new GEN2 robots yet and because of that currenlty there is no information about them on the internet and how they work exactly. I think we may have to wait a bit longer to fully integrate GEN2 robots to home assistant because it has been more than six months from release of the latest firmware and people still did not exploited the new features on Z10/L10 like only mopping while water tank is attached which is only loosely documented on W10 api specs.

Tasshack avatar Jun 07 '22 10:06 Tasshack

@auanasgheps it shouldn't be hard for me to add it. Until that you can handle it with a simple automation

PiotrMachowski avatar Jun 07 '22 13:06 PiotrMachowski

@Tasshack your effort is incredible, but I am against custom integrations. There have been attempts in the past especially for Dreame robots, but quickly become outdated or unmaintained and users get lost. Why not contribute directly to the MioT integration which is well supported and updated? (BTW I still don't understand why the official Xiaomi integration does not support Dreame robots)

auanasgheps avatar Jun 07 '22 14:06 auanasgheps

I can also confirm that running an automation that request a map update (ssid 6, aiid 3), is working fine! Now, I can get an almost live map. I've setup a request every 5 seconds, do you know if it's reasonable to request an update to the vacuum with a lesser delay, like 2 or 3 seconds?

webjib avatar Jun 09 '22 13:06 webjib

@webjib the map by default updates every 5 to 10 seconds, so I won't go under 5 seconds to be honest. What automation have you configured? My trigger does not detect when to start the automation, but I am a newbie with HA automations.

auanasgheps avatar Jun 11 '22 10:06 auanasgheps

I'm using a custom Dreame D9 integration, for which I've created a new service called "vacuum_update_map" (it's derived from https://github.com/pooyashahidi/xiaomi_vacuum). So sharing the entire automation will not help.

But here is the trigger:

trigger:
  - platform: template
    value_template: '{{ is_state(''vacuum.aspirobot'', ''cleaning'') or is_state(''vacuum.aspirobot'',
      ''mopping'') or is_state(''vacuum.aspirobot'', ''returning'') }}'

webjib avatar Jun 11 '22 10:06 webjib

Thanks! I used the 'status' trigger within the UI, but it didn't work. I will try yours!

auanasgheps avatar Jun 12 '22 19:06 auanasgheps

@Tasshack your effort is incredible, but I am against custom integrations. There have been attempts in the past especially for Dreame robots, but quickly become outdated or unmaintained and users get lost. Why not contribute directly to the MioT integration which is well supported and updated? (BTW I still don't understand why the official Xiaomi integration does not support Dreame robots)

@auanasgheps Xiaomi says Dreame is part of their eco system but they acquired Dreame late after they started to develop robot vacuums. Because of that, not all api features are compatible with the rest of the eco system. Thats why miiot and python-miio are not fully supporting the dreame devices yet. Especially with the lack of documentation you need to do a lot of reverse engineering to support them and to do that you need to own the acual device. The features that i have implemented to my integration can be achieved with miiot integration also but you have to write a lot of yaml and ninja scripts. I just prefer python, it is cleaner and more optimized.

Tasshack avatar Jun 13 '22 20:06 Tasshack

@webjib the map by default updates every 5 to 10 seconds, so I won't go under 5 seconds to be honest. What automation have you configured? My trigger does not detect when to start the automation, but I am a newbie with HA automations.

@webjib @auanasgheps If you have Z10 or W10, you can check SIID: 15 PIID: 3 (dust-enable attribute) to check robot is docked or not. This attribute returns 1 when auto empting can be triggered from app and it is the only way to determine robot is docked or not when the battery is 100% (Not charging while docked).

Tasshack avatar Jun 13 '22 20:06 Tasshack

@Tasshack actually, python-miio is already supporting some Dream Vacuums like the D9 or F9, but not all functions. The best situation would be to contribute first to the python-miio project to support more functions, and more models. Then, as the official HASS Miio integration is using python-miio project, it should be easy to officially support Dreame Vacuums. Lot of work.

webjib avatar Jun 14 '22 06:06 webjib

@webjib yes python-miio recently added the Dreame support but the version that shipped with HASS not yet supports it. Also some utilities like mirobo still does not support Dreame yet. I think it is a good idea to contribute to python-miio but i am not so good at python to do that. I can provide information about undocumented features that i have gathered from valetudo firmware though.

Tasshack avatar Jun 14 '22 15:06 Tasshack

@SpiGAndromeda how can i access the app logs, is there a guide that you can share with me?

Tasshack avatar Jun 14 '22 19:06 Tasshack

I have a Dreame D9 and the map does not update for me either (only when I open the smartphone app). Could someone please explain to me in more detail how you solved the problem?

Do I have to create a script like this:

service: xiaomi_miot.call_action
target:
  entity_id: vacuum.xxxxx
data:      
  siid: 6
  aiid: 1
  params:
    - piid: 2
      value: '{"frame_type":"I"}'

and afterwards an automation that runs this script?

Thanks for your help.

el-fredo avatar Jul 31 '22 14:07 el-fredo

@el-fredo I have set up an automation like this and it works to update the map for my Dreame W10

alias: map_update
description: ""
trigger:
  - platform: time_pattern
    seconds: /5
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: vacuum.xxx
        state: cleaning
      - condition: state
        entity_id: vacuum.xxx
        state: Washing
      - condition: state
        entity_id: vacuum.xxx
        state: Go Washing
action:
  - service: xiaomi_miot.call_action
    data:
      entity_id: vacuum.xxx
      siid: 6
      aiid: 1
      params:
        - piid: 2
          value: "{\"req_type\":1,\"frame_type\":\"I\",\"force_type\":1}"
mode: single

rbforelle avatar Sep 04 '22 16:09 rbforelle

@rbforelle Thank you for the automation! However, the way it's configured means that every 5 seconds HA will check if this automation should be running. I'm not sure if this is is a best practise, I fear it can overload HA. image

auanasgheps avatar Sep 05 '22 11:09 auanasgheps