Roborock Integration with Q Revo Vacuum / Mop - Segment cleaning

Alright, we’re making some progress and I feel like we’re closer.

When I run on dev tools, I get the rooms back:

When I update the script above, nothing happens.

BUT when I use my automation, it works (see code below). Is there some kind of syntax or formatting error?

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

Apologies as I’m new to HA.

So it looks like params is a list so it needs

 - segments

I see, so will the code we use on the template not work for this?

Here is the script I have on run vacuum now:

alias: Run Vacuum
sequence:
  - service: vacuum.send_command
    data:
      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 %}
           {% set vacrooms.roomid = vacrooms.roomid + [room] %}
          {% endif %}
         {%- endfor %}
         {{ vacrooms.roomid }}
    target:
      entity_id: vacuum.roborock_q_revo
mode: single
icon: mdi:robot-vacuum

I’m guessing this returns a string of segments, and we need it in a list?

It is a list. If you paste the whole script into the developer tool template and look at result, does it look like the sample that works? Could be slightly off in indentation

Try this one, reduce the complexity.

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

In the dev tool it looks like this:

Be sure you are doing it just like this, the samples you send do not have data_template, they have data which is wrong if the data is coming from a template.

That looks exactly like your sample that works except it uses data_template.

1 Like

So when I put it in dev tools, my result looks like yours (in a list)

Now when I paste the same code in the script editor, the code isnt validating and wont let me save.


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?