Help with zone cleaning parameters - Xiaomi vacuum

Hi everyone,

I have created scripts that overcome some issues with xiaomi vacuum integration:

Hello everyone,

I made a graphical tool for quickly generating the coordinates if you have the PPM navmap. It will probably also work if you have a screencap of your map from the Mi Home app, but I haven’t tried that.

I didn’t want to use flole or valetudo and I figured there ought to be a simple way to generate them in a GUI.

xiaomi_navmap_example

check it out and let me know if it’s helpful to you.

Cheers,
neon

Hi,

Probalby not the correct post but 
 is there a way to receive the alerts from the vacuum ? 
 example 
 want to triger an automation GOTO my trash can when the dust bin message is trigerred by the vacuum.

If you use valetudo ther’s a error message as attributes:

I created a template_sensor like this:


      xiaomi_vacuum_error_description:
        entity_id: vacuum.rockrobo
        friendly_name: Error Description 
        value_template: "{{ state_attr( 'vacuum.rockrobo', 'last_run_stats').get('errorDescription') }}" 

1 Like

How to use this python script? Where do I put this to make it work?

Python script has to be put in python_scripts directory

Example usage:

Ok, sorry. Newbie here. Got the python script part, it’s done and I’m able to see it as a service in configuration. Now, how do I test the provided example usage? Am I supposed to paste this code to scripts.yaml or something like that? Thanks in advance.

Usage just shows can python script can be used in HA. You can use it as a part of a script or an automation.

I just need one functional example to understand it better, could you help me with that? One simple script or one simple automation, just to see things working. Thanks!

You should use it instead of direct calls to vacuum.send_command service. Its only benefit is that you can use templates as a parameters.

Sidequestion: Is it possible to use the service “vacuum.send_command” with one of the get commands (e.g. get_dnd_timer from Link) to use this within a sensor or use it in an automation to update an input_boolean?

Is anyone else having this issue - I have a card setup with pause and a start clean button.
service: vacuum.pause & service: vacuum.start

In zone cleaning - pause and then sending vacuum.start works to resume the cleaning where it left off

Now I am using Room/segmented Cleaning and although pause still works - vacuum.start starts a brand new clean house cycle - so current room clean is ignored ? Have tried double pause but it doesn’t work. Any suggestions.

Hi Piotr,

Usage of templates inside params for service vacuum.send_command is something i was looking for some time now. Your script seems to be an answer for my need. Point is, that it works only for zone cleaning while I’m using app_segment_clean where each specific room is defined as a number - see below. Would it be possible for you to adjust you script for such configuration? What I need as an input for params is a list of specific numbers. I would appreciate your support! Thanks!

image

Hi!

My script is already adjusted to support app_segment_clean, but links to GitHub are altered by this forum to point to a version that is latest at the time of posting, so you just have to go to the latest version of the file to find features you need :wink:

Hi,

Thanks for feedback! I have found it, but it seems to be too complicated for me as a newbie. I have no idea how my template should look like to generate proper input for params.
I was trying with below, but no success:

data_template:
  command: app_segment_clean
  entity_id: vacuum.xiaomi_vacuum_cleaner
  params: '    
  {% if is_state("input_boolean.kuchnia", "on")  -%} 20 {%- endif %}    
  {% if is_state("input_boolean.salon", "on")  -%} 16 {%- endif %}    
  {% if is_state("input_boolean.korytarz", "on")  -%} 19 {%- endif -%}    
  {% if is_state("input_boolean.pokoj_leny", "on")  -%} 17 {%- endif %}    
  {% if is_state("input_boolean.lazienka", "on")  -%} 21 {%- endif %}    
  {% if is_state("input_boolean.sypialnia", "on")  -%} 18 {%- endif %}'

Try something like this:

data_template:
  command: app_segment_clean
  entity_id: vacuum.xiaomi_vacuum_cleaner
  params: >
    {% if is_state("input_boolean.kuchnia", "on")  -%} 20 {%- endif %}    
    {% if is_state("input_boolean.salon", "on")  -%} 16 {%- endif %}    
    {% if is_state("input_boolean.korytarz", "on")  -%} 19 {%- endif -%}    
    {% if is_state("input_boolean.pokoj_leny", "on")  -%} 17 {%- endif %}    
    {% if is_state("input_boolean.lazienka", "on")  -%} 21 {%- endif %}    
    {% if is_state("input_boolean.sypialnia", "on")  -%} 18 {%- endif %}

Nope, still nothing. When pasting it into HA templates seems to be OK, but there is an empty line created when some of the rooms are omitted - see below. Could it be the issue? Is your python script designed to work with such formatted data as an input?

Ok, I have the ultimate solution (in my opinion):

  1. Add attribute room_number for all your input_booleans (documentation):
    homeassistant:
      customize:
        input_boolean.kuchnia:
          room_number: 20
        input_boolean.salon:
          room_number: 16
        input_boolean.korytarz:
          room_number: 19
        input_boolean.pokoj_leny:
          room_number: 17
        input_boolean.lazienka:
          room_number: 21
        input_boolean.sypialnia:
          room_number: 18
    
  2. Create a group with all input_numbers:
    group:
      room_input_booleans:
        entities:
          - input_boolean.kuchnia
          - input_boolean.salon
          - input_boolean.korytarz
          - input_boolean.pokoj_leny
          - input_boolean.lazienka
          - input_boolean.sypialnia
    
  3. Use the following code in your script/automation:
    - service: python_script.vacuum_send_command
      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 }}"
    

If you don’t like this approach, you can do everything directly in a script:

- service: python_script.vacuum_send_command
  data_template:
    command: app_segment_clean
    entity_id: vacuum.xiaomi_vacuum_cleaner
    params: >
      {%- set room_numbers = {
        'input_boolean.kuchnia': 20,
        'input_boolean.salon': 16,
        'input_boolean.korytarz': 19,
        'input_boolean.pokoj_leny': 17,
        'input_boolean.lazienka': 21,
        'input_boolean.sypialnia': 18,
      } -%}
      [{%- for room_name in room_numbers | expand | selectattr('state', 'equalto', 'on') | map(attribute='entity_id') | list -%}
      {{ room_numbers[room_name] }}
      {%- if not loop.last %},{% endif -%}
      {%- endfor -%}]
1 Like

Currently, whats the easiest way to start a Zoned Cleanup with Valetudo?

I have my zones configurd on my robot, in the past this would work:

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

I can trigger it without error but the vacuum does not move. Help please!

The entity_id has to be inside the data area.