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.14k stars 121 forks source link

Failed to retrieve map from vacuum #422

Closed kimme1024 closed 1 year ago

kimme1024 commented 1 year ago

Checklist

The problem

First of all thanks for this great integration! I've been using it for more than a year now without any issues. However for the last couple of days I don't receive any maps anymore. I only see "Failed to retrieve map from vacuum" for both my vacuums (S5 &S7). I've checked the logs but nothing's showing. I only have the custom integration error about that it's not tested by Home Assistant. But after that, nothing at all. Always difficult when something breaks when you didn't change anything...

Any idea's?

What version of an integration has described problem?

v2.2.0

What was the last working version of an integration?

v2.2.0

What vacuum model do you have problems with?

S5 and S7

What version of Home Assistant do you use?

2023.3.6

What type of installation are you running?

Home Assistant Core

Camera's configuration

camera:
  - platform: xiaomi_cloud_map_extractor
    name: Roborock S5
    host: 192.168.1.30
    token: xxx
    username: xxx
    password: xxx
    draw: ['all']
    attributes:
      - calibration_points
      - room_numbers
      - rooms
    colors:
      color_map_inside: [21, 21, 21]
      color_map_outside: [28, 28, 28]
      color_map_wall: [142, 142, 142]
      color_map_wall_v2: [142, 142, 142]
      color_grey_wall: [142, 142, 142]
      color_ignored_obstacle: [0, 0, 0, 127]
      color_ignored_obstacle_with_photo: [0, 0, 0, 127]
      color_obstacle: [0, 0, 0, 127]
      color_obstacle_with_photo: [0, 0, 0, 127]
      color_path: [255, 255, 255]
      color_goto_path: [0, 255, 0]
      color_predicted_path: [255, 255, 0, 0]
      color_cleaned_area: [127, 127, 127, 127]
      color_zones: [0, 0, 0, 0]
      color_zones_outline: [0xAD, 0xD8, 0xFF]
      color_virtual_walls: [255, 0, 0]
      color_new_discovered_area: [64, 64, 64]
      color_no_go_zones: [255, 33, 55, 127]
      color_no_go_zones_outline: [255, 0, 0]
      color_no_mop_zones: [163, 130, 211, 127]
      color_no_mop_zones_outline: [163, 130, 211]
      color_charger: [0x66, 0xfe, 0xda, 0x7f]
      color_robo: [75, 235, 149]
      color_room_names: [0, 0, 0]
      color_unknown: [0, 0, 0]
      color_scan: [0xDF, 0xDF, 0xDF]
    room_colors:
      1: [21, 21, 21]
      2: [21, 21, 21]
      3: [21, 21, 21]
      4: [21, 21, 21]
      6: [21, 21, 21]
      7: [21, 21, 21]
      5: [21, 21, 21]
    map_transformation:
      rotate: 270
      scale: 3
      trim:
        top: 0
        bottom: 0
        left: 0
        right: 0
  - platform: xiaomi_cloud_map_extractor
    name: Roborock S7
    host: 192.168.1.181
    token: xxx
    username: xxx
    password: xxx
    draw: ['all']
    attributes:
      - calibration_points
      - room_numbers
      - rooms
    colors:
      color_map_inside: [21, 21, 21]
      color_map_outside: [28, 28, 28]
      color_map_wall: [142, 142, 142]
      color_map_wall_v2: [142, 142, 142]
      color_grey_wall: [142, 142, 142]
      color_ignored_obstacle: [0, 0, 0, 127]
      color_ignored_obstacle_with_photo: [0, 0, 0, 127]
      color_obstacle: [0, 0, 0, 127]
      color_obstacle_with_photo: [0, 0, 0, 127]
      color_path: [255, 255, 255]
      color_goto_path: [0, 255, 0]
      color_predicted_path: [255, 255, 0, 0]
      color_cleaned_area: [127, 127, 127, 127]
      color_zones: [0, 0, 0, 0]
      color_zones_outline: [0xAD, 0xD8, 0xFF]
      color_virtual_walls: [255, 0, 0]
      color_new_discovered_area: [64, 64, 64]
      color_no_go_zones: [255, 33, 55, 127]
      color_no_go_zones_outline: [255, 0, 0]
      color_no_mop_zones: [163, 130, 211, 127]
      color_no_mop_zones_outline: [163, 130, 211]
      color_charger: [0x66, 0xfe, 0xda, 0x7f]
      color_robo: [75, 235, 149]
      color_room_names: [0, 0, 0]
      color_unknown: [0, 0, 0]
      color_scan: [0xDF, 0xDF, 0xDF]
    room_colors:
      1: [21, 21, 21]
      16: [21, 21, 21]
      20: [21, 21, 21]
      17: [21, 21, 21]
      18: [21, 21, 21]
      19: [21, 21, 21]
      21: [21, 21, 21]
    map_transformation:
      rotate: 270
      scale: 3
      trim:
        top: 0
        bottom: 0
        left: 0
        right: 0

