[Howto] Buttons for Room Cleaning (with Queuing) for [Xiaomi Miio] (Robot Vacuum)

That’s odd, seems like it’s ok when i test it. That’s the correct payload anyway.
Do you have “input_number.vacuum_repeat” helper created? If not, it might be receiving repeat: 0 and since it’s false it would do 1 try.

Go to Home Assistant → Developer Tools → Templates and at the end of textbox type:

{% set repeat = states("input_number.vacuum_repeat") | int %}
[{"segments":[16],"repeat":{{ repeat }}}]

On the right side it should return something like:

[{"segments":[16],"repeat": 1}]

With 1 being the value of input_number.vacuum_repeat.
If it’s 0 or something else, you may be using wrong entity name for your input_number.

Or… Ultimately… Your vacuum might be using some other syntax, this is proven to work with S5 Max

1 Like

Yes! You were right, my “input_number.vacuum_repeat” had the wrong Entity ID. I named my first helper “input_number.vacuum_repeat” so the Entity ID thus became “input_number.input_number.vacuum_repeat”. With the new name “vacuum_repeat” everything is working

Thank you so much for the help

good day. use SERVICE XIAOMI_MIIO.VACUUM_CLEAN_SEGMENT in automation. I can not get a replay of cleaning segments. what to do? thanks in advance to those who helped

You’re very much welcome, glad it helped!

This doesn’t belong here. Please open a thread for your question.

Sorry for being a bit absent - I was moving and still in the process of getting HA ready. Heating is considered more important than automation of a vacuum these days. Not sure why ;D

Actually, I would like to integrate the crisscross pattern as well as abort/return to dock/start anew.

The second one is kind of important if you have somewhat unregular schedules and just want the robot to automatically find the spot when you’re longer not at home and clean.

So if you’re just 10 minutes away, the robot might be able to clean one room, return to the dock and wait for the next opportunity to clean the rest. Or is not able to clean the room, abort and redo the room on the next opportunity.

Just a note here to say that this all worked really well for me. I made a few foolish mistakes (tried to paste the two automations into scripts, for instance, and accidentally copied/pasted an apostrophe prefacing my input_number. But all is working really well now.

Just a note that probably is obvious but I might as well say it. If you open the Mi Home app when you are trying to figure out the room numbers, you’ll be able to see the room highlighted when your robot is headed that way. It takes a few seconds, but it’s better than waiting and chasing the machine down. I kept a tab open to the “Vacuum paused for 5 minutes…” automation and just clicked on Run Actions as soon as I saw the room highlighted. That made selecting rooms a little easier/quicker than physically chasing them down.

Again, probably obvious to most readers here but worth a mention just in case.

Thanks again, @RubenKelevra!

1 Like

Hi Matt,

I ran similar issue and I’m wondering if you did manage to solve it?

When I call the script via button below, my vacuum start cleaning and return to base after some seconds. My issue is that I don’t know where I should enter my room ID in button.

My button configuration looks like that:

type: entity-button
tap_action:
  action: call-service
  service: script.1643221182220
  service_data:
    room: hallway
  target: {}
entity: script.1643221182220
icon_height: 60px
icon: hass:robot-vacuum
name: Sprzątaj w korytarzu
show_state: true
show_icon: true
show_name: true

Hi Ruben,

thanks for your script, nice job!

Script itself works and call vacuum to start cleaning :slight_smile: but only for few seconds as I’m not sure how to tell the script what room ID he should go to.
When I’m testing my script via developer settings as you explained I got no result, nothing happen. What I might done wrong?

Hey @k1ohm,

first make sure you extended or changed the list of room-ids in the script you copied, as explained below the script:

Extend or change the room field’s selector.select.options as necessary. All valid room ids need to be listed here.

Then read the section about “Room number definition”:

I think you missed doing this step. If it’s not clear what to do, just ask again :slight_smile:

Hi and thank for a great script/automation.
I have two questions that I can’t find answer to.

  1. How can I make a button to tell robot to go to X, Y position?
  2. How to make a button to go to dock?
    Hope I do this community right, new to HA and all it means :slight_smile:

Hi @RubenKelevra,

thanks for reaching out. I’ve checked those steps and it looks good for me :slight_smile: :thinking:

Blockquote
Extend or change the room field’s selector.select.options as necessary. All valid room ids need to be listed here.
Blockquote

Done, see part of your script where I’ve changed my room names (full adjusted script below):
Looks good :thinking:

  fields:
    room:
      name: Room
      required: true
      example: kitchen
      selector:
        select:
          options:
          - bedroom
          - saloon
          - office
          - hallway
          - kitchen
          - bathroom
          - hall

Example “Room number definition” snip:

When script is called via button card shown below, then it goes to kitchen but I’m not sure why I cannot define room ID in that script :frowning:

type: entity-button
tap_action:
  action: call-service
  service: script.1643221182220
  service_data:
    room: kitchen
  target: {}
entity: script.1643221182220
icon_height: 60px
icon: hass:robot-vacuum
name: Sprzątaj w kuchni
show_state: true
show_icon: true
show_name: true

Full script:

'1643221182220':
  mode: queued
  alias: Roborock Room Cleaning
  max: 30
  fields:
    room:
      name: Room
      required: true
      example: kitchen
      selector:
        select:
          options:
          - bedroom
          - saloon
          - office
          - hallway
          - kitchen
          - bathroom
          - hall
  sequence:
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: vacuum.stefan
          state: cleaning
        - condition: state
          entity_id: vacuum.stefan
          state: error
      sequence:
      - wait_for_trigger:
        - platform: state
          entity_id: vacuum.stefan
          to: returning
        - platform: state
          entity_id: vacuum.stefan
          to: docked
        continue_on_timeout: false
        timeout: 01:30:00
      - service: vacuum.send_command
        target:
          device_id: fd75591fafb364ead290fb0e7d529e68
        data_template:
          command: app_segment_clean
          params: '{% set room_id = states("input_number.roborock_room_enum_" + room)
            | int %} {{ room_id }}

            '
      - wait_for_trigger:
        - platform: state
          entity_id: vacuum.stefan
          to: returning
        - platform: state
          entity_id: vacuum.stefan
          to: docked
        continue_on_timeout: false
        timeout: 01:30:00
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: vacuum.stefan
          state: returning
        - condition: state
          entity_id: vacuum.stefan
          state: docked
        - condition: state
          entity_id: vacuum.stefan
          state: idle
      sequence:
      - service: vacuum.send_command
        target:
          device_id: fd75591fafb364ead290fb0e7d529e68
        data_template:
          command: app_segment_clean
          params: '{% set room_id = states("input_number.roborock_room_enum_" + room)
            | int %} {{ room_id }}

            '
      - wait_for_trigger:
        - platform: state
          entity_id: vacuum.stefan
          to: returning
        - platform: state
          entity_id: vacuum.stefan
          to: docked
        continue_on_timeout: false
        timeout: 01:30:00
    default: []

