Multiple choice "menu" for selecting zones for vacuum clener

Hello,
could you please help me in the following scenario. I would like to create a predefined list of zones for Xiaomi/Roborock S55 vacuum cleaner with a possibility to select which zone or zones should be cleaned up and then fire the cleaning up. I imagine it as a set of on-off switches named, let’s say:

  • living room
  • bedroom
  • bathroom
  • hallway

And a button “Start” (scene’s “activate”?). I am selecting bedroom and hallway, hit Start and the vacuum cleans only these 2 zones.
This is the first issue - I’ve got no idea how to design such multiselect “menu” using HA’s components. I assume that when hit the “start” HA passes a list of zones to the service call. And this is a second issue - how to pass a variable number of entries to the array of zones according to integration specs (https://www.home-assistant.io/components/vacuum.xiaomi_miio/):

action:
    - service: vacuum.xiaomi_clean_zone
(...)
        zone:
        - [30914,26007,35514,28807]
        - [20232,22496,26032,26496]

Any help will be appreciated. Even the general tips from where to begin.

Not hard to do at all but will take time to setup all your zones …this is my main package for the vacuum https://github.com/Vasiley/Home-Assistant-Main/blob/6f2e7f7a97c28a517807b8174db4387aa724a4df/packages/equipment_xoiaomi_vacuum.yaml and that package calls other packages that are basically scripts for other rooms. Dont get confused by some of it. I have door/window sensors that vacuum looks at if they are open or closed ie. the mud room (we dont want here in there so it makes sure door is closed)

Thanks for the reply Vasiley, I’ll take a look.

I made a quick analyse and wonder how do you select to clean ie. Living Room AND Kitchen in one call before the vacuum start? As far as I know, input_select allows only to select one element at a time. Unless the vaccum starts doing the first selected job and you select another and its enlisted as “TODO” on something like “vacuum_jobs_card” and the vacuum starts mentioned kitchen after it finishes cleaning living room?

with - wait_template: "{{ is_state('input_boolean.boolean_susie_home', 'on') }}"

kinda misread what you wrote …i dont have a input select for the kitchen/living room …its just a nightly routinue

OK that’s not exactly what I’d like to achieve. But thanks anyway.

I’ve found a partial solution for my issue. I’ve done menu by using input_boleans and written a template to select the zones I want to clean:

{% if is_state('input_boolean.clean_livingroom', 'on') %}
- [17514,25754,21564,32204]{% endif %}{% if is_state('input_boolean.clean_bedroom', 'on') %}
- [21665,28237,24515,32237]{% endif %}{% if is_state('input_boolean.clean_room', 'on') %}
- [24608,27075,27308,32025]{% endif %}{% if is_state('input_boolean.clean_bathroom', 'on') %}
- [24379,25119,27229,27069]{% endif %}{% if is_state('input_boolean.clean_hallway', 'on') %}
- [20821,25131,24621,28231]{% endif %}

This works perfectly in HA website’s “Templates” editor. Can anybody help me with applying this to the automation? The schema is:

action:
    - service: vacuum.xiaomi_clean_zone
(...)
        zone:
        (the above goes here as a template)

did you look thru what i gave you in my packages …I already have a input select working for every room in my house

Yes, but as I mentioned this is not exactly I’d like to achieve. As I said, I’d like to use input_booleans not input_select. I made a quick preview what I’d like. Here’s the HA controls:
ha
and a result in Xiaomi’s app after clicking on “CLEAN!” (it’s not working for now, the screen is prepared in the app; it’s only works if I define the zones as static):

In case someone needed the solution, I figured it out.

  1. in configuration.yaml enable python scripts:
    python_script:
  2. in configuration.yaml create input_boolean switches:
input_boolean:
  clean_livingroom:
    name: "LIVINGROOM"
    initial: off
  clean_bedroom:
    name: "BEDROOM"
    initial: off
  clean_room:
    name: "NAT'S ROOM"
    initial: off
  clean_bathroom:
    name: "BATHROOM"
    initial: off
  clean_hallway:
    name: "HALLWAY"
    initial: off
  1. create a folder where scripts will be stored: <ha_config>/python_scripts
  2. python script named xiaomi.py:
args = {"entity_id": "vacuum.xiaomi_vacuum_cleaner", "repeats": "1","zone":[]}

zone_livingroom = data.get("input_boolean.livingroom")
zone_bedroom = data.get("input_boolean.bedroom")
zone_room = data.get("input_boolean.room")
zone_bathroom = data.get("input_boolean.bathroom")
zone_hallway = data.get("input_boolean.hallway")


if zone_livingroom == 'on':
  args["zone"].extend([[17514,25754,21564,32204]])
if zone_bedroom == 'on':
  args["zone"].extend([[21665,28237,24515,32237]])
if zone_room == 'on':
  args["zone"].extend([[24608,27075,27308,32025]])
if zone_bathroom == 'on':
  args["zone"].extend([[24379,25119,27229,27069]])
if zone_hallway == 'on':
  args["zone"].extend([[20821,25131,24621,28231]])

hass.services.call('vacuum', 'xiaomi_clean_zone', args)
  1. scripts.yaml part:
clean_xiaomi:
  alias: "xiaomi clean action"
  sequence:
    - service: python_script.xiaomi
      data_template:
       input_boolean.livingroom: '{{ states.input_boolean.clean_livingroom.state }}'
       input_boolean.bedroom: '{{ states.input_boolean.clean_bedroom.state }}'
       input_boolean.room: '{{ states.input_boolean.clean_room.state }}'
       input_boolean.bathroom: '{{ states.input_boolean.clean_bathroom.state }}'
       input_boolean.hallway: '{{ states.input_boolean.clean_hallway.state }}'
  1. ui-lovelace.yaml:
    - type: custom:vertical-stack-in-card
        cards:
            type: entities
            title: "Vacuum"
            show_header_toggle: false
            entities:
              - input_boolean.clean_livingroom
              - input_boolean.clean_bedroom
              - input_boolean.clean_room
              - input_boolean.clean_bathroom
              - input_boolean.clean_hallway

          - type: entity-button
            name: "CLEAN!"
            entity: script.clean_xiaomi
            show_icon: false
            tap_action:
              action: call-service
              service_data:
                entity_id: script.clean_xiaomi
              service: script.turn_on

Of course it might be done better but I’d like to show a general config. Digging community I found the info that zones cannot be templated in yaml since they accept python tables as an argument. There is an open issue on github to fix the ‘zone’ part to enable templates. So the method above is a workaround.

4 Likes

Hi Damian, thanks for your job.
I used your code but I don’t know how to complete the step 6 to combine the button inside the vertical stack. Now I have 2 different cards (first with boleans and 2 with button) but do not works.
Do you know how can i solve-it?

Many thanks

Hi Miquel,
can you please post a screenshot? Moreover, please note that in one of the recent Home Assistant update some services changed names and that might be the reason it is not working for you, for example in xiaomi.py:
was:
hass.services.call(‘vacuum’, ‘xiaomi_clean_zone’, args)
now it is changed to:
hass.services.call(‘xiaomi_miio’, ‘vacuum_clean_zone’, args)

I also changed the scripts.yaml a little to the recommended by HomeAssistant team form (but is is not necessary for now I think):

clean_xiaomi:
  alias: "xiaomi clean action"
  sequence:
    - service: python_script.xiaomi
      data_template:
       input_boolean.livingroom: '{{ states("input_boolean.clean_livingroom") }}'
       input_boolean.bedroom: '{{ states("input_boolean.clean_bedroom") }}'
       input_boolean.room: '{{ states("input_boolean.clean_room") }}'
       input_boolean.bathroom: '{{ states("input_boolean.clean_bathroom") }}'
       input_boolean.hallway: '{{ states("input_boolean.clean_hallway") }}'
       input_number.passes: '{{ states("input_number.xiaomi_passes") | int }}'
       input_select.power: '{{ states("input_select.xiaomi_power") }}'

Hi Damian,

This is a screenshot of my cards.


I changed the xiaomi.py and scripts.yaml but is not working.

I’ll read again all the code looking for changes in last update.

If you have any idea about have to solve it, i’ll apreciate it.

Thanks in advanced.

Hello,
I have a card with an input select every day of the week for selecting the zone for the vacuum to cleanup automaticly.


i have a script with the coordinate of every zone:

'1594741403275':
  alias: Salle à manger
  icon: mdi:table-chair
  sequence:
  - data:
      command: app_zoned_clean
      params:
      - - 23081
        - 20668
        - 28131
        - 27218
        - 1
    entity_id: vacuum.xiaomi_vacuum_cleaner
    service: vacuum.send_command
'1594741608430':
  alias: Cuisine
  icon: mdi:fridge-outline
  sequence:
  - data:
      command: app_zoned_clean
      params:
      - - 21121
        - 16117
        - 26121
        - 20867
        - 1
    entity_id: vacuum.xiaomi_vacuum_cleaner
    service: vacuum.send_command
'1594741653987':
  alias: Couloir
  icon: mdi:shoe-formal
  sequence:
  - data:
      command: app_zoned_clean
      params:
      - - 25749
        - 16115
        - 30799
        - 20265
        - 1
    entity_id: vacuum.xiaomi_vacuum_cleaner
    service: vacuum.send_command

And i have an automatisation for launching the select script of the day:

- id: '1594723468692'
  alias: Aspirateur
  description: ''
  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''input_datetime.heure_passage_aspirateur'')[0:5]
      }}'
  condition:
  - condition: state
    entity_id: sensor.aspi_day
    state: 'True'
  action:
  - value_template:  >
       {% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
       {% set today_name = sensor_names[now().weekday()] %}
       {% set entitid = 'input_boolean.arr_bambou_'+today_name %}
  - data:
    alias: {{ states.entitid.state }}
    service: script.turn_on  

The problème i have is that i can’t manage to get the value in the inputselect (the name of the script) to launch the script.
Can someone please help me?

Hi Damian

Works like a charm.
I want to replace the zone params with room numbers.
Any idea how to do that?

Note that syntax has changed slightly in python script…

hass.services.call(‘xiaomi_miio’, ‘vacuum_clean_zone’, args)

@GGeudens I also wanted to use room numbers and that means changing to segments instead of zones.
In the python change to:
args = {“entity_id”: “vacuum.entity”, “segments”:[]}
args[“segments”].extend([ROOM_NUMBER])
hass.services.call(‘xiaomi_miio’, ‘vacuum_clean_segment’, args)