Vacuum Interactive Map Card

Just incase anyone in wondering this won’t work with valetudo out of the box unless there are some major changes

valetudo requires that you run a mapping clean then create zones, you clean the zones by calling the zones directly by name and not co-ordinates every attempt i tried using co-ordinates results in the robot doing a loop then return to base.

secondly valetudo uses a different y axis if you get the co-ordinates from /api/get_config you need to subtract y from 51200 (x stays the same) this is shown here

what you can do is draw the co-ordinates in the lovelace card call the python script, have the script match the params and call the zone.

alternatively you can make a picture element card and just call the zones on click on the icon

elements:
  - icon: 'mdi:broom'
    style:
      '--iron-icon-fill-color': '#777'
      left: 70%
      top: 90%
    tap_action:
      action: call-service
      service: vacuum.send_command
      service_data:
        command: zoned_cleanup
        entity_id: vacuum.rockrobo
        params:
          zone_ids:
            - Kitchen
    type: icon
image: /local/img/vacuum_map.png
type: picture-elements

if 3_14 can make a valetudo mode where clicking on the zone on the map just calls the send command zone cleanup then that’s the only idea i have to get valetudo working in this card

1 Like

As far as I know Valetudo supports 2 commands for zoned cleanup: zoned_cleanup for named zones and app_zoned_clean for zones defined by coordinates (implemented here), so you should be able to use this card just fine (after making sure you use right coordinates for calibration).

You can check out comments in this issue on my GitHub for more info about Valetudo compatibility.

thanks for that calibration was easy after working out you can dump the co-ordinates from the config and subtracting both y from 51200, but when i use your lovelace card it calls app_zoned_clean, the area gets drawn in valetudo but the vacuum doesn’t clean the zone it just makes a weird path and returns to the dock i’ll try get a screen shot tomorrow.

Please include coordinates and screenshot of both card and valetudo maps if possible

well i just ran the robot in the middle of the night hope this helps you out

this is a part of the card but should be the relevant area

the card
captures 1

the debug co-ordinates

Imgur

this is valetudo it maps the zone but the robot does weird pathing gets stuck and returns home. but if you ask it to clean the zone by name it would do its usual where it does the perimeter then portions up the room and does it in sections.
Imgur

this is the zone in get_config

["Master",[[28895,20764,33856,26101,1],[33877,24793,37527,29401,1]]]

this is the mapping calibration

  - map:
      x: 405
      'y': 338
    vacuum:
      x: 18651
      'y': 20708
  - map:
      x: 470
      'y': 338
    vacuum:
      x: 21597
      'y': 20708
  - map:
      x: 469
      'y': 273
    vacuum:
      x: 21597
      'y': 23798

Running a vacuum at 3 AM is an essential part of developing this card :wink:

Do you use FloleVac? Do other modes work correctly?
Valetudo does some weird coordinates conversions, it is possible that coordinates from get_config do not match ones used in app_zoned_clean and app_goto_target.

1 Like

i have it in nox but i dont use it much, trying to do everything in home-assistant. i can do everything in valetudo itself so that’s the stop gap measure

yes the co-ordinates dont match, i’ve been manually modifying them as valetudo changes it with this value

    DIMENSION_MM: 50 * 1024,

in Tools.js

/* zones is an array of areas to clean:  [[x1, y1, x2, y2, iterations],..] */
Vacuum.prototype.startCleaningZoneByCoords = function(zones, callback) {
    if(Array.isArray(zones) && zones.length <= 5) {
        const flippedZones = zones.map(zone => {
            const yFlippedZone = [
                zone[0],
                Tools.DIMENSION_MM - zone[1],
                zone[2],
                Tools.DIMENSION_MM - zone[3],
                zone[4]
            ];

            // it seems as the vacuum only works with 'positive rectangles'! So flip the coordinates if the user entered them wrong.
            // x1 has to be < x2 and y1 < y2
            return [
                yFlippedZone[0] > yFlippedZone[2] ? yFlippedZone[2] : yFlippedZone[0],
                yFlippedZone[1] > yFlippedZone[3] ? yFlippedZone[3] : yFlippedZone[1],
                yFlippedZone[0] > yFlippedZone[2] ? yFlippedZone[0] : yFlippedZone[2],
                yFlippedZone[1] > yFlippedZone[3] ? yFlippedZone[1] : yFlippedZone[3],
                yFlippedZone[4]
            ]
        });

        this.sendMessage("app_zoned_clean", flippedZones, {}, callback)
    } else {
        callback(new Error("Zones must be array of at most 5 zones."))
    }
};

