Vacuum.send_command help with rooms in command: spot_area

I have a robot vacuum that I want to have automations for cleaning specific rooms and would like to know if there is a way to use room names instead of the room numbers. Developer Tools shows the following rooms under state attributes -

room_bedroom: 1
room_bathroom: 2
room_storeroom: 3
room_corridor: 6
room_gym: 7
room_kids_room: 8
room_kitchen: 9
room_living_room: 10

If I use {{ states.vacuum.deebot_n8_pro.attributes.room_name }} I get the room number associated with the name.

In order to create an automation I have to use the vacuum.send_command as follows:

service: vacuum.send_command
target:
  entity_id: vacuum.deebot_n8_pro
data:
  command: spot_area
  params:
    rooms: 6
    cleanings: 1

Is there a way to be able to input the name instead of the number?

Like with an input select?

input_select:
  room_to_clean:
    name: Room to Clean
    options:
      - 'Bedroom'
      - 'Bathroom'
      - 'Storeroom'
      - 'Corridor'
      - 'Gym'
      - 'Kids Room'
      - 'Kitchen'
      - 'Living Room'
service: vacuum.send_command
target:
  entity_id: vacuum.deebot_n8_pro
data:
  command: spot_area
  params:
    rooms: >
      {% set mapper =  {
        'Bedroom' : '1',
        'Bathroom' : '2',
        'Storeroom' : '3',
        'Corridor' : '6',
        'Gym' : '7',
        'Kids Room' : '8',
        'Kitchen' : '9',
        'Living Room' : '10' } %}
      {% set selection = states('input_select.room_to_clean') %}
        {{ mapper[selection] }}
    cleanings: 1
1 Like

That would be easier for launching the cleaning but I prefer buttons. So I am going to have a list of input booleans in an entities card. However, you answered my question. I just needed to replace the number with {{ states.vacuum.deebot_n8_pro.attributes.room_name }} I wasn’t sure if that would work. Now I see that it does. I also learned that the > becomes | when the automation is saved and that it is needed. The data is lost if I don’t use >

service: vacuum.send_command
target:
  entity_id: vacuum.deebot_n8_pro
data:
  command: spot_area
  params:
    rooms: |
      {{ states.vacuum.deebot_n8_pro.attributes.room_corridor }}
    cleanings: 1

It would be nice if the GUI for creating the automation had a dropdown box for the room and cleanings in the parameters box. If the fan speed is also and option that would be nice too. I imagine that would be too low on the to do list of the developers.

Can you please describe the whole process for having this to work? I have a Deeboot N8 Pro+ and I’m trying to integrate some buttons in order to let it clean on a specific room but my HA doesn’t recognize the vacuum.send_command service.
Thanks!

I gave the Deebot away and purchased a Roomba and I don’t remember the process. Sorry.

No problem, I’ve figured it out, I’m thinking about posting an article about the whole process.
Thanks anyway!

1 Like

Here’s my working solution…
NB: Dashboard/button implementation is based on how I have set mine up because I like how it looks. Yours may differ

  1. Create an input_boolean for each room. (ie: Helper > Toggle type)

  2. In your dashboard, create custom:button-card buttons, which toggle an input boolean (one for each room).

type: custom:button-card
entity: input_boolean.kitchen
name: Kitchen
icon: mdi:stove
action: toggle
show_state: false
show_name: true
state:
  - value: 'on'
    color: cornflowerblue
  - value: 'off'
    color: grey
styles:
  card:
    - width: 80px
    - height: 80px
    - '--mdc-ripple-color': lightblue
    - '--mdc-ripple-press-opacity': 0.5
  1. In your dashboard, create custom:button-card button to call the script when tapped.
type: custom:button-card
name: Clean
entity: vacuum.cheryl
icon: mdi:robot-vacuum
show_state: false
show_name: true
state:
  - value: idle
    color: lightgrey
  - value: cleaning
    color: teal
    styles:
      icon:
        - animation: blink 2s infinite
styles:
  card:
    - width: 80px
    - height: 80px
    - '--mdc-ripple-color': lightblue
    - '--mdc-ripple-press-opacity': 0.5
tap_action:
  action: call-service
  service: script.deebot_clean
  service_data:
    entity_id: vacuum.cheryl

