Roborock Integration with Q Revo Vacuum / Mop - Segment cleaning

Indentation and a missing “|” … this allows me to save:

alias: Run Vacuum
sequence:
  - service: vacuum.send_command
    data_template:
      command: app_segment_clean
      params:
        - segments: |
           {%- for rooms in state_attr('sensor.roborock_rooms','rooms') -%}
           {% if is_state(rooms.boolean,'on') %}
            - {{ rooms.id }}
           {%- endif %}
           {%- endfor %}
    target:
      entity_id: vacuum.roborock_q_revo
mode: single
icon: mdi:robot-vacuum

I posted that originally against your old code with data, I just changed to data_template. Be sure you use what I just updated.

I would note that I hate using a loop like this outputting the way it does but others have showed it works in their examples. I much more like it like my original which does output a list. I just think something was missing in that I did not notice (indenting, data v data_template, etc.). This in reality outputs a series of strings and I never understood that.

1 Like

I would note that I tested using send_command with my roborock_s7 and it does not work. What integration are you using?

1 Like

This allows me to save now, but when I run the script, nothing happens.

I’m using the official HA Roborock integration here: Roborock - Home Assistant

I use send command in my automation and it works (shared above).

An automation or a script?

I use send_command in my automation and it works (see snippet of automation below)

service: vacuum.send_command
data:
  command: app_segment_clean
  params:
    - segments:
        - 16
        - 17
        - 18
        - 19
        - 20
        - 21
      repeat: 2
target:
  entity_id: vacuum.roborock_q_revo

But the script does not work with send_command (see below)

alias: Run Vacuum
sequence:
  - service: vacuum.send_command
    data_template:
      command: app_segment_clean
      params:
        - segments: |
            {%- for rooms in state_attr('sensor.roborock_rooms','rooms') -%}
            {% if is_state(rooms.boolean,'on') %}
             - {{ rooms.id }}
            {%- endif %}
            {%- endfor %}
    target:
      entity_id: vacuum.roborock_q_revo
mode: single
icon: mdi:robot-vacuum

OK, after some time and tests and poking through the code, I see the issue and the solution. The template I wrote that iterates through the room_id’s would build a list like this:

- '16'
- '17'

While the integration I use can handle “strings” as room_ids, the standard Roborock integration cannot. It requires this:

- 16
- 17

The solution is simple and this is tested on my S7 and functions using the send_command. You will note the only difference is adding the | int filter when setting the value of the variable room as in:

{% set room = rooms.id | int %}

My complete, functional script for my vacuum is:

alias: Run Vacuum Test
sequence:
  - service: vacuum.send_command
    data_template:
      command: app_segment_clean
      params:
        - segments: |
            {% set vacrooms = namespace(roomid=[]) %}
            {% for rooms in state_attr('sensor.roborock_rooms','rooms') -%}
              {% if is_state(rooms.boolean,'on') %}
                {% set room = rooms.id | int %}
                {% set vacrooms.roomid = vacrooms.roomid + [room] %}
              {% endif %}
            {%- endfor %}
            {{ vacrooms.roomid }}
    target:
      entity_id: vacuum.roborock_s7
mode: single
icon: mdi:robot-vacuum

Just change to your entity for your Revo and it should work.

Just a note, how I diagnosed is that I duplicated my working script and changed it to use vacuum.send_command. I ran that script and just like you nothing happened. I went and ran my script and the vacuum ran as intended. I then compared the two traces for what was being sent and they were the same. After some poking into the raw code I could see that my integration did internal conversion to int which the other assumed an int. I added the int filter and voila, the vacuum happily ran.

I note that the example shown here shows that they are int values:

1 Like

Yep - this exact script did the trick for my Roborock Revo Q :slight_smile:

Amazing. Hopefully this helps someone else in the future when integrating your UI dashboard on HA for Roborock :slight_smile:

Thanks again!

1 Like

May I ask how “vacuum only” and “mop only” automations should look like?
Which of the parameters need to be set for “vacuum, but not mopping” mode?

