Roborock Integration with Q Revo Vacuum / Mop - Segment cleaning

Hey @kbrown01 any ideas on the above?

When I use the script from the documentation, seems to run okay, but I can’t get it mapped back to the rooms selected on the dashboard.

Any help or suggestions of things to look into would be helpful.

Thanks

What happens if you check some rooms in the GUI and then go to developer’s tools and test this part?

            {% 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 }}

I assume you created all the input_booleans this would refer to (one for each room using the “boolean” name that is in the JSON).

You can also check that the script runs and use the trace option to further diagnose.

Yep, using the input_booleans with the same name.

When I check off some rooms on the dashboard and run the script on developer tools, i see this warning.

Logger: homeassistant.components.script.1708203800106
Source: helpers/script.py:1805
Integration: Script (documentation, issues)
First occurred: February 19, 2024 at 8:18:08 PM (8 occurrences)
Last logged: February 22, 2024 at 8:48:04 PM

Run Vacuum: Already running
Run Vacuum: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['segments']
Run Vacuum: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['data_template']

Please post that script again so we can see. It looks like you have - parameters and not just parameters I think it should be like this (as I said, untested as I do not have that model):

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

CHanges made for data_template (not data) and removing the “-” in segments

Thanks!

I just tried the script you shared, and still no dice. Here is a snippet from the logs:

