Room Cleaning Automation Script

Hey folks, I’m trying to set up a room cleaning script I can call with different parameters, to make my cleaning automations easier to maintain. I’ve got a Roborock S7 through the Roborock integration.

I need two parameters - which room is getting cleaned and if I need vacuuming or mopping. The script needs to tell the device what mop intensity and fan speed needs to be set, then start a segment cleaning with the selected room. I’ve got something set up, but it’s not really working, I was wondering if someone can help me out.

Here’s what I’ve got so far:

alias: Clean Room
fields:
  mode:
    name: Mode
    description: Vacuum or mop a room
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - Vacuum
          - Mop
  room:
    name: Room
    description: The room to clean
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - label: Bedroom
            value: "18"
          - label: Hallway
            value: "21"
          - label: Kitchen
            value: "16"
          - label: Living Room
            value: "17"
          - label: Studio
            value: "19"
sequence:
  - device_id: ________
    domain: select
    entity_id: select.rumen_mop_intensity
    type: select_option
    option: "{{ 'intense' if mode == 'Mop' else 'off' }}"
  - service: vacuum.set_fan_speed
    data:
      fan_speed: "{{ 'balanced' if mode == 'Mop' else 'max' }}"
    target:
      entity_id: vacuum.rumen
  - service: vacuum.send_command
    data:
      command: app_segment_clean
      params:
        - segments:
            - "{{ room }}"
        - repeat: "{{ '2' if mode == 'Mop' else '1' }}"
    target:
      entity_id: vacuum.rumen
mode: queued
max: 10

Running the script results in an error:

Error: Option {{ 'intense' if mode == 'Mop' else 'off' }} not valid for select.rumen_mop_intensity

Managed to get it running in a different way. If anyone is interested, here’s the final script:

alias: Clean Room
fields:
  mode:
    name: Mode
    description: Vacuum or mop a room
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - Vacuum
          - Mop
  room:
    name: Room
    description: The room to clean
    required: true
    selector:
      select:
        mode: list
        multiple: true
        options:
          - label: Bedroom
            value: "18"
          - label: Hallway
            value: "21"
          - label: Kitchen
            value: "16"
          - label: Living Room
            value: "17"
          - label: Studio
            value: "19"
sequence:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: sensor.rumen_status
                state: idle
              - condition: state
                entity_id: sensor.rumen_status
                state: returning_home
              - condition: state
                entity_id: sensor.rumen_status
                state: charging
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ mode == 'Mop' }}"
                sequence:
                  - device_id: ________________
                    domain: select
                    entity_id: select.rumen_mop_intensity
                    type: select_option
                    option: intense
                  - service: vacuum.set_fan_speed
                    data:
                      fan_speed: balanced
                    target:
                      entity_id: vacuum.rumen
                  - service: vacuum.send_command
                    data:
                      command: app_segment_clean
                      params:
                        - segments:
                            - "{{ room }}"
                        - repeat: "2"
                    target:
                      entity_id: vacuum.rumen
                  - service: input_boolean.turn_on
                    data: {}
                    target:
                      entity_id: "{{ 'input_boolean.rumen_mopping_' + room }}"
              - conditions:
                  - condition: template
                    value_template: "{{ mode == 'Vacuum' }}"
                sequence:
                  - device_id: _____________
                    domain: select
                    entity_id: select.rumen_mop_intensity
                    type: select_option
                    option: "off"
                  - service: vacuum.set_fan_speed
                    data:
                      fan_speed: max
                    target:
                      entity_id: vacuum.rumen
                  - service: vacuum.send_command
                    data:
                      command: app_segment_clean
                      params:
                        - segments:
                            - "{{ room }}"
                        - repeat: "1"
                    target:
                      entity_id: vacuum.rumen
                  - service: input_boolean.turn_on
                    data: {}
                    target:
                      entity_id: "{{ 'input_boolean.rumen_vacuuming_' + room }}"
    default:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: idle
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: returning_home
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: charging
        continue_on_timeout: false
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id:
            - input_boolean.rumen_mopping_16
            - input_boolean.rumen_mopping_17
            - input_boolean.rumen_mopping_18
            - input_boolean.rumen_mopping_19
            - input_boolean.rumen_mopping_21
            - input_boolean.rumen_vacuuming_16
            - input_boolean.rumen_vacuuming_17
            - input_boolean.rumen_vacuuming_18
            - input_boolean.rumen_vacuuming_19
            - input_boolean.rumen_vacuuming_21
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ mode == 'Mop' }}"
            sequence:
              - device_id: ________
                domain: select
                entity_id: select.rumen_mop_intensity
                type: select_option
                option: intense
              - service: vacuum.set_fan_speed
                data:
                  fan_speed: balanced
                target:
                  entity_id: vacuum.rumen
              - service: vacuum.send_command
                data:
                  command: app_segment_clean
                  params:
                    - segments:
                        - "{{ room }}"
                    - repeat: "2"
                target:
                  entity_id: vacuum.rumen
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: "{{ 'input_boolean.rumen_mopping_' + room }}"
          - conditions:
              - condition: template
                value_template: "{{ mode == 'Vacuum' }}"
            sequence:
              - device_id: ________
                domain: select
                entity_id: select.rumen_mop_intensity
                type: select_option
                option: "off"
              - service: vacuum.set_fan_speed
                data:
                  fan_speed: max
                target:
                  entity_id: vacuum.rumen
              - service: vacuum.send_command
                data:
                  command: app_segment_clean
                  params:
                    - segments:
                        - "{{ room }}"
                    - repeat: "1"
                target:
                  entity_id: vacuum.rumen
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: "{{ 'input_boolean.rumen_vacuuming_' + room }}"
mode: queued
max: 10
1 Like

