[Howto] Buttons for Room Cleaning (with Queuing) for [Xiaomi Miio] (Robot Vacuum)

many thanks for the guide, I successfully added the script and input.numbers to determine the rooms. works like a charm :wink: I also created input.booleans to toggle a switch and clean the desired room, this is how the dashboard looks like:

UPDATE: found the solution: Xiaomi vacuum restore/select backup map (multi floor support) . works like a charm!

I live in a multi-story house, the floors look as following:

main-floor

second-floor

the issue
I have to open the Mi-home app and select on which floor the vacuum is in order that he can clean the rooms accordingly. shouldnt it auto-detect where he is when I send the command to lets say clean Raum1 / Bad in the dashboard on the second-floor? of course the vacuum is then already in the second-floor.

1 Like

Hi there,

i got a Problem and cannot solve it by myself.

I copy/pasted the scripts from the first Postings, i changed my entity_id and device_id and i was able to retrieve all the room numbers by testing it out by the given way in this first posting.

btw: i’m using a Roborock S5.

now i changed the list of rooms to my need, so the main script looks like this:

mode: queued
alias: Roborock Room Cleaning
max: 30
fields:
  room:
    name: Room
    required: true
    example: wohnzimmer
    selector:
      select:
        options:
          - bad
          - badezimmer
          - bastelzimmer
          - esszimmer
          - flur
          - herrenzimmer
          - kueche
          - schlafzimmer
          - wohnzimmer
sequence:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: vacuum.r2d2
                state: cleaning
              - condition: state
                entity_id: vacuum.r2d2
                state: error
        sequence:
          - wait_for_trigger:
              - platform: state
                entity_id: vacuum.r2d2
                to: returning
              - platform: state
                entity_id: vacuum.r2d2
                to: docked
            continue_on_timeout: false
            timeout: "01:30:00"
          - service: vacuum.send_command
            target:
              device_id: 123youdontneedtosee
            data_template:
              command: app_segment_clean
              params: >
                {% set room_id = states("input_number.roborock_room_enum_" +
                room) | int %} {{ room_id }}
          - wait_for_trigger:
              - platform: state
                entity_id: vacuum.r2d2
                to: returning
              - platform: state
                entity_id: vacuum.r2d2
                to: docked
            continue_on_timeout: false
            timeout: "01:30:00"
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: vacuum.r2d2
                state: returning
              - condition: state
                entity_id: vacuum.r2d2
                state: docked
              - condition: state
                entity_id: vacuum.r2d2
                state: idle
        sequence:
          - service: vacuum.send_command
            target:
              device_id: 123youdontneedtosee
            data_template:
              command: app_segment_clean
              params: >
                {% set room_id = states("input_number.roborock_room_enum_" +
                room) | int %} {{ room_id }}
          - wait_for_trigger:
              - platform: state
                entity_id: vacuum.r2d2
                to: returning
              - platform: state
                entity_id: vacuum.r2d2
                to: docked
            continue_on_timeout: false
            timeout: "01:30:00"
    default: []

i made the helpers with th roomid’s for each room, by example wohnzimmer

      {
        "id": "roborock_room_enum_wohnzimmer",
        "min": 1.0,
        "max": 22.0,
        "name": "roborock_room_enum_wohnzimmer",
        "icon": "mdi:sofa",
        "mode": "box",
        "step": 1.0
      },

and now i implemented the button into my lovelace:

show_name: true
show_icon: true
type: entity-button
tap_action:
  action: call-service
  service: script.roborock_room_cleaning
  service_data:
    room: wohnzimmer
entity: script.roborock_room_cleaning
icon_height: 60px
icon: hass:robot-vacuum
name: Wohnzimmer saugen

But when i now click the Button it says:

Fehler beim Aufrufen des Diensts script/roborock_room_cleaning. Service not found.

I don’t know what i’ve done to make it fail, maybe someone her can help me?

Thanks and best regards
Bjoern

This is what i found in the Log:

2023-01-07 00:07:52.834 ERROR (MainThread) [frontend.js.latest.202301040] https://hass.nomster.de/frontend_latest/app.c7254a29.js:850:114174 Error: Failed to execute 'define' on 'CustomElementRegistry': the name "xiaomi-vacuum-map-card-editor" has already been used with this registry

Unfortunately i don‘t know what to do with this Info :smirk:

Anybody, please?

I have this error also, looking for a fix?

I fixed it by myself.
i deleted the script, made a restart of home assistant, created the script new and after an addditional restart it is now working.

found this in the forum to gave me the idea: How to create custom service and call from button - #12 by sheminasalam

I have the same error

Hey there, would you mind explaining (to a newbie) how you created these switches? What I’m essentially trying to achieve is to have a switch for each room which I can then use in Homekit.

sure. first you have to create input-booleans (its like a virtual switch), here is how to do it: Input Boolean - Home Assistant you have to create the boolean as a switch.

