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.