On device_id: ____________ I have to put the device_id I get from get_room_mapping right?

I don’t get any error but when I manually run the script It doesn’t show up the menu to choose the clean type and room :confused:

It is also visible in other places, but yea, I think it’s the same one you get from the room mapping.

I think manually calling the script doesn’t have the parameters. If you do it through an automation or a button or anything that can have the action call-service it should give you the parameters. I use it through buttons on the custom room card:

tap_action:
  action: call-service
  service: script.clean_room
  service_data:
    mode: Vacuum
    room: '19'
  data:
    skip_condition: true

I made some changes and managed to get it running, so far I’ve only tested the vacuuming. Calls to the script successfully queue up and I added some helper toggles that I can use as states for which room is getting cleaned at the moment:

alias: Clean Room
fields:
  mode:
    name: Mode
    description: Vacuum or mop a room
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - Vacuum
          - Mop
  room:
    name: Room
    description: The room to clean
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - label: Bedroom
            value: "18"
          - label: Hallway
            value: "20"
          - label: Kitchen
            value: "16"
          - label: Living Room
            value: "17"
          - label: Studio
            value: "19"
sequence:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: sensor.rumen_status
                state: idle
              - condition: state
                entity_id: sensor.rumen_status
                state: returning_home
              - condition: state
                entity_id: sensor.rumen_status
                state: charging
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ mode == 'Mop' }}"
                sequence:
                  - device_id: 851842ef42182631f9c2e6bc43cb2377
                    domain: select
                    entity_id: select.rumen_mop_intensity
                    type: select_option
                    option: intense
                  - service: vacuum.set_fan_speed
                    data:
                      fan_speed: balanced
                    target:
                      entity_id: vacuum.rumen
                  - service: vacuum.send_command
                    data:
                      command: app_segment_clean
                      params:
                        - segments:
                            - "{{ room }}"
                        - repeat: "2"
                    target:
                      entity_id: vacuum.rumen
                  - service: input_boolean.turn_on
                    data: {}
                    target:
                      entity_id: "{{ 'input_boolean.rumen_mopping_' + room }}"
                  - service: input_text.set_value
                    data:
                      value: "{{ room }}"
                    target:
                      entity_id: input_text.rumen_last_room
              - conditions:
                  - condition: template
                    value_template: "{{ mode == 'Vacuum' }}"
                sequence:
                  - device_id: 851842ef42182631f9c2e6bc43cb2377
                    domain: select
                    entity_id: select.rumen_mop_intensity
                    type: select_option
                    option: "off"
                  - service: vacuum.set_fan_speed
                    data:
                      fan_speed: max
                    target:
                      entity_id: vacuum.rumen
                  - service: vacuum.send_command
                    data:
                      command: app_segment_clean
                      params:
                        - segments:
                            - "{{ room }}"
                        - repeat: "1"
                    target:
                      entity_id: vacuum.rumen
                  - service: input_boolean.turn_on
                    data: {}
                    target:
                      entity_id: "{{ 'input_boolean.rumen_vacuuming_' + room }}"
                  - service: input_text.set_value
                    data:
                      value: "{{ room }}"
                    target:
                      entity_id: input_text.rumen_last_room
    default:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: idle
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: returning_home
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: charging
        continue_on_timeout: false
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id:
            - input_boolean.rumen_mopping_16
            - input_boolean.rumen_mopping_17
            - input_boolean.rumen_mopping_18
            - input_boolean.rumen_mopping_19
            - input_boolean.rumen_mopping_21
            - input_boolean.rumen_vacuuming_16
            - input_boolean.rumen_vacuuming_17
            - input_boolean.rumen_vacuuming_18
            - input_boolean.rumen_vacuuming_19
            - input_boolean.rumen_vacuuming_21
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ mode == 'Mop' }}"
            sequence:
              - device_id: ___________
                domain: select
                entity_id: select.rumen_mop_intensity
                type: select_option
                option: intense
              - service: vacuum.set_fan_speed
                data:
                  fan_speed: balanced
                target:
                  entity_id: vacuum.rumen
              - service: vacuum.send_command
                data:
                  command: app_segment_clean
                  params:
                    - segments:
                        - "{{ room }}"
                    - repeat: "2"
                target:
                  entity_id: vacuum.rumen
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: "{{ 'input_boolean.rumen_mopping_' + room }}"
              - service: input_text.set_value
                data:
                  value: "{{ room }}"
                target:
                  entity_id: input_text.rumen_last_room
          - conditions:
              - condition: template
                value_template: "{{ mode == 'Vacuum' }}"
            sequence:
              - device_id: _____________
                domain: select
                entity_id: select.rumen_mop_intensity
                type: select_option
                option: "off"
              - service: vacuum.set_fan_speed
                data:
                  fan_speed: max
                target:
                  entity_id: vacuum.rumen
              - service: vacuum.send_command
                data:
                  command: app_segment_clean
                  params:
                    - segments:
                        - "{{ room }}"
                    - repeat: "1"
                target:
                  entity_id: vacuum.rumen
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: "{{ 'input_boolean.rumen_vacuuming_' + room }}"
              - service: input_text.set_value
                data:
                  value: "{{ room }}"
                target:
                  entity_id: input_text.rumen_last_room
  - wait_for_trigger:
      - platform: state
        entity_id:
          - sensor.rumen_status
        to: idle
      - platform: state
        entity_id:
          - sensor.rumen_status
        to: returning_home
      - platform: state
        entity_id:
          - sensor.rumen_status
        to: charging
    continue_on_timeout: false
