Help with zone cleaning parameters - Xiaomi vacuum

Hm, I tried with:

service: vacuum.send_command
data:
  entity_id: vacuum.pitbull
  command: zoned_cleanup
  params:
    zone_ids:
      - kitchen

and (like HA suggests with sample data)


service: vacuum.send_command
data:
  entity_id: vacuum.pitbull
  command: zoned_cleanup
  params:
    zone_ids: kitchen

Does not work. What is wrong?

Something is no yes :wink: I have followed all steps:

  1. python script created:
entity_id = data.get('entity_id')
command = data.get('command')
params = str(data.get('params'))
parsedParams = []

for z in params.replace(' ', '').replace('],[', '|').replace('[', '').replace(']', '').split('|'):
    rect = []
    for c in z.split(','):
        rect.append(int(c))
    parsedParams.append(rect)

if command in  ["app_segment_clean"]:
    parsedParams = parsedParams[0]

hass.services.call('vacuum', 'send_command',
                   {'entity_id': entity_id, 'command': command, 'params': parsedParams}, True)
  1. groups created:
room_input_booleans:
   entities:
      - input_boolean.kuchnia
      - input_boolean.salon
      - input_boolean.korytarz
      - input_boolean.pokoj_leny
      - input_boolean.lazienka
      - input_boolean.sypialnia  
  1. New attribute for input_boolean created:
editable: true
friendly_name: Korytarz
icon: 'mdi:wall'
room_number: 19
  1. Automation created:
- id: '1600287204887'
  alias: odkurzanie_selektywne
  description: ''
  trigger:
  - entity_id: input_boolean.slij_mariusza
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data_template:
       command: app_segment_clean
       entity_id: vacuum.xiaomi_vacuum_cleaner
       params: "{{ ''group.room_input_booleans'' | expand | selectattr(''state'', ''equalto'', ''on'') | map(attribute=''attributes.room_number'') | list }"
    service: python_script.vacuum_send_command
  - delay: 00:00:05
  - data: {}
    entity_id: input_boolean.slij_mariusza
    service: input_boolean.turn_off
  mode: single

And got an error when checking configuration:

  Invalid config for [automation]: invalid template (TemplateAssertionError: no filter named 'expand') for dictionary value @ data['action'][0]['data_template']['params']. Got None. (See /config/configuration.yaml, line 155). 

Any idea what went wrong?

I am not sue if quotes in params are correctā€¦
Try something like this:

  - data_template:
       command: app_segment_clean
       entity_id: vacuum.xiaomi_vacuum_cleaner
       params: "{{ 'group.room_input_booleans' | expand | selectattr('state', 'equalto', 'on') | map(attribute='attributes.room_number') | list }"

Problem solved!

I have pasted an error into google and it guided me to:

https://community.home-assistant.io/t/how-to-use-expand-function-in-sensor-template-to-sum-all-state-of-a-group/136791/5

Iā€™m not that good with coding but idea to use expand ('group.room_input_booleans') instead of 'group.room_input_booleans' | expand | is solving the issue. My automation is now working. Thanks for your effort @3_14( Piotr) :slight_smile: You are my HERO! :wink:

@EdwardEnglish where you able to solve this issue?
I am trying to corner the issue piece by piece. First I wanted to see if vacuum.send_command is working correctly. If I use Developer Tools to call a service.
vacuum.start for example works perfectly fine.
Shouldnā€™t I get the same result using

service vacuum.send_command
entity_id: vacuum.rockrobo
command: start

Happy for any input.

1 Like

Unfortunately notā€¦never found the time to give it more tries. But if anybody ever finds a solution please post it!

Have a look here, I solved it using the new 0.117 template as list feature and can send it directly to the vacuum without using any python script at all.

https://community.home-assistant.io/t/a-list-generated-by-a-template-is-it-possible-help/111239/35?u=hagenuck1

And also in 0.118 with Native types support for templates

Do you mind sharing the final code for this please?

I have tried using the python script method but get the following error:

 File "vacuum_send_command.py", line 9, in <module>
ValueError: invalid literal for int() with base 10: "'19'"

Seems like an issue with the room_number attribute, which I can confirm exists for the room I am trying to clean.

Ignore, got it to work by mapping to integers first.

here is the code, seems to work well now!

    - service: python_script.vacuum_send_command
      data_template:
        command: app_segment_clean
        entity_id: vacuum.robomac
        params: "{{ expand('group.vc_rooms') | selectattr('state', 'equalto', 'on') | map(attribute='attributes.room_number') | map('int') | list }}"

With the latest valetudo update it broke my vacuum.send_command stuff but I was able to get it working using MQTT publish like so.

service: mqtt.publish
data:
    topic: valetudo/robovacDown/MapSegmentationCapability/clean/set
    payload: '20'

One thing Iā€™ve not been able to figure out yet is how to provide a payload of multiple segments to be cleaned though. Say like payload: ['20', '21', '22'].

EDIT: Figured it out. 2021.06 - Home Assistant segment clean help Ā· Discussion #989 Ā· Hypfer/Valetudo Ā· GitHub