this switch is used to trigger the room-cleaning itself. You can expose the input.booleans to Homekit via the Homekit-integration: HomeKit - Home Assistant

then please follow the instructions from the thread-creator. it is important to follow it precisely in order to make it work.

my script looks as following. you have to replace the vacuum-entity and device-id with yours, as well as the room-names.

mode: queued
alias: Roborock Room Cleaning
max: 30
fields:
  room:
    name: Room
    required: true
    example: wohnzimmer
    selector:
      select:
        options:
          - wohnzimmer
          - kitchen
          - 1ogbad
          - 1ogofficeandreas
          - 1ogroomandreas
          - 1oggang
          - 1ogofficemarco
          - 2ogroommarco
          - ugeingang
sequence:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                state: cleaning
                entity_id: vacuum.roborock_s7
              - condition: state
                state: error
                entity_id: vacuum.roborock_s7
        sequence:
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: idle
            continue_on_timeout: false
            timeout: "01:30:00"
          - service: vacuum.send_command
            target:
              device_id: XXX
            data_template:
              command: app_segment_clean
              params: >
                {% set room_id = states("input_number.roborock_room_enum_" +
                room) | int %} {{ room_id }}
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: idle
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: docked
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: returning
                enabled: false
            continue_on_timeout: false
            timeout: "01:30:00"
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: vacuum.roborock_s7
                state: idle
              - condition: state
                entity_id: vacuum.roborock_s7
                state: docked
              - condition: state
                entity_id: vacuum.roborock_s7
                state: returning
        sequence:
          - service: vacuum.send_command
            target:
              device_id: XXX
            data_template:
              command: app_segment_clean
              params: >
                {% set room_id = states("input_number.roborock_room_enum_" +
                room) | int %} {{ room_id }}
          - wait_for_trigger:
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: idle
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: docked
                enabled: true
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                to: returning
                enabled: true
            continue_on_timeout: false
            timeout: "01:30:00"
    default: []

Danke Andrew! (: I guess I was being to vague in above, apologies. So, I have this whole “Blueprint” here working, I can trigger the room cleaning via the dashboard and my vaccum does what it’s supposed to.

THIS is the part I am after, what did you do to make this switch trigger a room cleaning?
I have created a switch via the UI (as per your screenshot), but how do I “link” this switch to the room cleaning of a specific room? I looked through your script but was unable to find anything that “links” to a boolean switch.

got you, actually thats quite simple, I use Node-Red for that.

When the input.boolean is on, the corresponding map (I live in a 2-story house) gets loaded, then it waits 10 secs and runs the cleaning-script with the data: {“room”:“wohnzimmer”}

Now you can build an input.boolean for each room and adjust the data in the call-service window.

runs perfectly within Homekit :wink:

1 Like

Hi all,

Is the clean rooms with the names possible with a roborock S4 ?
I saw the tutorial with the S6.

Thank you.
Lyes

Hi,

using this code, I receive “Error rendering data template: UndefinedError: ‘room’ is undefined” - I know this is due to my non existing competence to trace down my error.

I am anyways more than thankful for a little lift here.

Cheers,
K

I will try to use this script with Dreamebot L10 pro…
After some changes (device id, entity id…) for use with My vacuum cleaner I got error:
Unable to discover device over cloud

When i push button to clean some room all buttons chenge state to on and icons become yellow.
Is it possible to fix this that only pushed buttons go to state on and change icon color?

i have a edream vacuum, sub brand of Xiaomi i have it working with the edream card.
but when i install the HACS Xiaomi Miio i get a model unknown…
it there a way to still get costum keys

Just wondering if (once we have all the room IDs) this would be a shorter way for a button to clean a specific room:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: vacuum.send_command
  target:
    device_id: 123456
  data:
    command: app_segment_clean
    params: 20
entity: script.robot_vacuum_room_cleaning
icon: mdi:pot-steam
name: kitchen

You lose the ability to queue the rooms with this.

Hi All,

Like previously described by @1kohm @mattbedit I too experience that calling the service directly from Developer Tools or as an Automation, results in the vacuum starting only to declare itself done after a few seconds, and return to dock.

Any ideas on how to solve this?

Thank you!

/Max

I have same error here. Did you manage to figure it out ?

I checked the value of all the “input_number.roborock_room_enum_room” in the developper tools and they are correct.

Then I tried to force the value of the "room_id " variable, and it worked (it cleaned the specific room)…
So ,instead of

        params: |
                {% set room_id = states("input_number.roborock_room_enum_"+room)
                | int %} {{room_id}}

I set

        params: |
                {% set room_id = 21 %} {{room_id}}

I also tried

        params: |
                {% set room_id = states("input_number.roborock_room_enum_"+room)
                | int(0) %} {{room_id}}

No error this time. The script runs but It does not clean anything (I think it takes the 0 value).