Errors shown in the HA logs (if applicable)

sadly, none :(

Additional information

No response

eriklysoe commented 1 year ago

Same problem here as well

klu16 commented 1 year ago

scan_interval: 30 looks like it did a trick for me... I see the map again. I will observe and report later :)

MathijsG commented 1 year ago

scan_interval: 30 looks like it did a trick for me... I see the map again. I will observe and report later :)

Even with 60 im apparently still flooding the API, as mine is down again. I think we really need a different way of organizing the image, and maybe at least save the last image until the newest one is resolved successfully. As without a map you can't even plan cleaning anymore, as you lack the room selection etc.

AseKarlsson commented 1 year ago

scan_interval: 30 looks like it did a trick for me... I see the map again. I will observe and report later :)

Also added scan_interval: 30 last evening, but sadly maps gone now in the morning again.

meepmeep commented 1 year ago

I'm on a 120 interval, I added back the camera: configuration block yesterday afternoon. And this morning the map is unable to load on the Xiaomi App (and it's not even loaded on HA Dashboard).

sergicm commented 1 year ago

For me it's working again the last 2-3 days, only used the blueprint to disable the update while docked.

AseKarlsson commented 1 year ago

What is the best way to get map working again after a failure. First time I just restarted the vaccuum, but now I cannot get it working again (not even on phone)?

meepmeep commented 1 year ago

@sergicm the blueprint from @YoMan12 ?

I still doesn't understand one point : this integration pull the map as soon as it's included in the configuration.yml or only when added as a card on a dashboard?

MathijsG commented 1 year ago

What is the best way to get map working again after a failure. First time I just restarted the vaccuum, but now I cannot get it working again (not even on phone)?

