Valetudo Vacuums Map Camera for Home Assistant

@gsca075 Thanks for the update - the reset-trims action is working perfectly :+1:.

Iā€™ve included below my scripts for running maploader and the reset-trims actions in case it helps anyone, although theyā€™re quite simple - I included a 20 second pause between both steps as that seems to be enough time for maploader to finish and for the map files on the robot to be updated.

Main / Ground floor script [ID = main]:

alias: Robot Vacuum Cleaner - Main
sequence:
  - if:
      - condition: state
        entity_id: vacuum.valetudo_homecleanrobot
        state: docked
    then:
      - action: select.select_option
        target:
          entity_id: select.valetudo_homecleanrobot_maploader_map
        data:
          option: main
      - delay:
          hours: 0
          minutes: 0
          seconds: 20
          milliseconds: 0
      - action: mqtt_vacuum_camera.reset_trims
        data: {}
description: ""
icon: mdi:robot-vacuum

First floor / upstairs floor script [ID = first_floor]:

alias: Robot Vacuum Cleaner - First Floor
sequence:
  - if:
      - condition: state
        entity_id: vacuum.valetudo_homecleanrobot
        state: docked
    then:
      - action: select.select_option
        target:
          entity_id: select.valetudo_homecleanrobot_maploader_map
        data:
          option: first_floor
      - delay:
          hours: 0
          minutes: 0
          seconds: 20
          milliseconds: 0
      - action: mqtt_vacuum_camera.reset_trims
        data: {}
description: ""
icon: mdi:robot-vacuum

Then for the Xiaomi Vacuum Interactive Map Card Iā€™m using the following code twice with a different segments and the card visibility settings depending on the maploader floor status. I included a menu selection (menu_id: House Floor Map) to switch between each floor map.

type: custom:xiaomi-vacuum-map-card
map_source:
  camera: camera.robot_vacuum_cleaner_camera
calibration_source:
  camera: true
internal_variables:
  topic: valetudo/homecleanrobot
entity: vacuum.valetudo_homecleanrobot
vacuum_platform: Hypfer/Valetudo
card_mod:
  style: |
    ha-card {
      --map-card-room-outline-line-width: 0px;
    }
map_modes:
  - template: vacuum_clean_segment
    predefined_selections:
      - id: '1'
        icon:
          name: mdi:countertop
          x: 3575
          'y': 3170
        label:
          text: Kitchen & Dining Room
          x: 3575
          'y': 3170
          offset_y: 30
        outline:
          - - 3200
            - 3005
          - - 3950
            - 3005
          - - 3950
            - 3385
          - - 3200
            - 3385
      - id: '2'
        icon:
          name: mdi:paper-roll
          x: 3897
          'y': 3463
        label:
          text: Bathroom
          x: 3897
          'y': 3463
          offset_y: 30
        outline:
          - - 3795
            - 3430
          - - 4000
            - 3430
          - - 4000
            - 3550
          - - 3795
            - 3550
      - id: '3'
        icon:
          name: mdi:chair-rolling
          x: 3890
          'y': 3645
        label:
          text: Study
          x: 3890
          'y': 3645
          offset_y: 30
        outline:
          - - 3800
            - 3550
          - - 4000
            - 3550
          - - 4000
            - 3820
          - - 3800
            - 3820
      - id: '4'
        icon:
          name: mdi:stairs-down
          x: 3652
          'y': 3712
        label:
          text: Hallway
          x: 3652
          'y': 3712
          offset_y: 30
        outline:
          - - 3585
            - 3365
          - - 3800
            - 3365
          - - 3800
            - 3840
          - - 3585
            - 3840
      - id: '5'
        icon:
          name: mdi:sofa
          x: 3362
          'y': 3595
        label:
          text: Living Room
          x: 3362
          'y': 3595
          offset_y: 30
        outline:
          - - 3200
            - 3325
          - - 3585
            - 3325
          - - 3585
            - 3865
          - - 3200
            - 3865
  - template: vacuum_clean_zone
  - template: vacuum_goto