mode: queued
max: 10

Additionally, to turn off the helper toggles if I send the vacuum home manually, I added an automation that triggers when the state changes to returning home:

alias: "Rumen: Done Cleaning"
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.rumen_status
    to: idle
  - platform: state
    entity_id:
      - sensor.rumen_status
    to: returning_home
  - platform: state
    entity_id:
      - sensor.rumen_status
    to: charging
condition: []
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id:
        - input_boolean.rumen_mopping_16
        - input_boolean.rumen_mopping_17
        - input_boolean.rumen_mopping_18
        - input_boolean.rumen_mopping_19
        - input_boolean.rumen_mopping_20
        - input_boolean.rumen_vacuuming_16
        - input_boolean.rumen_vacuuming_17
        - input_boolean.rumen_vacuuming_18
        - input_boolean.rumen_vacuuming_19
        - input_boolean.rumen_vacuuming_20
mode: single

I’ll try the mopping this weekend, I think everything should be the same, I just had some issues with the repeat last time I tried mopping.

Thanks :relaxed:
I tried this morning but it returned some error, I couldn’t see what the error was because I was late for work. If I could see it in logbook to see what’s happening and you know how I’ll be grateful, if not later today I’ll check everything to see if I find the needle in the farm :sweat_smile:

Share the error once you find it, I’ll try my best to help.

Unfortunately, I’m not good at English.

I have a Roborock S5 MAX cleaning machine.
I tried to create the script myself for several days, but in vain.

Please share the whole process with us.
The last version of the script, the code lines of the cards and the automation.
Please share pictures or videos.
I’m not a beginner, but I haven’t advanced knowledge.

I would like to make it possible about each room to have a button (input_boolean) and when I press it (state ON) and finally the “Start clean” input_boolean (I change it to ON state) then vacuuming starts in the selected rooms.

:exclamation: Extras: :exclamation:
It would be even better if we could also determine the order.
E.g:
Rooms:

  • Living room
  • Kitchen
  • Hallway
  • Bathroom

Today I would choose Hallway and Living room in the following order. Tomorrow it could be Living room, Bathroom, Hallway. After tomorrow it could be Bathroom, Kitchen, Living room and Hallway.
Do you think it is possible to determine which room to vacuum and in what order before starting the cleaning?
And when you’ve finished cleaning and returned to the dock, the buttons should switch back to OFF.

I would greatly appreciate your help! :slightly_smiling_face:

Hey, I’ll try to explain how I’ve set things up and how everything works.

