Howto: Xiaomi vacuum zoned cleaning

Isn’t it possible to pass the params from a template like a sensor?

start_zoned_cleanup:
alias: Start zoned cleanup
sequence:

  • data_template:
    entity_id: vacuum.bruno
    command: app_zoned_clean
    params: ‘{{ states(’‘sensor.vacuum_zoned_cleanup’‘) }}’
    service: vacuum.send_command

Regarding cleaning >5 zones in a single script, what if the wait commands check for state ‘returning’ instead of docked?

- wait_template: (is_state('vacuum.xiaomi_vacuum_cleaner', 'returning'))

According to the HA history, after a zone clean, the vacuum state changes to ‘returning’ before ‘docked’.

@zero545

Did you get this working? From what I remember, it did not respond to new zone clean commands until after docking.

I did not have the problem of waiting for the right state, but the vacuum robot did not react to any commands (not even stop) until it was back in the dock. I haven’t looked into this for a while. Did that behaviour change?

I was just speculating and wondering if someone had tried it. I tested it today and no joy.

This is consistent with its normal behaviour outside of HA, now that I think about it - it won’t take other commands unless paused, docked or stopped.

I’ll try a pause command + wait until state is returning, unless someone has tried that already?
@e1miran

You can’t use data_template with this service - data template passes a STRING not an array (it is up to the service software to parse that string properly, and the software doesn’t do that).

e.g. your params for the first condition evaluates to the STRING:
“[[25500,19750,29250,25500,1]]”
NOT the list of lists of integers data structure required:
[[25500,19750,29250,25500,1]]

see:

1 Like

Okay, no luck. Same as reported - it will commence the next zone after it has redocked.

Has anyone managed to get zone cleaning to work with IFTTT with # amounts of cleaning?
Like this guide for example https://hackernoon.com/how-i-set-up-room-cleaning-automation-with-google-home-home-assistant-and-xiaomi-vacuum-cleaner-9149e0267e6d

I have followed the guide and the google assistant responds with the correct phrase but it does not start the cleaning. The logbook says Error while executing automation automation.ifttt. Invalid data for call_service at pos 1: Service does not match format <domain>.<name>

that guide is based on old IFTTT method
i think you are using webhooks and IFTTT integration? then the commands are different

@ciB is “we cannot use lists (which the coordinates are) in templates.” that still the case ? I mean now that xiaomi_clean_zone has been added to HASS or that has nothing to do with it ? I am just trying to figure out how much is still the case so i can start making my zones.

Since the coords are still passed through the data field, this rule still applies - unless they have added that templates can actually render lists (as far as I know they still only return Strings).

Looking at the document i see they provide the coordinates on the data_template : https://www.home-assistant.io/components/vacuum.xiaomi_miio/ but i guess that still does not make a difference ?

Can you give an example of what you want to achieve?

I have tried your solution, i know it’s a long time but for me the vacuum cleaner goes back to the dock after first zone cleanup instead moving to the next zone, i thought it was because the state was never set to Returning home but it does but the wait_template does not react to it for some reason. The first wait_template where it checks for idle works fine since it continues.

test_clean:
  alias: "Vacuum kitchen"
  sequence:
  # Go to starting point
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_goto_target
        params: [24950,25500]
    #Wait untill done
    - wait_template: "{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.status == 'Idle'}}"
    #clean room
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_zoned_clean
        params: [[23961,27821,24461,28321,1]]
    #Wait untill done
    - wait_template: "{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.status == 'Returning home'}}"
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_zoned_clean
        params: [[24803,27020,25303,27520,1]]

Any ideas why it doesn’t work ?

While the vacuum is returning home it will not accept any New zoned clean ups. Try stopping it first, that might work. What you can do anyway is to add and pass all the zones in one list, the vacuum will then automatically do all the zones one after the other.

@ciB thank you, Yes i was thinking it might be because of that, i will try. The reason i wanted to do this was to see how far i can get automating / scripting a specific way the vacuum should do things also to help it with app_goto_target since i did see that in some cases it would give up on some zones but it would work i used app_goto_target to a point close to the zone then ask it to do clean up zone.

  • Out of curiosity do you know if the vacuum respects the order the zones are given or it does it random ?
  • Also do you know when given multiple zones does it then return back to the dock or does it continue to next zone ?

@ciB
I tried to send the vacuum.stop after the wait_template that checks for Returning home but it doesn’t care. It just goes back to the dock.

So i got it to work i thought using vacuum.pause for a moment but then when i tried again the script it failed to pause so it went back to the dock. I think it’s Xiaomi API that for most of the times it fails.

I have been using the multiple zoned cleaning for months via Node-RED without any problem. The key is the catching of the robot during paused state. e1miran also uses the Node-RED with other way on hihger level.
The working of my solution is the following: first I select the rooms after it start the zoned cleanup.
In this way the robot has a short break during paused state because of the HA discovery (0-10 s).

3 Likes

I am unsure exactly what it is but i have indeed tried with timeout to give it some time like this :

script
test_clean:
  alias: "Vacuum kitchen"
  sequence:
  # Go to starting point
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_goto_target
        params: [24950,25500]
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 1
    #Wait untill done
    - wait_template: "{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.status == 'Idle'}}"
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 2
    #clean room
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_zoned_clean
        params: [[22572,28094,23072,28594,1]]
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 3
    #Wait until done
    - wait_template: "{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.status == 'Returning home'}}"
      timeout: '00:00:30'
      continue_on_timeout: 'false'
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 4
    #Stop going home so we can tell it to clean next zone
    - service: vacuum.pause
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 5
    #Wait untill done
    - wait_template: "{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.status == 'Paused'}}"
      timeout: '00:00:30'
      continue_on_timeout: 'false'
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 6
    - service: vacuum.send_command
      data:
        entity_id: vacuum.xiaomi_vacuum_cleaner
        command: app_zoned_clean
        params: [[24803,27020,25303,27520,1]]
    - service: input_number.set_value
      data:
        entity_id: input_number.vaccum_progress
        value: 7

As far as i can see the robot does change it’s state in HASS since i am looking at the state during the script run but when HASS tells it to stop or pause it’s ignoring it so i don’t believe it to be a problem that the state is delayed.