i havent had time to look through valetudo yet so it might be something funky in there.

since i only use zone cleaning after the initial discovery my map hasnt dissapeared. i never had to redo any co-ordinates on the S5

In FloleVac you can check currently selected zone for zoned cleanup.
Could you check if “goto” and “freehand drawn zones” work on your case?
Do you use mqqt to communicate with vacuum?

i just tried to get flolevac to connect to the valetudo setup diretly but it just stuck trying to load the map

goto works
zone cleaning works

i have both the xiaomi_miio component and the mqtt auto discovered, the card is pointing the to xiaomi_miio version

If goto and zones work correctly then I would suggest to define zones using coordinates from debug mode in card.

If above doesn’t work you can try to use mqtt instead of miio.

mqtt gets this error when using zones

Failed to call service vacuum/send_command. dictionary update sequence element #0 has length 5; 2 is required

Have you tried creating zones using debug?

I’ve been running this card for a while and looking to refine my automations now (I would usually just run a standard whole house cleanup) and looking to sort out my zones.

I’m hitting this issue though when creating zones; Firstly, I have the calibration points set for my image. I’ll then have Zone Cleanup selected in the card and select a couple of zones:

With debug enabled, I get the coordinates returned and I’ll feed them into the card config for a zone:

default_mode: predefined_zones
zones:
  - [[23407,22442,28293,30658],[29006,28463,31625,29687]]

Next, I select Zones mode in the card and I get this:

Any suggestions on how I can sort this? It seems to either be out or I’m doing something wrong…

Thanks in advance.

Edit: I’ve just attempted the whole calibration again from scratch and same issue.

Also, to show my calibration method against my map image:

Hi, I suggest to calibrate card using method from this post:

Using points that are close to each other can cause problems related to error cumulation on bigger distances.

Is there a way to do this without Flolevac?

FloleVac is the easiest way, but you can do it by calling service vacuum.xiaomi_clean_zone in HA and trying different coordinates.
Data:

{
  "entity_id": "vacuum.xiaomi_vacuum",
  "zone": [[25500, 25500, 26500, 26500]],
  "repeats": 1
}

Just wondering if this add the zone feature to the original xiaomi gen1?

Yes, you can use this card to save zones, but you have to be aware of map rotation issue:

This looks like a great addition to Home Assistant, however I have small understanding issue :smile:

I used community store and installed the plugin, then I have opened raw lovelace editor and added reference under resources

  - type: module
    url: /community_plugin/lovelace-xiaomi-vacuum-map-card/xiaomi-vacuum-map-card.js

After that I’m a bit lost as when I try adding new element in lovelace, I select “+” -> Manual Card -> then I paste following:

views:
- name: Example
  cards:
    - type: custom:xiaomi-vacuum-map-card
      entity: vacuum.xiaomi_vacuum
      map_image: '/local/custom_lovelace/xiaomi_vacuum_map_card/map.png'
      calibration_points:
        - vacuum:
            x: 25500
            y: 25500
          map:
            x: 466
            y: 1889
        - vacuum:
            x: 26500
            y: 26500
          map:
            x: 730
            y: 1625
        - vacuum:
            x: 25500
            y: 26500
          map:
            x: 466
            y: 1625
      zones:
        - [[25500, 25500, 26500, 26500]]
        - [[24215, 28125, 29465, 32175]]
        - [[24245, 25190, 27495, 27940], [27492, 26789, 28942, 27889]]
        - [[28972, 26715, 31072, 27915], [29457, 27903, 31107, 29203], [30198, 29215, 31498, 31215], [29461, 31228, 31511, 32478]]

Then I see this code in red :frowning:

I understand that I’m somewhere totally wrong, but not sure where and not sure how I could do it.
Please help…

This is aconfiguration of a whole view, you have to remove everything above - type: 'custom:...'