Wait until the limit is reset (https://blog.axway.com/learning-center/apis/basics/api-rate-limits) it doesn't have anything to do with the vacuum cleaner locally, everything is related to the Roborock API now enforcing rate limits on their cloud services.

AseKarlsson commented 1 year ago

What is the best way to get map working again after a failure. First time I just restarted the vaccuum, but now I cannot get it working again (not even on phone)?

Wait until the limit is reset (https://blog.axway.com/learning-center/apis/basics/api-rate-limits) it doesn't have anything to do with the vacuum cleaner locally, everything is related to the Roborock API now enforcing rate limits on their cloud services.

Thanks, Do we know what the limit reset time is for Roborock?

cosmos1978 commented 1 year ago

Seems my automations I uploaded here were removed ?

So I will place them again as I think this is a better solution than the blueprint to disable the camera completely. One automation will enable or disable the second automation if the roborock is either docker or not. The second automation will update the camera service every 15 seconds.

You will need to set the scan_interval in the configuration.yaml to a high value like 14400 ( 4 hours )


alias: start/stop xiaomi fast scan interval
description: ""
trigger:
  - platform: state
    entity_id:
      - vacuum.roborock_s6
condition: []
action:
  - if:
      - condition: state
        entity_id: vacuum.roborock_s6
        state: docked
    then:
      - service: automation.turn_off
        data: {}
        target:
          entity_id: automation.update_xiaomi_map_extractor
    else:
      - service: automation.turn_on
        data: {}
        target:
          entity_id: automation.update_xiaomi_map_extractor
mode: single

alias: update xiaomi map extractor
description: ""
trigger:
  - platform: time_pattern
    seconds: "15"
condition: []
action:
  - service: homeassistant.update_entity
    data: {}
    target:
      entity_id: camera.xiaomi_cloud_map_extractor
initial_state: "off"
mode: restart
PiotrMachowski commented 1 year ago

@cosmos1978 they were not removed, you just posted them in a completely different thread.

I will adjust the blueprint to support different scan intervals later today/tomorrow

cosmos1978 commented 1 year ago

@cosmos1978 they were not removed, you just posted them in a completely different thread.

I will adjust the blueprint to support different scan intervals later today/tomorrow

Ok sorry about that :-)

AseKarlsson commented 1 year ago

What is the best way to get map working again after a failure. First time I just restarted the vaccuum, but now I cannot get it working again (not even on phone)?

Wait until the limit is reset (https://blog.axway.com/learning-center/apis/basics/api-rate-limits) it doesn't have anything to do with the vacuum cleaner locally, everything is related to the Roborock API now enforcing rate limits on their cloud services.

Thanks, Do we know what the limit reset time is for Roborock?

Killed the map updates from HA about 8 hours ago, still cannot get the map on Xiaomi Phone App, any feeling how long Roborock locks you out?

eriklysoe commented 1 year ago

Answer from support, not very helpful

I understand it may have something to do with API rate limits, do you know the limit reset time for roborock? So we can adjust the home assistant integration accordingly?

«Thank you for taking the time to reach back out to Roborock Support and for updating us on the situation. Under these circumstances we suggest you disconnect robot from home assist or disable its map feature have a try, which should solve the issue.»

eriklysoe commented 1 year ago

What is the best way to get map working again after a failure. First time I just restarted the vaccuum, but now I cannot get it working again (not even on phone)?

Wait until the limit is reset (https://blog.axway.com/learning-center/apis/basics/api-rate-limits) it doesn't have anything to do with the vacuum cleaner locally, everything is related to the Roborock API now enforcing rate limits on their cloud services.

Thanks, Do we know what the limit reset time is for Roborock?

Killed the map updates from HA about 8 hours ago, still cannot get the map on Xiaomi Phone App, any feeling how long Roborock locks you out?

For me, map came back immetiately in phone app after killing integration in home assistant, and then long reboot of roborock.

meepmeep commented 1 year ago

@AseKarlsson wait until next day.

@cosmos1978 solution seems to do the job. Thank you !

PiotrMachowski commented 1 year ago

@cosmos1978 one suggestion regarding your automation: at this moment it refreshes the camera every minute, to make it work every 15s you have to use seconds: "/15"

AseKarlsson commented 1 year ago

@cosmos1978, Added your automation yesterday evening, GREAT!!!. Got back my map today morning. In the afternoon I tried to start a cleaning and found out that HA could not load the map anymore, but Mi Home still could. Restarted HA and could see the map again, just a glitch?

Great automation, also had to change: from: initial_state: "off" to: initial_state: false in the code to not get an error

Have anyone tried to go down to 5 seconds during vacuum or do we get banned again?

AseKarlsson commented 1 year ago

@PiotrMachowski, What a great integration you made, what kind of thoughts do you have for going forward?

cosmos1978 commented 1 year ago

And today I got the error again. failed to retrieve map from vacuum. So even with my automation it still fails after some time.

cosmos1978 commented 1 year ago

And today I got the error again. failed to retrieve map from vacuum. So even with my automation it still fails after some time.

And what is even weirder is that when I restart the virtual machine my home assistant is running in it fixes the map. But a home assistant restart does nothing. I am beginning to doubt if the problem is only related to the cloud API. A restart of the home assistant OS should not fix the map if it was an API related issue.

PiotrMachowski commented 1 year ago

What a great integration you made, what kind of thoughts do you have for going forward?

@AseKarlsson any suggestions? 😄 Right now I try (and fail a bit) to keep up. I have made too many repos to maintain


@cosmos1978 I think that restart might clear some stuff in python cache, which might make Xiaomi recognize the integration as a different device

AseKarlsson commented 1 year ago

@PiotrMachowski, Cannot give any suggestions from my knowledge level of coding, I am happy that you are on it and seeking a solution for us all!

Do we know the API overflow limit of Roborock at the moment?

Next release preferable without need of external solutions and can your own BluePrint be included in the code as well by default?

Keep up the good work!

PiotrMachowski commented 1 year ago

Next release preferable without need of external solutions and can your own BluePrint be included in the code as well?

I think I would prefer to keep variable intervals as a blueprint to keep it easy to modify without changing the code.

About other changes, I'd try to merge all pull requests, fix some issues, improve stability, extract map parsing to a dedicated packages. Maybe someday I'll make a config flow. That is my general plan, but nothing is guaranteed ;)

AseKarlsson commented 1 year ago

Not a bad idea, but seeking for the BluePrint did not happen before I was cought i in the problems

PiotrMachowski commented 1 year ago

I have created a new blueprint that should handle all possible cases. It is not mentioned in a documentation at this moment, I will add it there later.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

AseKarlsson commented 1 year ago

I have created a new blueprint that should handle all possible cases. It is not mentioned in a documentation at this moment, I will add it there later.

Question: Should not theese times be the other way around (default:10 and default: 1800)?

        Camera's update interval that should be used when the vacuum is docked.
        Not used in `Turn off when docked` and `Default when docked` modes.
      selector:
        number:
          max: 10000
          min: 1
          unit_of_measurement: s
      default: 10
    interval_cleaning:
      name: Interval cleaning
      description: |-
        Camera's update interval that should be used when the vacuum is cleaning.
        Not used in `Turn off when docked` and `Default when cleaning` modes.
      selector:
        number:
          max: 10000
          min: 1
          unit_of_measurement: s
      default: 1800
witooski commented 1 year ago

I have exactly the same question. Default values seem to be set the other way around :)

cyberden commented 1 year ago

There seems to be a mismatch in the labels. The way it is configured is the way that works correctly even if it doesn't make sense.

oksakoor commented 1 year ago

I tried blueprint but it wont solve map missing problem.

PiotrMachowski commented 1 year ago

@AseKarlsson @witooski you are correct, I have adjusted it (this is what you get when you code at 4AM...)


@oksakoor you have to disable camera's automatic updates first with auto_update: false in its config. Also it might take some time to recover on Xiaomi Cloud.

trizmark commented 1 year ago

Any idea how long it takes to recover access to Xiaomi Cloud? Disabled the camera hours ago and the map is still not loading in the Xiaomi Home app...

PiotrMachowski commented 1 year ago

@trizmark you can try rebooting the vacuum

trizmark commented 1 year ago

Did that, no luck. I guess I'll have to be more patient.

oksakoor commented 1 year ago

Did that, no luck. I guess I'll have to be more patient.

Same here.

MathijsG commented 1 year ago

Yeah, if you look at earlier messages in this thread, people even reach 24+ hours.

But you could try the tips given earlier in this thread.

kimme1024 commented 1 year ago

It's been unavailable for me for a couple of days but I was out so I left it as is. Today I added the blueprint and changed the configuration.yaml file. After that I rebooted the vacuums and it worked immediately. So far it still works after a couple of hours but the vacuums didn't run yet so the biggest test will be during the night so I'll have to check again tomorrow. The only thing that's messed up right now is the map orientation. Somehow it's changed so I'll have to fiddle around with that to get it nice again on my dashboards.

Thanks for the support and hopefully it's fixed this way!

AseKarlsson commented 1 year ago

@PiotrMachowski, BluePrint Imported and looks good now for a couple of hours. Great work done, thanks!

oksakoor commented 1 year ago

This is my config bottom part. Thats correct?

draw: ["all"]
attributes:
  - calibration_points
auto_update: false

So far tried reboot robot cleaner and restart HA but no luck.

PiotrMachowski commented 1 year ago

Yes, it's correct. Now you have to wait

trizmark commented 1 year ago

It took me about 4-5 hours before I could reach my vacuum. Re-enabled the map extractor with the new automation and now everything works like a charm! Awesome work @PiotrMachowski !

oksakoor commented 1 year ago

Thanks for confirming. I made 5 hours ago those steps. Now i have an inner peace that i don't wait blindly with wrong config etc :)

AseKarlsson commented 1 year ago

Thanks for confirming. I made 5 hours ago those steps. Now i have an inner peace that i don't wait blindly with wrong config etc :)

Just wait over midnight was the tip I received earlier on the same question and that was the case!

YoMan12 commented 1 year ago

Unfortunatelly I haven't time to make more investigation during the weekend (unexpected ;) ) and I can see that some solutions are made :) Just to enlarge the knowledge I can say that basing on my logs I found out that in my case "reset" is made at 3:20 and block is coming at ca. 18:00 (17:56, 18:01, 18:02 - checked on three following days). I set up scan_interaval to 30s so it makes about 1700-1800 API questions for a day but as it was written here some of You have made bigger intervals and the problem appeared as well so maybe it is kind of more complicated algorithm. I will check new blueprint as well. BTW: similar problem seems to be with Xiaomi cameras. Somebody has found out the solution?

klu16 commented 1 year ago

Just here to report that with: auto_update: false - camera settings in configuration.yaml and imported blueprint with chosen option "Default when cleaning" and Interval docked set to 3600, I haven't had any map problems since couple of hours. Thanks for the fix! 😊

trizmark commented 1 year ago

Unfortunately, my map broke at 3am this morning with 20s / 1800s settings. ☹️

oksakoor commented 1 year ago

I waited 19h but nothing. What is recommended settings in blueprint?

kimme1024 commented 1 year ago

Unfortunately, my map broke at 3am this morning with 20s / 1800s settings. ☹️

Broken here as well

trizmark commented 1 year ago

I waited 19h but nothing. What is recommended settings in blueprint?

I went with 20s / 1800s, but that doesn't seem to work (for me at least). The default is 10/1800. When (and hopefully not if) I regain access, I simply add a button to refresh the map manually as and when I need it. It's far from ideal, but that should work.