Roborock (integration) map configuration

So, as it turns out, apparently there is both a native HA Roborock integration and a custom one via HACS. Only the custom one provides a camera entity. Once installed, it works fine, though a lot of native sensors become state attributes instead.

Good catch! Now that you say that, I went and checked, and I am using the Roborock integration from HACS. My apologies for the prior bad intel!

Hi All,

In the Roborock app when you choose selected rooms, they are highlighted while the not vacuumed rooms are grayed out. I wonder if it is possible with this integration.

Is this already solved with some kind of work around?

I’m not seeing the roborock integration in HACS. Is it still available or under some different type of name? Thanks!

At least for me, this doesn’t work. The custom integration from hacs does not start a vacuum round. The robot exits the dock and immediately docks again.

So roborock is probably the worst supported vacuum robot vacuum for home assistant at the moment, unfortunately.

What do you see in the app when it starts cleaning? Maybe you’re not providing a list of rooms or areas to clean, so it just starts and then returns because there is nothing to clean? What does the vacuum say before returning?

You should use something like this for room cleaning (get your room ids with roborock.get_maps service)

  - service: vacuum.send_command
    target:
      entity_id: vacuum.xiaomi_vacuum_cleaner
    data:
      command: app_segment_clean
      params:
        - 22

or this for area cleaning:

  - service: vacuum.send_command
    data:
      command: app_zoned_clean
      params:
        - - 27748
          - 24959
          - 30854
          - 29100
          - 1
    target:
      entity_id: vacuum.xiaomi_vacuum_cleaner

Have you managed to turn off the colors with the roborock integration?

I have an automation to alter the colors in python library /site-packages/vacuum_map_parser_base/config/color.py

and remove all room colors so it becomes transparent

Very nice @radinsky, care to share the code?

Sure, that’s why the community for… :slight_smile:

import os
import re
import glob

# Define the path to the Python file
PYTHON_VERSION = f"{os.sys.version_info.major}.{os.sys.version_info.minor}"
COLOR_FILE = f"/usr/local/lib/python{PYTHON_VERSION}/site-packages/vacuum_map_parser_base/config/color.py"
PYCACHE_DIR = f"/usr/local/lib/python{PYTHON_VERSION}/site-packages/vacuum_map_parser_base/config/__pycache__"
MARKER = "# Colors updated by update_colors.py"

# Check if the file exists
if not os.path.isfile(COLOR_FILE):
    print(f"File not found: {COLOR_FILE}")
    exit(1)

# Check if the marker is already present
with open(COLOR_FILE, 'r') as file:
    content = file.read()
    if MARKER in content:
        print("The colors have already been updated.")
        exit(0)

# Define the colors to keep their original opacity
KEEP_OPACITY = ["PATH", "GOTO_PATH", "CLEANED_AREA", "CHARGER", "CHARGER_OUTLINE", "ROBO", "ROBO_OUTLINE", "ZONES", "ZONES_OUTLINE"]

# Read the content of the file
with open(COLOR_FILE, 'r') as file:
    content = file.readlines()

# Update the COLORS dictionary
updated_content = []
in_colors_section = False
in_room_colors_section = False

for line in content:
    if 'COLORS: dict[SupportedColor, Color] =' in line:
        in_colors_section = True
    if in_colors_section and '}' in line:
        in_colors_section = False
    
    if 'ROOM_COLORS: dict[str, Color] =' in line:
        in_room_colors_section = True
    if in_room_colors_section and '}' in line:
        in_room_colors_section = False
    
    if in_colors_section and 'SupportedColor.' in line:
        match = re.search(r'SupportedColor\.([A-Z0-9_]+):\s*\(([^)]+)\)', line)
        if match:
            color_name = match.group(1)
            color_values = match.group(2).split(',')
            if color_name not in KEEP_OPACITY:
                if len(color_values) == 3:
                    line = re.sub(r'\(([^)]+)\)', f'({match.group(2)}, 0)', line)
                elif len(color_values) == 4:
                    if '0)' not in line:
                        values = ', '.join(color_values[:3]).strip()
                        line = re.sub(r'\(([^)]+)\)', f'({values}, 0)', line)
    
    if in_room_colors_section:
        line = re.sub(r'\(([^)]+)\)', r'(\1, 0)', line)
    
    updated_content.append(line)

# Add the marker to the file
updated_content.append(f"\n{MARKER}\n")

# Write the updated content back to the file
with open(COLOR_FILE, 'w') as file:
    file.writelines(updated_content)

# Clear the __pycache__ directory
for pyc_file in glob.glob(f"{PYCACHE_DIR}/*.pyc"):
    os.remove(pyc_file)

print(f"Color opacities updated successfully in {COLOR_FILE} and cache cleared.")

And I have a shell_command like this:

update_roborock_colors: 'python3 /config/python_scripts/update_roborock_colors.py'

You can trigger it manually or automatically after HA core update

Thanks for the code, but unfortunately i never did anything with python… do you know a step by step guide on how to get this to work?

Ok i tried something and i dont know what im doing wrong.

  1. I installed the file editor
  2. created a new folder “homeassistant/python_scripts”
  3. created the file “update_roborock_colors.py” and copied your code
  4. Added the following in configurations.yaml:

python_scripts:

logger:
default: info

shell_command:
update_roborock_colors: ‘python3 /config/python_scripts/update_roborock_colors.py’

  1. Created a button helper “Roborock Colors”
  2. Created a button card with tap action shell_command…

When i press the button nothing happens.

When copying the shell command in SSH i get the message “file not found: /usr/local/lib/python3.12/site-packages/vacuum_map_parser_base/config/color.py”

Im sorry if im just stupid but this is really new for me. Id appreciate any help.
Thanks!

Check in logs if you see any error, but in general it shouldn’t return anything.
You need to restart HA after you executed shell command so the changed modules will loaded…

The issue seems to be that the folder “/usr/local/lib/” is empty. I dont have any python folders inside here. Do i need to do something else beforehand to have access to those folders or something?

Actually I assumed you run HA in docker (supervised) as I do.
If not, you should point the path (COLOR_FILE and PYCACHE_DIR) to your python location.

Thanks for the help it actually worked! My image just didnt update. I didnt have to edit anything in your code.

I created an automation to run the shell command on button press and send me a notification on my phone with the response.

You said i can run the shell command automatically after a core update. What do i have to use as trigger to do this?

Thanks!

Great it worked!
I’m running it on every HA boot (it will not change the file if it already was changed, so no problem to execute it more than once…)

alias: Update Roborock Colors
description: Update Roborock color map in python library using python script
mode: single
triggers:
  - event: start
    trigger: homeassistant
conditions: []
actions:
  - metadata: {}
    data: {}
    action: shell_command.update_roborock_colors

@bkr1969, were you able to resolve this using the core integration? As soon as I enter the map_source as an image, I get the same “Invalid calibration” error.

So, now that the Vacuum map card is working with image entities and works with the core Roborock integration, I think it would be a great step if we could have on the integration config UI options to set-up which elements we want to show in the map and what color palette to use.