There is a vacuum robot which has a service accepting room numbers for cleaning:
- service: vacuum.send_command
data:
entity_id: vacuum.xiaomi_roborock_s50
command: app_segment_clean
params: [1, 2, 3]
or
...
params:
- 1
- 2
- 3
Here is a code for a template sensor to generate that list:
{% set ns = namespace(COMMAND = "") -%}
{%- set ROOM_FLAGS = expand('group.vacuum_clean_rooms') -%}
{%- for flag in ROOM_FLAGS -%}
{%- if flag.entity_id | regex_match("input_boolean.vacuum_clean_room_", ignorecase=False) and
is_state(flag.entity_id,'on') -%}
{%- set ROOM = flag.entity_id.split("vacuum_clean_room_")[1] -%}
{%- set ROOM_NUMBER = states('input_number.vacuum_clean_room_number_' + ROOM)|int -%}
{%- set CLEAN_COUNT = states('input_number.vacuum_clean_room_count_' + ROOM)|int -%}
{%- set ROOM_NUMBER_STRING = (ROOM_NUMBER|string + ",") * CLEAN_COUNT -%}
{%- set ns.COMMAND = ns.COMMAND + ROOM_NUMBER_STRING -%}
{%- endif -%}
{%- endfor -%}
{%- set ns.COMMAND = (ns.COMMAND)[:-1] -%}
{{ ns.COMMAND }}
Output in Developer Tools → Template:
Here is my script:
script:
vacuum_clean_rooms:
alias: 'vacuum: Clean rooms'
sequence:
- service: vacuum.send_command
data:
entity_id: vacuum.xiaomi_roborock_s50
command: app_segment_clean
params: "{{ states('sensor.vacuum_clean_command') }}"
And I am getting this error:
Unable to send command to the vacuum: {'code': -10000, 'message': 'data for segment is not a number'}
I think that the "{{ states('sensor.vacuum_clean_command') }}"
expression produces not a list…