Example below of my buttons (including those shown above.

  1. Check the room numbers that your deebot has set. I’m not sure exactly why, but the names don’t always correlate, especially if you rename rooms etc etc. For example, in my screen shot it has “default: -7 -12 -22 -21” which is four separate rooms. I think it has something to do with when you initially map rooms, then name and divide them.
    Take note of the room numbers - ignore the room names.

  1. Create a script, as shown below. At this point, notice that I have entered the number 7 for the “rooms” variable. This is for testing and checking which rooms are which number.
description: Start a deebot cleaning task
variables:
  queue: input_text.deebot_cheryl_queue
  vacuum_bot: vacuum.cheryl
sequence:
  - alias: Get room numbers
    variables:
      rooms: 7
  - alias: Send cleaning job to vacuum
    service: vacuum.send_command
    data:
      entity_id: "{{ vacuum_bot }}"
      command: spot_area
      params:
        rooms: "{{ rooms }}"
        cleanings: 1
    enabled: true
  - service: system_log.write
    data:
      level: error
      message: "Deebot Clean Script: Rooms variable =  {{ rooms }}"
    enabled: false
alias: Deebot Clean
mode: single
  1. Run the script, and watch the Ecovacs app to see which room is being cleaned. Stop the robot vac via the app. Make note of the room that is being cleaned and the room number in the script. Change the room number and run the script again, keeping track of which room is which number. Do this for all room numbers in your list from step 5.

  2. Now youneed to map the names and numbers in a template. This is best achieved with several windows open.

  • Window1 : Dashboard: with all your buttons configured, select one, to toggle and enable an input helper.
  • Window 2: Using the Developer Tools > Template view, create a template as shown below. Use your room name input booleans in the “x” variable in the template. For the “y” variable, put all your room numbers (from step 5) in a comma separated list. My room numbers are 11, 17, 21, 11, 8, 12, 13, 3, 7, 0. Right now it doesn’t matter what order they are in because they definitely aren’t mapped “name < - > number” in the same order your type them. I have searched but can’t figure out how/why the mapping doesn’t correlate in order.
  • One at a time, set an input_helper button/state to be on. You will see the “Result” on the right hand side of the Template view change.
  • If the Result is not the room number that you expect based on which input_boolean you enabled, swap the two numbers in the “y” variable (Result and the expected room number) in your template list. Repeat this for all helpers and numbers, until your list is in the correct order - so that when you toggle a helper, the correct room number is shown in the Result.
  • To check these are all correct, enable multiple input booleans to check that the template gives you a list of the expected room numbers.

Template:

{% set x = expand('input_boolean.kitchen', 'input_boolean.dining',
        'input_boolean.living', 'input_boolean.master',
        'input_boolean.entrance', 'input_boolean.study',
        'input_boolean.bathroom', 'input_boolean.hallway', 'input_boolean.bed2',
        'input_boolean.bed34') | map(attribute='state') | list %} 

        {% set y = [11, 17, 21, 11, 8, 12, 13, 3, 7, 0] %}  {% set ns =
        namespace (z=[]) %}   {% for i in x %} 
          {% if i == 'on' %} 
            {% set ns.z = ns.z + [y[loop.index-1]] %} 
          {% endif %} 
        {% endfor%}   {% set out = ns.z|join(', ') %} {{ out }}

Test by enabling multiple input_booleans for expected room number list.

  1. Update the Script, replacing the “rooms” variable with the template you tested above.
description: Start a deebot cleaning task
variables:
  queue: input_text.deebot_cheryl_queue
  vacuum_bot: vacuum.cheryl
sequence:
  - alias: Get room numbers
    variables:
      rooms: >-
        {% set x = expand('input_boolean.kitchen', 'input_boolean.dining',
        'input_boolean.living', 'input_boolean.master',
        'input_boolean.entrance', 'input_boolean.study',
        'input_boolean.bathroom', 'input_boolean.hallway', 'input_boolean.bed2',
        'input_boolean.bed34') | map(attribute='state') | list %} 

        {% set y = [11, 17, 21, 11, 8, 12, 13, 3, 7, 0] %}  {% set ns =
        namespace (z=[]) %}   {% for i in x %} 
          {% if i == 'on' %} 
            {% set ns.z = ns.z + [y[loop.index-1]] %} 
          {% endif %} 
        {% endfor%}   {% set out = ns.z|join(', ') %} {{ out }}
  - alias: Send cleaning job to vacuum
    service: vacuum.send_command
    data:
      entity_id: "{{ vacuum_bot }}"
      command: spot_area
      params:
        rooms: "{{ rooms }}"
        cleanings: 1
    enabled: true
  - service: system_log.write
    data:
      level: error
      message: "Deebot Clean Script: Rooms variable =  {{ rooms }}"
    enabled: false
alias: Deebot Clean
mode: single

8 Likes

Thanks for sharing your brilliant solution! I have implemented (with a few personal tweaks here and there) your solution in my own dashboard. It works perfect and very intiutively. Again, much appreciated you shared this in such great detail!

Just wanted to say thank you for the step by step. Was able to finally finalize my script which was quite close to working except for the template part.

Thank you so much for this step by step, it’s perfect. I’ve learnt a lot too, win win. You are a star for doing this :smile:

This thread was super helpful for some of the esoteric template syntax (I had previously done something with direct Python scripting, but this is nicer, no need to remote in)

However I did discover a gotcha:
The expand() command expands groups, and removes duplicates, in the process, sorting the resulting list. Which means the order you specify the input_boolean list in the template isn’t the order they get iterated in, and then it doesn’t match the list of room IDs, which confused me for a while.
So I removed the expand and map calls and put the state() call in the comparison instead.

I ended up with this:

{% set x = ['input_boolean.vacuum_kitchen', 
                'input_boolean.vacuum_living_room',
                'input_boolean.vacuum_rumpus_room', 
                'input_boolean.vacuum_bedroom1',
                'input_boolean.vacuum_bedroom2', 
                'input_boolean.vacuum_bedroom3'] | list %} 

    {% set y = [2, 12, 15, 3, 4, 8] %}   
    {% set ns = namespace (z=[]) %}    
    {% for i in x %}
      {% if states(i) == 'on' %} 
        {% set ns.z = ns.z + [y[loop.index-1]] %}  
      {% endif %} 
    {% endfor%}    {% set out = ns.z|join(', ') %}  {{ out }}

There is a really awesome GUI for the Deebot which would probably work for other vacuums with a little tweaking: https://deebot.readthedocs.io/integrations/home-assistant/examples/ui/advanced/

I’d like to add my thanks as well! Set up a brilliant automation/script based on this.

Hi, all! i’m struggling to achieve goal of creating working script for my robot vacuum mijia m40 (xiaomi.vacuum.d110ch) to do room selected cleaning

my script now is looking like this

vacuum_rooms_clean:
  alias: "robot-vacuum clean selected rooms2"
  description: Start robot-vacuum cleaning task
  variables:
  #   # queue: input_text.deebot_cheryl_queue
    vacuum_bot: vacuum.xiaomi_d110ch_95ed_robot_cleaner
  mode: single    
  sequence:
    - alias: Get room numbers
      variables:
        rooms: >-
          {% set x = expand('input_boolean.main_bedroom_vacuum', 'input_boolean.small_bedroom_vacuum',
          'input_boolean.storeroom_vacuum', 'input_boolean.bathroom_vacuum',
          'input_boolean.toilet_vacuum', 'input_boolean.small_hallway_vacuum',
          'input_boolean.garderob_vacuum', 'input_boolean.lobby_vacuum', 'input_boolean.boilroom_vacuum',
          'input_boolean.big_hallway_vacuum', 'input_boolean.livingroom_vacuum','input_boolean.kitchen_vacuum') | map(attribute='state') | list %} 

          {% set y = ['10,1,3,2,1', '7,1,3,2,1', '3,1,3,2,1', '12,1,3,2,1', '8,1,3,2,1', '6,1,3,2,1', '4,1,3,2,1', '5,1,3,2,1', '11,1,3,2,1', '2,1,3,2,1', '1,1,3,2,1', '9,1,3,2,1'] %}  {% set ns =
          namespace (z=[]) %}   {% for i in x %} 
            {% if i == 'on' %} 
              {% set ns.z = ns.z + [y[loop.index-1]] %} 
            {% endif %} 
          {% endfor%}   {% set out = ns.z|join('],[') %} {{ out }}
      
    - alias: Send cleaning job to vacuum       
      action: xiaomi_miot.call_action
      data:
        entity_id: "{{ vacuum_bot }}"
        siid: 4 
        aiid: 1 
        params:
          - piid: 1
            value: 18
          - piid: 10
            value: >-
              {\"selects\":[[{{rooms}}]]}
        force_params: true

Rooms id for my robot have to be like [1,1,3,2,1] where first number is room id. So room1 [1,1,3,2,1], room2 [2,1,3,2,1]. room3 [3,1,3,2,1] etc.
This version of script correctly get my rooms id but the second part of script (sending job to robot) is not executing properly and i think it’s bc of double quotes that need to be around of value

So correct command for my robot that do cleaning for only one selected room is looking like this

action: xiaomi_miot.call_action
data:
  entity_id: vacuum.xiaomi_d110ch_95ed_robot_cleaner
  siid: 4
  aiid: 1
  params:
    - piid: 1
      value: 18
    - piid: 10
      value: "{\"selects\":[[4,1,3,2,1]]}"
  force_params: true

if it will have single quotes around value it will not work. It’s only work if it have double quotes

When i try to do debug of my script in HA it shows that script is working, rooms id properly inserted but script add single quotes around of final value and robot not accept it

I understand that problem is bc of escaping special symbols but i’m not good with jinja and googling not helps much

Will be very grateful If someone could give me advise or working solution

Using Xiaomi Miot For HomeAssistant integration to send commands to robot!

p.s. English is not my main language so please take my apologies
p.p.s There is no integration at this moment for showing map and select rooms to clean for this model of robot

Bc of rules of this forum i can’t post more than one screenshot in one post so here is debug results of my script