map_locked: false
append_tiles: true
tiles:
  - entity: sensor.valetudo_homecleanrobot_maploader_status
    label: Map Load Status
    icon: mdi:map-legend
append_icons: true
icons:
  - type: menu
    menu_id: Water_Amount
    tooltip: Water Amount
    entity: select.valetudo_homecleanrobot_water
    available_values_attribute: options
    icon: mdi:water
    icon_mapping:
      low: mdi:water-outline
      medium: mdi:water-opacity
      high: mdi:water
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        option: '[[value]]'
        entity_id: '[[entity_id]]'
  - type: menu
    menu_id: Robot Mode
    tooltip: Robot Mode
    entity: select.valetudo_homecleanrobot_mode
    available_values_attribute: options
    icon: mdi:robot-vacuum
    icon_mapping:
      mop: mdi:waves
      vacuum: mdi:fan-chevron-up
      vacuum_and_mop: mdi:hydro-power
    tap_action:
      action: call-service
      service: select.select_option
      service_data:
        option: '[[value]]'
        entity_id: '[[entity_id]]'
  - type: menu
    menu_id: House Floor Map
    tooltip: House Floor Map
    entity: select.valetudo_homecleanrobot_maploader_map
    available_values_attribute: options
    icon: mdi:home-floor-0
    icon_mapping:
      main: mdi:home-floor-0
      first_floor: mdi:home-floor-1
    tap_action:
      action: call-service
      service: script.turn_on
      service_data:
        entity_id: script.robot_vacuum_cleaner_[[value]]
visibility:
  - condition: or
    conditions:
      - condition: state
        entity: select.valetudo_homecleanrobot_maploader_map
        state: main
      - condition: state
        entity: select.valetudo_homecleanrobot_maploader_map
        state: unavailable
      - condition: state
        entity: select.valetudo_homecleanrobot_maploader_map
        state: unknown
1 Like

The new 2024.08.2 version of the camera is enabling the Auto Zoom functionality also for Rand256 users.
Did also made a substantial refactor of the rrpaser.py mainly to make it more pythonic (easy to read). Also updated the docs.
With almost 600 download of the previous version, if you appreciate this camera, please star this project on our GitHub Repository if you didnā€™t yet. This would be really appreciated :wink: and also help us to grow up this project.

Improvements and Refactoring

In the quest of improving the code of the Camera the init process and quality of the code was at focus on the 2024.09.0 that was released yesterday.

The camra also improve the compatibility with Home Assistant as per from state idle goes in streaming while rendering the images :wink:

In the next releases Iā€™m planning to detect whenever the maps change or have been reload on the Vacuums.

1 Like

Hi, thank you for your hard work! Reading this thread and your github, I understand the bug Iā€™m hitting is identified. The map doesnā€™t seem to update dynamically (roborock s5, latest valetudo), unless I call the ā€œreloadā€ action. I guess the refactoring mentionned on github is, amongst others, about fixing this? Or should I report it as an issue?

1 Like

Hello @hayvan96,

Yep, in order to load the camera a little faster I had to write down the maps trimsā€¦ this is why in the last versions I introduced the reset_trims action.
I hope to found a solution a little more friendly for it. As well when the maps of the vacuums will change the camera will probably detect it and do this reset_trims automatically (not store them till the vacuum is again docked). What Iā€™m currently working out is although going to be publish on the 2024.10.0 as there will be a lot of changes that are going a little slow due to personal reasons. I opened an issue as per Iā€™m aware of this ā€œinconvenienceā€. Anyhow once the maps are defined in the vacuumā€¦ the camera operate normally, isnā€™t it also in your case? I mean how often you rescan the complete floor? With Rand256 actually is possible to save (with the S5) the maps if you need to change often the maps. I will create on the next version a service that will do this (for the Rand256 vacuums, not clear with the official one is possible).

