Howto: Xiaomi vacuum zoned cleaning

Wow! Thanks for the heads up, will try it when I get home tonight!

I posted my call_service in NR to HA in my original post. Could you show me what youā€™ve done so far and maybe than I can see what maybe went wrong.

Sure.

Here are two screenshots showing the ha call service node in node red.

Selection_001 Selection_002

I created the zone within valetudo and named it ā€œbathroomā€. I tried with the zone name and with the coordinates that i took via ssh from valetudos config file. Both ways dont work.

If you need more information i will gladly provide it.
The vacuum works within HA and i can start cleaning via mqtt. Its just the zone cleaning that doesnt work.

Ok, strangeā€¦

Here is a screenshot from my call_service data.

And here is my whole call_service node from NR.

[{"id":"9846b891.2a3c48","type":"api-call-service","z":"8e02f22d.0542e","name":"Bed, bath, hall, wardrobe, living room","server":"56702eec.d56a5","version":1,"service_domain":"vacuum","service":"send_command","entityId":"vacuum.rockrobo","data":"{\"command\":\"zoned_cleanup\",\"params\":{\"zone_ids\":[\"bedroom\",\"bathroom\",\"hallway\",\"wardrobe\",\"livingroom\"]}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":401.25,"y":468.75,"wires":[["56e8c62d.122978"]]},{"id":"56702eec.d56a5","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

thanks, but doesnt work :slight_smile:
no idea whats wrong. is there a way to debug this?

Thatā€™s so weird. Can you post a screen of your fw version etc from the vacuum? Do you run valetudo?

yes i have valetudo
fw version: 3.3.9
fw build: 001886
valetudo version: 0.4.0

Iā€™m on the exact same fw and build and valetudo version. Could there be some problem be with the MQTTā€¦?

Tony (or anyone else that might be able to help),

I used your post to identify my zones. When I use the services tab under developer tools and input:

entity_id: vacuum.xiaomi_vacuum_cleaner
command: app_segment_clean
params: 18

My vacuum starts heading toward the proper zone and cleaning.

From there I setup an input_select and a params: template so I could choose the zone from the UI.

Looks like this:

- id: 'y1'
  alias: Vacuum Zone Cleaning
  trigger:
    - platform: state
      entity_id: input_boolean.vacuum_zone_cleaning
      to: 'on'
  action:
    - service: vacuum.send_command
      data_template:
        params: >
          {%- if is_state('input_select.zone', 'Room 1 (16)') -%}
            {{ 16 }}
          {%- elif is_state('input_select.zone', 'Room 2 (17)') -%}  
            {{ 17 }}
          {%- elif is_state('input_select.zone', 'Room 3 (18)') -%}
            {{ 18 }}
          {%- elif is_state('input_select.zone', 'Room 4 (19)') -%} 
            {{ 19 }}
          {%- elif is_state('input_select.zone', 'Room 5 (20)') -%} 
            {{ 20 }}
          {%- elif is_state('input_select.zone', 'Room 6 (21)') -%} 
            {{ 21 }}
          {%- else -%}
            {{ 22 }}
          {%- endif -%}
        command: app_segment_clean
        entity_id: vacuum.xiaomi_vacuum_cleaner

But I always get this error:
Unable to send command to the vacuum: {'code': -10005, 'message': 'data for segment is not a number'}

Any help, greatly appreciated,
Thanks

guys, there is a breaking change in 103 for xiaomi component, my script to clean multiple zones doesnt work anymore, i get error below

how can i convert it to a send_command, script? example 2 still works below, but it doesnt recognizes multiple zones

thnx


[homeassistant.components.script] Error executing script script.vacuum_clean_house_without_bureau. Service not found for call_service at pos 1: Unable to find service vacuum/xiaomi_clean_zone


vacuum_clean_house_without_bureau:
  alias: Living stofzuigen
  sequence:
  - service: vacuum.xiaomi_clean_zone
    data_template:
      entity_id: vacuum.roborock
      repeats: 1
      zone: 
      - [14300,17900,25800,25950]
      - [25480,17400,29530,22250]

vacuum_clean_hallway:
  alias: Hal stofzuigen
  sequence:
  - service: vacuum.send_command
    data:
      entity_id: vacuum.roborock
      params: [[25480,17400,29530,22250,1]]
      command: app_zoned_clean

edit: seems resolved by using this command instead:
- service: xiaomi_miio.vacuum_clean_zone

1 Like

Try the following instead:

- id: 'y1'
  alias: Vacuum Zone Cleaning
  trigger:
    - platform: state
      entity_id: input_boolean.vacuum_zone_cleaning
      to: 'on'
  action:
    - service: vacuum.send_command
      data_template:
        params: >-
          {%- if is_state('input_select.zone', 'Room 1 (16)') -%}
            [16]
          {%- elif is_state('input_select.zone', 'Room 2 (17)') -%}  
            [17]
          {%- elif is_state('input_select.zone', 'Room 3 (18)') -%}
            [18]
          {%- elif is_state('input_select.zone', 'Room 4 (19)') -%} 
            [19]
          {%- elif is_state('input_select.zone', 'Room 5 (20)') -%} 
            [20]
          {%- elif is_state('input_select.zone', 'Room 6 (21)') -%} 
            [21]
          {%- else -%}
            [22]
          {%- endif -%}
        command: app_segment_clean
        entity_id: vacuum.xiaomi_vacuum_cleaner

That should do the trick, but you can do it in a much easier way (assuming you always keep the segment ID at the end of the input_select option within () - and nothing is written afterwards):

- id: 'y1'
  alias: Vacuum Zone Cleaning
  trigger:
    - platform: state
      entity_id: input_boolean.vacuum_zone_cleaning
      to: 'on'
  action:
    - service: vacuum.send_command
      data_template:
        params: "{{ [states('input_select.zone').split('(')[1][:-1]|int] }}"
        command: app_segment_clean
        entity_id: vacuum.xiaomi_vacuum_cleaner

Please try it and let us know how it goes.

FYI, as per my testing, the 1S vacuum (and probably the S6x) allows cleaning, room cleaning and also zone cleaning from HA (although Mi Home only allows the first 2).

The params has to be a list. Try [18]

thank you for your response i tried this:

  action:
    - service: vacuum.send_command
      data_template:
        params: {{ [states('input_select.zone').split('(')[1][:-1]|int] }}
        command: app_segment_clean
        entity_id: vacuum.xiaomi_vacuum_cleaner

but i had to put quotes around params: {{ [states('input_select.zone').split('(')[1][:-1]|int] }} for it to pass a config check. Then when i attempt to run the automation, i get this error:
Unable to send command to the vacuum: {'code': -10005, 'message': 'data for segment is not a number'}

i am pretty sure i have also tried your first suggestion but i will try again later tonight i cant remember where, but somewhere on github i saw a similar issue with fan speed that suggested the code needed to be changed to accept the numbers. i am no where near a coder so i couldnā€™t even begin to diagnose it From my advice on Discord, i believe the config check requires the quotes but then the quotes make it not a number something to do with a string? still open for any suggestions and thank you

When I was looking at this Lovelace card, I noticed that it is mentioned that vacuum.send_command service does not support templating, which is why in my system, I actually have a script for each segment/area I want to clean. It could be something like:

automation:
  - id: 'y1'
    alias: Vacuum Zone Cleaning
    trigger:
      - platform: state
        entity_id: input_boolean.vacuum_zone_cleaning
        to: 'on'
    action:
      - service: script.turn_on
        data_template:
          entity_id: >-
           {% if states('input_select.zone') %}
              {{ [states('input_select.zone').split('(')[0].replace(" ", "") }}
           {% endif %}

script:
  room1:
    alias: Room 1
    sequence:
      - service: vacuum.send_command
        data:
          entity_id: vacuum.xiaomi_vacuum_cleaner
          command: app_segment_clean
          params: [16]
  room2:
    alias: Room 2
    sequence:
      - service: vacuum.send_command
        data:
          entity_id: vacuum.xiaomi_vacuum_cleaner
          command: app_segment_clean
          params: [17]
...

Try it out and let us know how it goes

1 Like

Missing quotes were my mistake, as you need it in one-liner templates. Fixed it in my previous answer already.

Sorry, yes, that was also the conclusion in the Discord conversation. Thank you for confirming this. So, I just did different room automations with the input_select information as a condition. This allows me to also template vacuum.set_fan_speed in a similar fashion as you did vacuum.send_command and it works well. Odd that vacuum.set_fan_speed can be templated but vacuum.send_command canā€™t. Oh well, such is Home Assistant. Thanks again!!!

Hello, I have been using my roborock S50 with HA for the past few months and it has been working fine, until nowā€¦
Iā€™m not sure when the problem happened but itā€™s definitely during the past few weeks although I havenā€™t updated anything on my hassbian.
Now, I can still use the web interface to monitor the robot and issue basic orders (clean, change fan speed, return to dockā€¦) but the cleaning zones are not working anymore (nothing happens except the normal popup ā€œService input_select/select_option called.ā€). Furthermore, IFTTT is not working at all anymore (basic orders + cleaning zones).
I spent a lot of time setting this up this year, and I honestly donā€™t have the will to start from scratch again.
I havenā€™t found anything in the logs so Iā€™m a little out of ideasā€¦

Which service is called for zoned cleanup? Because it was changed.

Itā€™s ā€œvacuum.send_commandā€ but I havenā€™t updated HA recently.
Moreover, if I call the rooms scripts from the developer tools, itā€™s workingā€¦

I restored a backup of the entire system, itā€™s working fine now.
There has been a few power outages recently, I suspect it has corrupted HA. Looks like itā€™s not very resilientā€¦