2024-02-27 15:27:58.803 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=32422 Response from method get_dnd_timer: {'start_hour': 22, 'start_minute': 0, 'end_hour': 8, 'end_minute': 0, 'enabled': 1, 'actions': {'resume': 1, 'vol': 1, 'led': 1, 'dust': 1, 'dry': 0}}
2024-02-27 15:28:02.509 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=23748 Requesting method get_child_lock_status with []
2024-02-27 15:28:02.515 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=23748 Response from method get_child_lock_status: {'lock_status': 0}
2024-02-27 15:28:08.007 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=10675 Requesting method get_valley_electricity_timer with []
2024-02-27 15:28:08.020 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=10675 Response from method get_valley_electricity_timer: {'start_hour': 0, 'start_minute': 0, 'end_hour': 0, 'end_minute': 0, 'enabled': 0}
2024-02-27 15:28:09.069 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=30619 Requesting method get_sound_volume with []
2024-02-27 15:28:09.075 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=30619 Response from method get_sound_volume: 100
2024-02-27 15:28:28.160 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=18708 Requesting method get_clean_summary with []
2024-02-27 15:28:28.173 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=18708 Response from method get_clean_summary: {'clean_time': 37181, 'clean_area': 518505000, 'clean_count': 28, 'dust_collection_count': 15, 'records': [1708869662, 1708808347, 1708808339, 1708808330, 1708805951, 1708652907, 1708652213, 1708622653, 1708391502, 1708389659, 1708366009, 1708276810, 1708201745, 1708126425, 1708123726, 1708122747, 1707839568, 1707702062, 1707619484, 1707605673]}
2024-02-27 15:28:28.173 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=11180 Requesting method get_clean_record with [1708869662]
2024-02-27 15:28:28.245 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=11180 Response from method get_clean_record: {'begin': 1708869662, 'end': 1708873356, 'duration': 3084, 'area': 39600000, 'error': 0, 'complete': 1, 'start_type': 2, 'clean_type': 3, 'finish_reason': 56, 'dust_collection_status': 1, 'avoid_count': 18, 'wash_count': 4, 'map_flag': 0}
2024-02-27 15:28:28.245 DEBUG (MainThread) [homeassistant.components.roborock.coordinator] Finished fetching roborock data in 0.086 seconds (success: True)
2024-02-27 15:28:29.374 DEBUG (Thread-3 (_thread_main)) [roborock.cloud_api] [Roborock Q Revo] Sending PINGREQ
2024-02-27 15:28:29.397 DEBUG (Thread-3 (_thread_main)) [roborock.cloud_api] [Roborock Q Revo] Received PINGRESP
2024-02-27 15:28:42.087 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=20389 Requesting method get_status with []
2024-02-27 15:28:42.098 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=20389 Response from method get_status: {'msg_ver': 2, 'msg_seq': 782, 'state': 8, 'battery': 100, 'clean_time': 3084, 'clean_area': 39600000, 'error_code': 0, 'map_present': 1, 'in_cleaning': 0, 'in_returning': 0, 'in_fresh_state': 1, 'lab_status': 1, 'water_box_status': 1, 'back_type': -1, 'wash_phase': 0, 'wash_ready': 1, 'wash_status': 0, 'fan_power': 102, 'dnd_enabled': 0, 'map_status': 3, 'is_locating': 0, 'lock_status': 0, 'water_box_mode': 202, 'distance_off': 0, 'water_box_carriage_status': 1, 'mop_forbidden_enable': 1, 'camera_status': 1, 'is_exploring': 0, 'adbumper_status': [0, 0, 0], 'water_shortage_status': 0, 'dock_type': 8, 'dust_collection_status': 0, 'auto_dust_collection': 1, 'avoid_count': 18, 'mop_mode': 300, 'debug_mode': 0, 'in_warmup': 0, 'collision_avoid_status': 1, 'switch_map_mode': 0, 'dock_error_status': 0, 'charge_status': 1, 'unsave_map_reason': 0, 'unsave_map_flag': 0, 'dry_status': 0, 'rdt': 0, 'clean_percent': 0, 'rss': 2, 'dss': 681, 'common_status': 0, 'last_clean_t': 1708873353, 'corner_clean_mode': 0, 'kct': 0}
2024-02-27 15:28:42.454 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=13689 Requesting method get_consumable with []
2024-02-27 15:28:42.460 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=13689 Response from method get_consumable: {'main_brush_work_time': 10062, 'side_brush_work_time': 37181, 'filter_work_time': 10062, 'filter_element_work_time': 0, 'sensor_dirty_time': 37181, 'strainer_work_times': 38, 'dust_collection_work_times': 15}
2024-02-27 15:28:42.587 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=25793 Requesting method get_dust_collection_mode with []
2024-02-27 15:28:42.594 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=25793 Response from method get_dust_collection_mode: {'mode': 0}
2024-02-27 15:28:48.450 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=15154 Requesting method get_wash_towel_mode with []
2024-02-27 15:28:48.458 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=15154 Response from method get_wash_towel_mode: {'wash_mode': 1}
2024-02-27 15:28:54.020 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=32029 Requesting method get_smart_wash_params with []
2024-02-27 15:28:54.028 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=32029 Response from method get_smart_wash_params: {'smart_wash': 0, 'wash_interval': 900}
2024-02-27 15:28:58.160 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=22347 Requesting method get_clean_summary with []
2024-02-27 15:28:58.219 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=22347 Response from method get_clean_summary: {'clean_time': 37181, 'clean_area': 518505000, 'clean_count': 28, 'dust_collection_count': 15, 'records': [1708869662, 1708808347, 1708808339, 1708808330, 1708805951, 1708652907, 1708652213, 1708622653, 1708391502, 1708389659, 1708366009, 1708276810, 1708201745, 1708126425, 1708123726, 1708122747, 1707839568, 1707702062, 1707619484, 1707605673]}
2024-02-27 15:28:58.219 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=20556 Requesting method get_clean_record with [1708869662]
2024-02-27 15:28:58.265 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=20556 Response from method get_clean_record: {'begin': 1708869662, 'end': 1708873356, 'duration': 3084, 'area': 39600000, 'error': 0, 'complete': 1, 'start_type': 2, 'clean_type': 3, 'finish_reason': 56, 'dust_collection_status': 1, 'avoid_count': 18, 'wash_count': 4, 'map_flag': 0}
2024-02-27 15:28:58.266 DEBUG (MainThread) [homeassistant.components.roborock.coordinator] Finished fetching roborock data in 0.107 seconds (success: True)
2024-02-27 15:28:58.805 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=23278 Requesting method get_dnd_timer with []
2024-02-27 15:28:58.810 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=23278 Response from method get_dnd_timer: {'start_hour': 22, 'start_minute': 0, 'end_hour': 8, 'end_minute': 0, 'enabled': 1, 'actions': {'resume': 1, 'vol': 1, 'led': 1, 'dust': 1, 'dry': 0}}
2024-02-27 15:29:02.516 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=17445 Requesting method get_child_lock_status with []
2024-02-27 15:29:02.522 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=17445 Response from method get_child_lock_status: {'lock_status': 0}
2024-02-27 15:29:08.021 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=17282 Requesting method get_valley_electricity_timer with []
2024-02-27 15:29:08.027 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=17282 Response from method get_valley_electricity_timer: {'start_hour': 0, 'start_minute': 0, 'end_hour': 0, 'end_minute': 0, 'enabled': 0}
2024-02-27 15:29:09.076 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=20650 Requesting method get_sound_volume with []
2024-02-27 15:29:09.082 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=20650 Response from method get_sound_volume: 100
2024-02-27 15:29:28.160 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=29504 Requesting method get_clean_summary with []
2024-02-27 15:29:28.168 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=29504 Response from method get_clean_summary: {'clean_time': 37181, 'clean_area': 518505000, 'clean_count': 28, 'dust_collection_count': 15, 'records': [1708869662, 1708808347, 1708808339, 1708808330, 1708805951, 1708652907, 1708652213, 1708622653, 1708391502, 1708389659, 1708366009, 1708276810, 1708201745, 1708126425, 1708123726, 1708122747, 1707839568, 1707702062, 1707619484, 1707605673]}
2024-02-27 15:29:28.168 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=14965 Requesting method get_clean_record with [1708869662]
2024-02-27 15:29:28.227 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=14965 Response from method get_clean_record: {'begin': 1708869662, 'end': 1708873356, 'duration': 3084, 'area': 39600000, 'error': 0, 'complete': 1, 'start_type': 2, 'clean_type': 3, 'finish_reason': 56, 'dust_collection_status': 1, 'avoid_count': 18, 'wash_count': 4, 'map_flag': 0}
2024-02-27 15:29:28.227 DEBUG (MainThread) [homeassistant.components.roborock.coordinator] Finished fetching roborock data in 0.068 seconds (success: True)
2024-02-27 15:29:29.467 DEBUG (Thread-3 (_thread_main)) [roborock.cloud_api] [Roborock Q Revo] Sending PINGREQ
2024-02-27 15:29:29.490 DEBUG (Thread-3 (_thread_main)) [roborock.cloud_api] [Roborock Q Revo] Received PINGRESP
2024-02-27 15:29:42.099 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=30853 Requesting method get_status with []
2024-02-27 15:29:42.109 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=30853 Response from method get_status: {'msg_ver': 2, 'msg_seq': 783, 'state': 8, 'battery': 100, 'clean_time': 3084, 'clean_area': 39600000, 'error_code': 0, 'map_present': 1, 'in_cleaning': 0, 'in_returning': 0, 'in_fresh_state': 1, 'lab_status': 1, 'water_box_status': 1, 'back_type': -1, 'wash_phase': 0, 'wash_ready': 1, 'wash_status': 0, 'fan_power': 102, 'dnd_enabled': 0, 'map_status': 3, 'is_locating': 0, 'lock_status': 0, 'water_box_mode': 202, 'distance_off': 0, 'water_box_carriage_status': 1, 'mop_forbidden_enable': 1, 'camera_status': 1, 'is_exploring': 0, 'adbumper_status': [0, 0, 0], 'water_shortage_status': 0, 'dock_type': 8, 'dust_collection_status': 0, 'auto_dust_collection': 1, 'avoid_count': 18, 'mop_mode': 300, 'debug_mode': 0, 'in_warmup': 0, 'collision_avoid_status': 1, 'switch_map_mode': 0, 'dock_error_status': 0, 'charge_status': 1, 'unsave_map_reason': 0, 'unsave_map_flag': 0, 'dry_status': 0, 'rdt': 0, 'clean_percent': 0, 'rss': 2, 'dss': 681, 'common_status': 0, 'last_clean_t': 1708873353, 'corner_clean_mode': 0, 'kct': 0}
2024-02-27 15:29:42.461 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=26831 Requesting method get_consumable with []
2024-02-27 15:29:42.468 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=26831 Response from method get_consumable: {'main_brush_work_time': 10062, 'side_brush_work_time': 37181, 'filter_work_time': 10062, 'filter_element_work_time': 0, 'sensor_dirty_time': 37181, 'strainer_work_times': 38, 'dust_collection_work_times': 15}
2024-02-27 15:29:42.595 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=25077 Requesting method get_dust_collection_mode with []
2024-02-27 15:29:42.601 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=25077 Response from method get_dust_collection_mode: {'mode': 0}
2024-02-27 15:29:48.009 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=800793 Requesting method app_segment_clean with {'segments': ['17']}
2024-02-27 15:29:48.022 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=800793 Response from method app_segment_clean: None
2024-02-27 15:29:48.023 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=19711 Requesting method get_clean_summary with []
2024-02-27 15:29:48.082 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=19711 Response from method get_clean_summary: {'clean_time': 37181, 'clean_area': 518505000, 'clean_count': 28, 'dust_collection_count': 15, 'records': [1708869662, 1708808347, 1708808339, 1708808330, 1708805951, 1708652907, 1708652213, 1708622653, 1708391502, 1708389659, 1708366009, 1708276810, 1708201745, 1708126425, 1708123726, 1708122747, 1707839568, 1707702062, 1707619484, 1707605673]}
2024-02-27 15:29:48.083 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=10555 Requesting method get_clean_record with [1708869662]
2024-02-27 15:29:48.145 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=10555 Response from method get_clean_record: {'begin': 1708869662, 'end': 1708873356, 'duration': 3084, 'area': 39600000, 'error': 0, 'complete': 1, 'start_type': 2, 'clean_type': 3, 'finish_reason': 56, 'dust_collection_status': 1, 'avoid_count': 18, 'wash_count': 4, 'map_flag': 0}
2024-02-27 15:29:48.145 DEBUG (MainThread) [homeassistant.components.roborock.coordinator] Finished fetching roborock data in 0.122 seconds (success: True)
2024-02-27 15:29:48.460 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=32305 Requesting method get_wash_towel_mode with []
2024-02-27 15:29:48.469 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=32305 Response from method get_wash_towel_mode: {'wash_mode': 1}
2024-02-27 15:29:48.633 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=800793 Requesting method app_segment_clean with {'segments': ['17']}
2024-02-27 15:29:48.636 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=800793 Response from method app_segment_clean: None
2024-02-27 15:29:48.637 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=24866 Requesting method get_clean_summary with []
2024-02-27 15:29:48.687 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=24866 Response from method get_clean_summary: {'clean_time': 37181, 'clean_area': 518505000, 'clean_count': 28, 'dust_collection_count': 15, 'records': [1708869662, 1708808347, 1708808339, 1708808330, 1708805951, 1708652907, 1708652213, 1708622653, 1708391502, 1708389659, 1708366009, 1708276810, 1708201745, 1708126425, 1708123726, 1708122747, 1707839568, 1707702062, 1707619484, 1707605673]}
2024-02-27 15:29:48.687 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=10769 Requesting method get_clean_record with [1708869662]
2024-02-27 15:29:48.743 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=10769 Response from method get_clean_record: {'begin': 1708869662, 'end': 1708873356, 'duration': 3084, 'area': 39600000, 'error': 0, 'complete': 1, 'start_type': 2, 'clean_type': 3, 'finish_reason': 56, 'dust_collection_status': 1, 'avoid_count': 18, 'wash_count': 4, 'map_flag': 0}
2024-02-27 15:29:48.743 DEBUG (MainThread) [homeassistant.components.roborock.coordinator] Finished fetching roborock data in 0.107 seconds (success: True)
2024-02-27 15:29:54.030 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=15261 Requesting method get_smart_wash_params with []
2024-02-27 15:29:54.037 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=15261 Response from method get_smart_wash_params: {'smart_wash': 0, 'wash_interval': 900}
2024-02-27 15:29:58.812 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=19847 Requesting method get_dnd_timer with []
2024-02-27 15:29:58.822 DEBUG (MainThread) [roborock.local_api] [Roborock Q Revo] id=19847 Response from method get_dnd_timer: {'start_hour': 22, 'start_minute': 0, 'end_hour': 8, 'end_minute': 0, 'enabled': 1, 'actions': {'resume': 1, 'vol': 1, 'led': 1, 'dust': 1, 'dry': 0}}

Hoping this helps try to find out where the issue lies.

So the errors are gone.
With the fix, did you re-run the template in developer’s tools?
(Please note, don;t paste in the whole script … just paste in the code in “segments”)
As in:

If yes and you get the list of id’s then …
What happens if you just can the script to like two id’s?

alias: Run Vacuum
sequence:
- service: vacuum.send_command
  data_template:
    command: app_segment_clean
    params:
      segments: |
        - 16
        - 17
  target:
    entity_id: vacuum.roborock_q_revo
mode: single
icon: mdi:robot-vacuum

If that does not work then the whole command does not work

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