THE CLEANING SCRIPT

alias: Clean Room
fields:
  mode:
    name: Mode
    description: Vacuum or mop a room
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - Vacuum
          - Mop
  room:
    name: Room
    description: The room to clean
    required: true
    selector:
      select:
        mode: dropdown
        options:
          - label: Bedroom
            value: "18"
          - label: Hallway
            value: "20"
          - label: Kitchen
            value: "16"
          - label: Living Room
            value: "17"
          - label: Studio
            value: "19"
sequence:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: sensor.rumen_status
                state: idle
              - condition: state
                entity_id: sensor.rumen_status
                state: returning_home
              - condition: state
                entity_id: sensor.rumen_status
                state: charging
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ mode == 'Mop' }}"
                sequence:
                  - device_id: <YOUR DEVICE ID>
                    domain: select
                    entity_id: select.rumen_mop_intensity
                    type: select_option
                    option: intense
                  - service: vacuum.set_fan_speed
                    data:
                      fan_speed: balanced
                    target:
                      entity_id: vacuum.rumen
                  - service: vacuum.send_command
                    data:
                      command: app_segment_clean
                      params:
                        - segments:
                            - "{{ room }}"
                          repeat: 2
                    target:
                      entity_id: vacuum.rumen
                  - service: input_boolean.turn_on
                    data: {}
                    target:
                      entity_id: "{{ 'input_boolean.rumen_mopping_' + room }}"
                  - service: input_text.set_value
                    data:
                      value: "{{ room }}"
                    target:
                      entity_id: input_text.rumen_last_room
              - conditions:
                  - condition: template
                    value_template: "{{ mode == 'Vacuum' }}"
                sequence:
                  - device_id: <YOUR DEVICE ID>
                    domain: select
                    entity_id: select.rumen_mop_intensity
                    type: select_option
                    option: "off"
                  - service: vacuum.set_fan_speed
                    data:
                      fan_speed: max
                    target:
                      entity_id: vacuum.rumen
                  - service: vacuum.send_command
                    data:
                      command: app_segment_clean
                      params:
                        - segments:
                            - "{{ room }}"
                          repeat: 1
                    target:
                      entity_id: vacuum.rumen
                  - service: input_boolean.turn_on
                    data: {}
                    target:
                      entity_id: "{{ 'input_boolean.rumen_vacuuming_' + room }}"
                  - service: input_text.set_value
                    data:
                      value: "{{ room }}"
                    target:
                      entity_id: input_text.rumen_last_room
    default:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: idle
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: returning_home
          - platform: state
            entity_id:
              - sensor.rumen_status
            to: charging
        continue_on_timeout: false
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id:
            - input_boolean.rumen_mopping_16
            - input_boolean.rumen_mopping_17
            - input_boolean.rumen_mopping_18
            - input_boolean.rumen_mopping_19
            - input_boolean.rumen_mopping_21
            - input_boolean.rumen_vacuuming_16
            - input_boolean.rumen_vacuuming_17
            - input_boolean.rumen_vacuuming_18
            - input_boolean.rumen_vacuuming_19
            - input_boolean.rumen_vacuuming_21
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ mode == 'Mop' }}"
            sequence:
              - device_id: <YOUR DEVICE ID>
                domain: select
                entity_id: select.rumen_mop_intensity
                type: select_option
                option: intense
              - service: vacuum.set_fan_speed
                data:
                  fan_speed: balanced
                target:
                  entity_id: vacuum.rumen
              - service: vacuum.send_command
                data:
                  command: app_segment_clean
                  params:
                    - segments:
                        - "{{ room }}"
                      repeat: 2
                target:
                  entity_id: vacuum.rumen
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: "{{ 'input_boolean.rumen_mopping_' + room }}"
              - service: input_text.set_value
                data:
                  value: "{{ room }}"
                target:
                  entity_id: input_text.rumen_last_room
          - conditions:
              - condition: template
                value_template: "{{ mode == 'Vacuum' }}"
            sequence:
              - device_id: <YOUR DEVICE ID>
                domain: select
                entity_id: select.rumen_mop_intensity
                type: select_option
                option: "off"
              - service: vacuum.set_fan_speed
                data:
                  fan_speed: max
                target:
                  entity_id: vacuum.rumen
              - service: vacuum.send_command
                data:
                  command: app_segment_clean
                  params:
                    - segments:
                        - "{{ room }}"
                      repeat: 1
                target:
                  entity_id: vacuum.rumen
              - service: input_boolean.turn_on
                data: {}
                target:
                  entity_id: "{{ 'input_boolean.rumen_vacuuming_' + room }}"
              - service: input_text.set_value
                data:
                  value: "{{ room }}"
                target:
                  entity_id: input_text.rumen_last_room
  - wait_for_trigger:
      - platform: state
        entity_id:
          - sensor.rumen_status
        to: idle
      - platform: state
        entity_id:
          - sensor.rumen_status
        to: returning_home
      - platform: state
        entity_id:
          - sensor.rumen_status
        to: charging
    continue_on_timeout: false