alias: Run Vacuum-only 
sequence:
  - service: vacuum.send_command
    data_template:
      command: set_mop_mode????
      params: 300???? 
    target:
      entity_id: vacuum.roborock_s8_pro_ultra

  - service: vacuum.send_command
    data_template:
      command: app_segment_clean
      params:
        - segments:
            - 16
            - 17
          repeat: 2
    target:
      entity_id: vacuum.roborock_s8_pro_ultra
mode: single
icon: mdi:robot-vacuum

So I just realized I may not have posted back here but I did solve the problem. It just wasn’t intuitive, and someone pointed me in the right direction. See example below. The key piece was setting the mob intensity to off “select.roborock_q_revo_bed_mop_intensity”

alias: Action - Spot Clean Litter after Raking
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.primary_rake_status
    to: raking
condition:
  - condition: device
    device_id: 976d6012174bdfadc3b28a966561f617
    domain: vacuum
    entity_id: a378de65d7ee5456288691d97997c6f8
    type: is_docked
  - condition: time
    after: "09:00:00"
    before: "22:30:00"
action:
  - service: select.select_option
    data:
      option: "off"
    target:
      entity_id: select.roborock_q_revo_bed_mop_intensity
  - service: vacuum.send_command
    data:
      command: app_segment_clean
      params:
        - segments:
            - 17
          repeat: 1
    target:
      entity_id: vacuum.roborock_q_revo_bed
    enabled: true
mode: single

How can I find the correct room id’s with the Q Revo? What is described in Xiaomi Miio - Home Assistant doesn’t work eith the Roborock app.

Check out the " HOW CAN I CLEAN A SPECIFIC ROOM" section of the this link: https://www.home-assistant.io/integrations/roborock/

Hi,
Could you please elaborate on how the camera was created and how you tset this up exactly? I have the qrevo but am struggling enormously with the xiaomi-lovelace-card

For me it worked out of the box.

If you view the Q Revo on the HA UI > Integrations section you should see the entity. Something like roborock_q_revo_floor_name.

Have you setup the map on the Roborock app?

1 Like

I’ve also been wondering how people are getting the room IDs. I have the Q Revo, and when I go to services, roborock.get_maps is not an available action type… Map loads nicely on my main screen, but no details about specific room IDs.

I am getting all the room ID’s. However I am not able to start cleaning with the Call Service.

This is the code I’ve used, both in a script an in an automation. Neither will start the cleaning.

service: vacuum.send_command
data:
  command: app_segment_clean
  params:
    segments:
      - 16
      - 21
    repeat: 1
target:
  entity_id: vacuum.r2_q2

From developer tools I get this:

vacuum.r2_q2:
  maps:
    - flag: 0
      name: ""
      rooms:
        "16": Living room
        "17": Kitchen
        "18": Corridor1
        "19": Dining room
        "20": Corridor
        "21": Hall
    - flag: 1
      name: ""
      rooms:
        "16": Bedroom
        "17": Corridor
        "18": Bathroom
        "19": Sauna
        "20": Master bedroom
        "21": Shower
    - flag: 2
      name: ""
      rooms: {}

I have multiple level house so multiple maps.

I don’t understand why it’s not working. I have the Roborock integration installed.

Did you try loading the floor level first?

service: vacuum.send_command
target:
  entity_id: vacuum.r2_q2
data:
  command: load_multi_map
  params: 0

Neither load_multi_map or recover_map did anything. But somehow I managed to start cleaning with this:

service: vacuum.send_command
data:
  entity_id: vacuum.r2_q2
  command: app_segment_clean
  params: [17] 

I still have to figure out how to incorporate multiple rooms and repeats.

But thank you for the reply :slight_smile:

Seperate rooms by comma. Try this

service: vacuum.send_command
target:
  entity_id: vacuum.r2_q2
data:
  command: app_segment_clean
  params:
    - segments: [16,21]
      repeat: 1

Hi Peter, would you like to share all the project for the Qrevo?
I try to follow the thread, but i’m such a noob.
Thx Leo.