Thanks in any cases for using this camera, you are really welcome whenever you want or need to open issues, request new features or cooperate actively on this development.

Well our flat has a one step stair in the middle of it, so I have two parts (lower, higher). So saving map is not a option for me,as it should remember two different ā€œfloorsā€ knowing that the charger is only in one of them.

So once the whole area is mapped, itā€™s perfect. But before that, walls donā€™t update, or map doesnā€™t extend progressively to the extensive map, unless of course I call the reload action.

Okay I got itā€¦ so just for curiosity, your S5 is mapping with the Start command correct? thatā€™s just to understand if I can solve this or I need to add an enable / disable the store trim to cover this case :wink:

Yes it starts mapping (every time) when I launch it. Because of these two levels/floors, I havenā€™t enabled Persistent Maps in Valetudo

But when it finish the cycle, if the dock is not on the second levelā€¦ and there are no maps predefinedā€¦ mmmmm how the vacuum stop? Manually? you can build a kind of slide for the vacuum to go up and down from the step :laughing: of course I joke.

Anyhow I think we can work on a solution for this :slight_smile: especially because I donā€™t like it too that the walls are missing and it is necessary to reload constantly. Surely this will be fix on next version, please give me the time to complete it okay?

I repeat with Rand256 you can easily store the floors (Iā€™m not sure if with the official is possible to do it).

On the floor without dock, it returns to where it started, and then complains ā€œcanā€™t return to the dockā€.

Well probably you can use HA to detect when the vacuum is in returning to stop it and send it a precise pointā€¦I mean it looks it is a really particular scenario.

The vacuum has no problem to locate itself and works perfectly like it used to when connected to the Xiaomi cloud. Itā€™s exactly like having two or three floors in an house and one vacuum.The issue is only being able to follow how it is cleaning and if all the floor has been cleaned. I can do it via the Valetudo interface (webserver), not in homeassistant.
I know where I put it where I launch it on the chargerless floor and it will always return to the point, itā€™s fine.
At the beginning, the s5 was not able to save maps so it used to re scan the whole floor every time, even the one where the dock is.

I will work on it and soon release a beta version so that you can test if the re-scan works as it should be. I donā€™t know how I can finish to update the 2024.10.0 but I will do my best to help you with the initial issue you are facing :wink:

@hayvan96 I just released 2024.10.0b1 that include the attempt to fix the refresh issue. Note that when the vacuum start to clean you must run the reset_trims action in order to clear the trims_data. I repeat the vacuum start and then reset_trims is the correct sequence. The issue was closed automatically from GitHub but please feel free to comment on GitHub if this fix works or not. The camera will refresh the images every 5 frames if no trims_data are set.

Iā€™ve tried it. Started the vacuum and then called once the reset_trims action. It seems to work: the map autoadapts and extends progressively ; the robot doesnā€™t go across the walls (which was the visual impression I had before when the map was static and note accurate).

Meaningā€¦ that the image was compose improperly? Sorry I did catch well your description.
edit: if I read it again it looks that the issue is closed. Thanks for the for the feedback :slight_smile:

No i mean it works correctly. Before your change, walls were static (not updating) so the robot seemed to go across walls, but itā€™s no longer the case. Now ā€œnew wallsā€ (newly discovered by the robot) appear progressively, the map extends, etc. I have the same map in home assistant, and in the Valetudo (webserver) interface :+1:

Yes, itā€™s almost closed. I mean thereā€™s still a manual action to launch (reset trims), I guess this could be solved by an automation (when the robot goes stop to start, then call reset-trims once)?

well yes in your case the automation could be an option.
Send the command start to the vacuum and call reset trims afterwords, I repeat this is a particular scenario or I can also call the service as soon the coordinator work as it should (listening at the vacuum events). Another idea would be to have an option to actually store those trimsā€¦ Will think about itā€¦ but for instance the main issue is solved. Thanks once again for raising this topic.