Hello.

Maybe there are better ways, but the below work very good for me (don’t forget to change vacuum.your_vacuum_name by your own vacuum entity_id and the params below by the ones you need).

In an entity card, put:

      - name: Come Outside
        tap_action:
          action: call-service
          service: vacuum.send_command
          service_data:
            entity_id: vacuum.your_vacuum_name
            command: app_goto_target
            params:
              - 25617
              - 25136
        icon: mdi:robot-vacuum
        type: button
      - name: Go Home
        tap_action:
          action: call-service
          service: vacuum.return_to_base
          service_data:
            entity_id: vacuum.your_vacuum_name
        icon: mdi:robot-vacuum
        type: button
1 Like

Hello, i have a problem after pasting the script, when checking configuration:

Unexpected error calling config validator: ‘int’ object is not iterable

Can someone help fix it?
input_numbers are entered in configuration.yaml

Hey,
Thanks! It’s all working great, but I was wondering if it’s possible to choose repeats for each room? (or generally for all of them?)
I can of course send the vacuum twice to the same room but it’s different, the roborock does a different route if it’s set to 2-3 repeats

1 Like

I too am looking for an answer to your question. I’m trying to perform the 2 cycle crosshatch pattern on each room when cleaning multiple rooms.

yeah exactly.
I found this method, but I don’t know how to convert it to the specific room method because the actions are different

- service: xiaomi_miio.vacuum
    target:
      entity_id: vacuum.roborock
    data:
      repeats: 2
      zone:
      - 22976

I figured it out using scripts for each room x2 (crosshatch) and combined them in a single automation. The trick was catching the vacuum in the state returning after cleaning one room and then calling the next room script.

Here’s my automation for multiple rooms cleaned 2X with crosshatch pattern.


alias: vacuum back of house
description: ''
trigger:
  - platform: time
    at: '12:00:00'
condition:
  - condition: state
    entity_id: input_boolean.home
    state: 'on'
action:
  - service: script.vacuum_hallway
    data: {}
  - wait_for_trigger:
      - platform: template
        value_template: '{{ is_state(''vacuum.rosie'',''returning'') }}'
  - service: script.vacuum_office
    data: {}
  - wait_for_trigger:
      - platform: template
        value_template: '{{ is_state(''vacuum.rosie'',''returning'') }}'
  - service: script.vacuum_guest_bedroom
    data: {}
  - wait_for_trigger:
      - platform: template
        value_template: '{{ is_state(''vacuum.rosie'',''returning'') }}'
  - service: script.vacuum_master_bedroom
    data: {}
mode: single


and one of the scripts. I’m using the room designation vs zoned.


alias: Clean the office
sequence:
  - service: vacuum.send_command
    target:
      entity_id: vacuum.rosie
    data:
      command: app_segment_clean
      params:
        - 17
        - 17
mode: single
icon: mdi:robot-vacuum


Best of luck, Michelle

1 Like

I know that there are a number of guides on the forum that should guide you. I came from homebridge, so I already had the room numbers. You could slowly figure it out by starting with 16 (1-15 is used for other things). Trigger your script or automation and see what room the robot goes to clean. Keep changing by one number to find each room number.

I already have my room numbers, I actually have a successful daily routine, vacuum all my selected rooms, goes back to charge, and the mop all my selected rooms. It does it every day when no one’s at home. It works great. Only thing it doesn’t do is x2 crosshatch. I’ll give your method a try

1 Like