[SOLVED] Rule for Xiaomi vacuum, multi zone cleaning


i like to implement the following scenario but i’m not sure if and how this may could be done.
maybe someone could point me in the right direction.

the idea is to have a certain amount of proxy items, like the below one to select the zones which shall be cleaned. then maybe via a .MAP file to determine the coordinates for the zones and send then a single command to the vacuum.

proxy items:

Group gVacProx "Vacuum Proxys"

Switch pVacAll  "All"               (gVacProx)
Switch pVacMBR  "Master Bedroom"    (gVacProx)
Switch pVacGR   "Guest Room"        (gVacProx)
Switch pVacGR2  "Guest Room 2"      (gVacProx)
Switch pVacKI   "Kitchen"           (gVacProx)
Switch pVacLR   "Living"            (gVacProx)
Switch pVacCD   "Corridor"          (gVacProx)

map file

"Master Bedroom"=[20609,22587,25009,28237,1],[21223,20086,22723,22786,1]
"Guest Room"=[23222,16714,26622,21164,1]
"Guest Room 2"=[30466,22834,36816,28284,1]

vacuum command example for 3 zones


i tried, maybe in at the wrong place, to find an example of how i could use a map transform to read out the zone information for each item with an “ON” status of the gVacProx group and add the zone information of those items in one sendCommand like the above example.

i would be more than happy if someone could point me in the right direction.

regards Matt

I’m not sure if this will work as intended. First point is, the .map file left side shall not have quotes (and neither the right side), instead you have to escape the space:

Master\ Bedroom=[20609,22587,25009,28237,1],[21223,20086,22723,22786,1]
Guest\ Room=[23222,16714,26622,21164,1]
Guest\ Room\ 2=[30466,22834,36816,28284,1]

I guess the rule to build the command is something like this:

var String sCoordinates = ""                                                       // has to be global to work in lambda

rule "start vaccuum"
    Item startMyVacuumCleaner received command ON                                  // or some other trigger...
    if (gVacProx.members.filter[r|r.state == ON].size != 0) {                      // Start only if at least one switch is set to ON
        sCoordinates = ""                                                          // (re-) initialize var
        gVacProx.members.filter[r|r.state == ON].forEach[r|                        // for each switch set to ON
            sCoordinates=sCoordinates + transform("MAP","room.map",r.label) + ","  // add it to a string
        sCoordinates = sCoordinates.substring(0,sCoordinates.length - 1)           // get rid of last comma
        if(pVacAll.state == ON) sCoordinates=transform("MAP","room.map","All")     // if All is active, use simple map
        actionCommand.sendCommand("app_zoned_clean["+sCoordinates+"]")             // start cleaning

@Udo_Hartmann, Thanks a lot.
i just add your code and it’s working perfectly.

thanks a lot for the quick help :+1:

Cool :slight_smile: