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

Some notes before we start:

  • This is not exactly a blueprint, but I still like to share it anyway with you.
  • It is made for my Roborock S6 MaxV, but it should work with other Xiaomi/Roborock models as well.
  • This how-to has been created with the Xiaomi Mii integration in mind.
  • If you use a different integration, you most certainly need to do modifications. Feel free to create forks and let me know, so I can link them.
  • License of source code: AGPL 3.0

Goal

Create buttons that start cleaning each room. When the cleaning is still in progress, wait for completion before sending the robot to the next room.

Main Script

mode: queued
alias: Roborock Room Cleaning
max: 30
fields:
  room:
    name: Room
    required: true
    example: living_room
    selector:
      select:
        options:
          - bathroom
          - bedroom
          - hallway
          - kitchen
          - living_room
          - stairway_landing
sequence:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: vacuum.roborock_vacuum_a10
                state: cleaning
              - condition: state
                entity_id: vacuum.roborock_vacuum_a10
                state: error
        sequence:
          - wait_for_trigger:
              - platform: state
                entity_id: vacuum.roborock_vacuum_a10
                to: returning
              - platform: state
                entity_id: vacuum.roborock_vacuum_a10
                to: docked
            continue_on_timeout: false
            timeout: '01:30:00'
          - service: vacuum.send_command
            target:
              device_id: 1234567
            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.roborock_vacuum_a10
                to: returning
              - platform: state
                entity_id: vacuum.roborock_vacuum_a10
                to: docked
            continue_on_timeout: false
            timeout: '01:30:00'
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: vacuum.roborock_vacuum_a10
                state: returning
              - condition: state
                entity_id: vacuum.roborock_vacuum_a10
                state: docked
              - condition: state
                entity_id: vacuum.roborock_vacuum_a10
                state: idle
        sequence:
          - service: vacuum.send_command
            target:
              device_id: 1234567
            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.roborock_vacuum_a10
                to: returning
              - platform: state
                entity_id: vacuum.roborock_vacuum_a10
                to: docked
            continue_on_timeout: false
            timeout: '01:30:00'
    default: []

Extend or change the room fieldā€™s selector.select.options as necessary. All valid room ids need to be listed here. Make sure to replace the device_id and entity_id with the ids of your vacuum.

Return to Dock Automation

alias: 'Vacuum: Paused for 5 minutes -> cancel cleaning and return to dock'
description: ''
trigger:
  - platform: state
    entity_id: vacuum.roborock_vacuum_a10
    to: paused
    for: '00:05:00'
  - platform: state
    entity_id: vacuum.roborock_vacuum_a10
    for: '00:05:00'
    to: idle
condition: []
action:
  - service: script.turn_off
    target:
      entity_id: script.roborock_room_cleaning
  - device_id: 1234567
    domain: vacuum
    entity_id: vacuum.roborock_vacuum_a10
    type: dock
  - service: script.turn_on
    target:
      entity_id: script.roborock_room_cleaning
mode: queued
max: 10

This automation will return the vacuum after 5 minutes when it is stopped with a button press, the app, etc. or if thereā€™s a rare case of non-successful docking. Make sure to replace the device_id and entity_id with the ids of your vacuum.

Error Notification Automation

alias: 'Vacuum: Notify on Error'
description: ''
trigger:
  - platform: state
    entity_id: vacuum.roborock_vacuum_a10
    to: error
condition: []
action:
  - device_id: 7654321a
    domain: mobile_app
    type: notify
    title: 'Vacuum: Error'
    message: Vacuum encountered an error.
mode: queued
max: 10

If the robot encounters an error youā€™ll get a notification. Just enter the device ID of the mobile app you like to have notified. Make sure to replace the entity_id with the id of your vacuum.

Room number definition

Create an input_number per room to act as enum, example for bathroom:

input_number.roborock_room_enum_bathroom

The ids are usually 15 and above - if you made any manual changes to the map. Just try the ids to identify the rooms.

Buttons

type: entity-button
tap_action:
  action: call-service
  service: script.roborock_room_cleaning
  service_data:
    room: bathroom
entity: script.roborock_room_cleaning
icon_height: 60px
icon: hass:robot-vacuum
name: Start

This button will call the script for the room bathroom. The button will light up as soon as you press it and stop being illuminated after the robot has cleaned all rooms in the (script) queue.

By clicking on two buttons youā€™ll send the robot to the first and then the second room. The queuing in the script will take care of this automatically and command the cleaning of the second room as soon as the robot reports back that it returns to the dock.

I recommend turning the volume of the voice output down to the minimum to avoid all the chatter of the robot while cleaning.

Have fun

21 Likes

This looks awesome and I have the same vacuum. How did you add your Roborock to HA?

1 Like

You need to use this.

1 Like

This is great, I am just not so clear on input number and how I go about integrating it. Sorry total noob! Can you step us through where and how in the input number is added?

Anybody? I literally have this all working to the stage where I just need to define the room value and Iā€™m not sure exactly how to do that.

Use the Xiaomi Miio integration. With the new 2021.7 version you just need to log in with your xioami account.

1 Like

Just so weā€™re clear I asking how to do this part:

## Room number definition

Create an input_number per room to act as enum, example for bathroom:

input_number.roborock_room_enum_bathroom

The ids are usually 15 and above - if you made any manual changes to the map. Just try the ids to identify the rooms.

I have found all the ids for each associated room, I am just not sure how to define each room and associated ID in YAML

Did you sacrifice the camera functionality when using this? Are you still able to use the Roborock app?

Hey Matt,

sorry for the delay.

Sure thing:

  • Open your HA instance
  • Select the Configuration on the left side
  • Select Helpers in the settings
  • Click on Add Helper on the bottom right
  • Select Number
  • Enter a name like ā€œroborock_room_enum_living_roomā€
  • Click on Create
  • Add this ā€œinput_number.roborock_room_enum_living_roomā€ to any Lovelace Dashboard you like and change the number from 0 to say 15

Now let the script start for living_room and see which room the robot starts to. If itā€™s not the living room, write down which room it is, and change the number to 16. Let the robot return to the dock and start the script with living_room again. Repeat this until you know which room got which number.

Now you can create the other enums variables for your rooms and change the numbers to the correct ones.

Remember that if you have a room which isnā€™t listed in the scripts options, you just need to add it there :slight_smile:

Feel free to report back if youā€™re now successful or need any further help.

1 Like

Yes and no, matt1131. Using the Xiaomi Home app to add the robot to your wifi will replace the Roborock app with a plugin in the Xiaomi app.

They are similar, so you can still enable the object detection (reactive AI), pet detection and the photos for objects.

But the live video feed functionality is not available with the Xiaomi App. I never used it, it was just a gimmick to me.

Additionally the Xiaomi App feels sluggish and slow, but you donā€™t need to use it anyway, since HA can do the most daily stuff and this runs completely locally - so itā€™s fast.

Additionally the map(s) and all details except the names of the rooms are saved on the robot, so they will retained when you switch the apps.

Hope this helps with this decision.

2 Likes

Hey Ruben, thanks for the info, itā€™s very helpful in making the decision. One more question: can you still do zones in HA?

Well, you can still use the Xiaomi Home app to modify the map, add/remove nogo-zones, change the rooms, or run the vacuum in an ad-hoc ā€œzoneā€ area.

The only limitation on map changes since the IDs might change for them.

Using the Xiaomi Home app while using HA doesnā€™t affect each otherā€™s functionality. My script just sends commands locally to the Robot vacuum to clean a specific room. Nothing more, nothing less.

When the robot reports back, that it completed the task, the script will terminate and if you have anything else ā€œplannedā€ in HA with a secondary script call, this script will just be sending its command to the robot.

Hope this answers your question.

1 Like

Perfect, thanks!

1 Like

Hi Ruben,

Firstly, thanks so much for your time and help stepping me through getting this working. So I have the scripts and automations running - running the script as a button in lovelace (running call service of the script), the Roborock starts up and after 5 secs returns to the dock. I just donā€™t seem to be able to get the input numbers to respond as buttons.

Iā€™ve now added them in ā€˜Helpersā€™, numbers as exactly the text specified and also matching the entries in the script, when it comes to adding them as buttons, I have tried adding as a button setting from the list of pre-made input numbers and setting the value (which I have tested separately in developed mode to workout which room corresponds to which number).

When I try to run the script as a button and select any of my input number buttons, nothing happens. What should my lovelace code be for the input numbers. Hereā€™s an example of my run script in lovelace:

type: entity-button
tap_action:
action: call-service
service: script.1626578970110
service_data:
room: bathroom
entity: script.1626578970110
icon: hass:robot-vacuum
name: Start

And here is an example room button:
type: button
tap_action:
action: call-service
service: input_number.set_value
service_data:
value: 22
target:
entity_id: input_number.roborock_room_enum_hallway
entity: input_number.roborock_room_enum_hallway
icon: mdi:door
name: Hallway

Thanks again!

This seems to be a Blueprint I need! Thanks for sharing :+1:

Butā€¦before I can implement this, I would first need to create zones, am I right?

I have my S5 in HA, camera and map is included. But I donā€™t know how to create zones for cleaning, for instance, my kitchen or hallway etc.

Anyone who can send me to the right direction?

Hi,

When I copy the main script code into a new script, I get the following error:

Message malformed: template value does not contain a dynamic template @ data['sequence'][0]['choose'][1]['sequence'][0]['target']['device_id'][0]

Obviously Iā€™m new to YAML :slight_smile:

@robw please read the instructions again:

Make sure to replace the device_id and entity_id with the ids of your vacuum.

Hey @Intro_Verti,

sorry for the delay - I somehow managed to delete the notification mail.

Anyway, no, you donā€™t need zones. You just use the segments. Segments are simply the rooms the robot creates after it runs once through your house. You modify the automatic detection just as you like after the first detection (which you probably already did) and the rooms stored in the robot can be addressed with the segment-ids.

Since itā€™s hard to remember that the Living Room is id 16 or the Bedroom is 17 I created those variables.

So thereā€™s basically nothing to do, just run the robot with id 15 and upwards and note which room is which id.

The documentation about the segments can be found here:

1 Like

Hey Matt,

Well, this usually happens if you select a room which had the door closed while the robot has run the last time.

In this case youā€™ll get an error message via Xiaomi Home that the room cannot be reached.

I think thatā€™s a bug and I reported this to Roborock a while ago.

Anyway, this is probably not the only issue you have - but I donā€™t really get why you need two buttons.

Does it work if you go to developer settings ā†’ services, then use Input number: Set to set the input_number.roborock_room_enum_hallway to say 15 and then run select the script and run it with ā€œhallwayā€ in the same mask?

@RubenKelevra - thanks for sharing this - Iā€™m in the process of setting it up and I love it already! One question: Iā€™ve identified all the rooms on the main floor of our house, but not sure how to go about finding the 2nd floor numbers? Iā€™ve taken the dock upstairs and tried continuing with the numbers, but they are all ā€˜areas that cannot be reachedā€™. Do I just keep trying or should I expect a different range of numbers for an additional floor? Thanks.

Edit: also, can you share what your lovelace looks like for this? Do you end up with a button for each room and ā€˜hardcodeā€™ the room numbers into each?