mode: queued
max: 10

A basic explanation of this script is that when triggered it will do one of two things:

  • If the vacuum is idle, charging, or returning home - it will instruct it to start cleaning a room.
  • If the vacuum is in any other state - it will wait until it is in one of the above states and then trigger instruction.

What you need to change to get it running is to replace <YOUR DEVICE ID> with your device ID and change the room field values to be your room IDs. You can follow along with the Roborock integration documentation to get all the IDs.

HELPER BOOLEANS

I’ve added boolean helpers that turn on when a certain room is being cleaned so I can use them as UI triggers. If you want to do the same, you would 2 boolean helpers for every room. Mine are named: input_boolean.rumen_<MODE>_<ROOM> where the mode is vacuuming or mopping, based on which mode I’ve selected when calling the script.

If you don’t want to use them, you can remove all the input_boolean.turn_off and input_boolean.turn_on from the script.

If you will be using them, you will also need another automation that turns them off when cleaning is complete:

alias: "Rumen: Done Cleaning"
description: ""
trigger:
  - platform: device
    device_id: 851842ef42182631f9c2e6bc43cb2377
    domain: vacuum
    entity_id: 8602935513713fbf2fde95a748491121
    type: docked
  - type: not_running
    platform: device
    device_id: 851842ef42182631f9c2e6bc43cb2377
    entity_id: eb7b7ee50ed14dddb67cfcfae4146f58
    domain: binary_sensor
condition: []
action:
  - service: input_boolean.turn_off
    target:
      entity_id:
        - input_boolean.rumen_mopping_16
        - input_boolean.rumen_mopping_17
        - input_boolean.rumen_mopping_18
        - input_boolean.rumen_mopping_19
        - input_boolean.rumen_mopping_20
        - input_boolean.rumen_vacuuming_16
        - input_boolean.rumen_vacuuming_17
        - input_boolean.rumen_vacuuming_18
        - input_boolean.rumen_vacuuming_19
        - input_boolean.rumen_vacuuming_20
    data: {}
mode: single

UI TRIGGER CONFIGURATION

For my dashboard, I am using the Room Card, but it should be a similar setup for anything else. Here’s how my buttons are configured:

- entities:
      - entity: input_boolean.rumen_vacuuming_16
        name: Vacuum
        state_color: true
        icon: mdi:robot-vacuum
        show_icon: true
        tap_action:
          action: call-service
          service: script.clean_room
          service_data:
            mode: Vacuum
            room: '16'
          data:
            skip_condition: true
        double_tap_action:
          action: none
      - entity: input_boolean.rumen_mopping_16
        name: Mop
        state_color: true
        icon: mdi:robot-vacuum-variant
        show_icon: true
        tap_action:
          action: call-service
          service: script.clean_room
          service_data:
            mode: Mop
            room: '16'
          data:
            skip_condition: true
        double_tap_action:
          action: none

What is important here is to pass the correct parameters to the script so it does what you want it to do in the correct room.

The entity is my boolean helper for the corresponding room and action. If you are using the helpers, this will change the color according to the state of the helpers. For example, it is currently vacuuming the kitchen:
image

PHYSICAL BUTTONS CONFIGURAION

I’ve got some Philips Hue switches that I use for a bunch of stuff, including calling the vacuum to a room. Here’s how I’ve got that set up:

description: "Vacuum Bedroom"
mode: single
trigger:
  - device_id: e9da518ea8f888c6d4a20883e79751c9
    domain: hue
    platform: device
    type: repeat
    subtype: 4
    unique_id: 87922b93-6313-4bb5-aee8-b16e047cc836
condition: []
action:
  - service: script.clean_room
    metadata: {}
    data:
      mode: Vacuum
      room: "18"

ADDITIONAL NOTES

I’ve set up the fields for the script to be dropdowns, this way it will be easier when creating an automation in the visual editor:

The cleaning script is in queue mode with a maximum queue length of 10, I use this to queue my whole-house cleaning. It might be what you’re looking for with the multiple-room cleaning. I’m not sure if there is a way to see or modify the queue, I usually spam the return to dock button to clear the queue.

1 Like