[SOLVED] Rule for Xiaomi vacuum, multi zone cleaning

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:

All=[20618,16019,36718,28319,1]
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]
Kitchen=[27261,17993,31011,21343,1],[27224,16569,28624,18069,1],[28567,16763,29067,17613,1]
Living=[25105,22682,30305,28232,1]
Corridor=[32069,19389,33719,21439,1],[23708,21281,34808,22581,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"
when
    Item startMyVacuumCleaner received command ON                                  // or some other trigger...
then
    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
    }
end
5 Likes