Zoned cleaning with Xiaomi S50 - Cannot get it right

Hi guys,

I have been attempting to getting a nice setup with my rooted Xiaomi S50 vacuum. I found a cool setup my abeksis that I pretty much wanted to copy to have something to start with.
https://github.com/abeksis/My-HomeAssistant-Config/blob/master/HomeAssistant_File/packages/vacuum_xiaomi/vacuum_xiaomi.yaml

So after messing around with it a lot and translating it to danish etc. I got something that looks like this:

It seems my buttons on the picture elements card are working, and all the sensors show up fine. But I do not understand how the zoned cleaning and automated start on weekdays/weekends work. I can set a zone to clean, and I can put times to run on weekends/weekdays, but nothing seems to happen whatever I do.

I found coordinates for my zones, by first creating the zones in Valetudo and then using: http://rockrobo/api/get_config to get:
`

{“spots”:,“areas”:[[“kitchen1”,[[953,-5035,-2160,333,2],[-2160,-3720,-6441,333,2],[-2160,-5035,-2845,-3720,2]]],[“Hallway”,[[-3947,348,-2576,3930,2],[-6538,2526,-3947,7165,2]]],[“Bedroom”,[[-3957,-9735,899,-6422,2]]],[“Room1”,[[-6401,-6430,-1879,-3637,2]]],[“Living Room”,[[1115,-7514,6743,-3009,2]]]]}

`

This is what my Xiaomi package looks like:

#################################################################
#                                                               #
#                    packages/vacuum_xiaomi                     #
#                                                               #
#################################################################
vacuum:
  - platform: xiaomi_miio
    host: !secret r2d2_ip
    token: !secret r2d2_token
    name: R2D2

#################################################################
#                                                               #
#                          sensor                               #
#                                                               #
#################################################################
sensor:
  - platform: template
    sensors:
      vacuum_start_time_weekdays:
        friendly_name: 'Start Time (weekdays)'
        value_template: '{{ "%0.02d:%0.02d" | format(states("input_number.vacuum_start_hour_weekdays") | int, states("input_number.vacuum_start_minutes_weekdays") | int) }}'
        entity_id: input_number.vacuum_start_hour_weekdays
      vacuum_start_time_weekend:
        friendly_name: 'Start Time (weekend)'
        value_template: '{{ "%0.02d:%0.02d" | format(states("input_number.vacuum_start_hour_weekend") | int, states("input_number.vacuum_start_minutes_weekend") | int) }}'
        entity_id: input_number.vacuum_start_hour_weekend
      vacuum_weekdays:
        friendly_name: "Støvsug - Hverdage"
        value_template: ""
      vacuum_weekend:
        friendly_name: "Støvsug - Weekend"
        value_template: ""
      vacuum_battery:
        friendly_name: "Vacuum - Batteri"
        value_template: "{{ states.vacuum.r2d2.attributes.battery_level | float | int }}% batteri"
        icon_template: '{{ states.vacuum.r2d2.attributes.battery_icon }}'
        device_class: battery
        entity_id: vacuum.r2d2
      vacuum_accessories:
        friendly_name: "Vacuum - Forbrug"
        value_template: "Forbrug"
      vacuum_operation:
        friendly_name: "Vacuum - Operationer"
        value_template: "Operationer"
      vacuum_main_brush:
        friendly_name: "Vacuum - Børste"
        value_template: "Børste {{ states.vacuum.r2d2.attributes.main_brush_left }} timer"
        entity_id: vacuum.r2d2
      vacuum_side_brush:
        friendly_name: "Vacuum - Sidebørste"
        value_template: "Sidebørste: {{ states.vacuum.r2d2.attributes.side_brush_left }} timer"
        entity_id: vacuum.r2d2
      vacuum_filter:
        friendly_name: "Vacuum - Filter"
        value_template: "Filter: {{ states.vacuum.r2d2.attributes.filter_left }} timer"
        entity_id: vacuum.r2d2
      vacuum_sensor:
        friendly_name: "Vacuum - Støv"
        value_template: "Støv: {{ states.vacuum.r2d2.attributes.sensor_dirty_left }} timer"
        entity_id: vacuum.r2d2
      vacuum_fan_speed:
        friendly_name: "Vacuum - Niveau"
        value_template: "Niveau: {{ states.vacuum.r2d2.attributes.fan_speed }}"
        entity_id: vacuum.r2d2
      vacuum_cleaning_time:
        friendly_name: "Cleaning - Tid"
        value_template: "Rengjort tid: {{ states.vacuum.r2d2.attributes.cleaning_time }} timer"
        entity_id: vacuum.r2d2
      vacuum_cleaned_area:
        friendly_name: Rengjort areal
        unit_of_measurement: 'm²'
        value_template: "Areal rengjort: {{ states.vacuum.r2d2.attributes.cleaned_area }}"
        entity_id: vacuum.r2d2        
      vacuum_fan_speed_list:
        friendly_name: "Vacuum - Hastighed"
        value_template: "{{ states.vacuum.r2d2.attributes.fan_speed_list }}"
        entity_id: vacuum.r2d2

#################################################################
#                                                               #
#                          switch                               #
#                                                               #
#################################################################
switch:
  - platform: template
    switches:
      vacuum:
        friendly_name: "Vacuum"
        value_template: "{% if is_state('vacuum.r2d2', 'cleaning') %}on{% else %}off{% endif %}"
        turn_on:
          service: input_select.select_option
          entity_id: input_select.vacuum_zone
          data_template:
            option: "Home"
        turn_off:
          service: vacuum.return_to_base
          data:
            entity_id: vacuum.r2d2
        icon_template: mdi:robot-vacuum

#################################################################
#                                                               #
#                       input select                            #
#                                                               #
#################################################################
input_select:
  vacuum_fan_speed_list:
    name: Suction mode
    options:
    - Stille som en mus
    - Normal
    - Ekstra hvæs
    - Jetfly

  vacuum_zone:
    name: Hvilket område vil du rengøre?
    options:
    - Vælg et område
    - Hjem
    - Køkken
    - Stue
    - Room1
    - Soveværelse
    - Gang
    
#################################################################
#                                                               #
#                         input Boolean                         #
#                                                               #
#################################################################
input_boolean:
  vacuum_zone_settings:
    name: zone settings
    initial: false

#################################################################
#                                                               #
#                         input Number                          #
#                                                               #
#################################################################
input_number:
  vacuum_passes:
    name: Hvor mange gange?
    initial: 1
    min: 1
    max: 3
    step: 1
  vacuum_start_minutes_weekend:
    name: Start minut
    initial: 0
    min: 0
    max: 59
    step: 1
    mode: slider
  vacuum_start_hour_weekend:
    name: Start time
    initial: 13
    min: 8
    max: 16
    step: 1
    mode: slider
  vacuum_start_minutes_weekdays:
    name: Start minut
    initial: 0
    min: 0
    max: 59
    step: 1
    mode: slider
  vacuum_start_hour_weekdays:
    name: Start time
    initial: 10
    min: 9
    max: 15
    step: 1
    mode: slider

#################################################################
#                                                               #
#                          automation                           #
#                                                               #
#################################################################
automation:

  - alias: Vacuum - Suction speed
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: input_select.vacuum_fan_speed_list
    action:
      - service_template: >
          {% if trigger.to_state.state == 'Stille som en mus' %}
            script.vacuum_set_quiet
          {% elif trigger.to_state.state == 'Normal' %}
            script.vacuum_set_balanced
          {% elif trigger.to_state.state == 'Ekstra hvæs' %}
            script.vacuum_set_turbo
          {% elif trigger.to_state.state == 'Jetfly' %}
            script.vacuum_set_max
          {% endif %}

  - alias: Vacuum - Selection of the area
    initial_state: 'on'
    hide_entity: True
    trigger:
      platform: state
      entity_id: input_select.vacuum_zone
      from: 'Vælg område'
    action:
      - service_template: >
          {% if states.input_select.vacuum_zone.state == "Hjem" %}
            script.vacuum_home
          {% elif states.input_select.vacuum_zone.state == "Køkken" %}
            script.vacuum_kitchen
          {% elif states.input_select.vacuum_zone.state == "Stue" %}
            script.vacuum_living_room
          {% elif states.input_select.vacuum_zone.state == "Soveværelse" %}
            script.vacuum_bedroom
          {% elif states.input_select.vacuum_zone.state == "Room1" %}
            script.vacuum_room1
          {% elif states.input_select.vacuum_zone.state == "Gang" %}
            script.vacuum_hallway           
          {% else %}
          {% endif %}
      - delay: 00:01:00
      - wait_template: "{{is_state('vacuum.r2d2', 'docked')}}"
      - delay: 00:00:15
      - service: input_select.select_option
        entity_id: input_select.vacuum_zone
        data_template:
          option: "Vælg område"
      - service: input_select.select_option
        entity_id: input_select.vacuum_fan_speed_list
        data_template:
          option: "Turbo"

  - alias: Vacuum Schedule cleaning on weekdays
    initial_state: 'off'
    trigger:
    - platform: template
      value_template: '{{ states.sensor.vacuum_start_time_weekdays.state == states.sensor.time.state }}'
    condition:
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    action:
    - data:
        entity_id: vacuum.r2d2
      service: vacuum.start

  - alias: Vacuum Schedule cleaning on weekends
    initial_state: 'off'
    trigger:
    - platform: template
      value_template: '{{ states.sensor.vacuum_start_time_weekend.state == states.sensor.time.state }}'
    condition:
    - condition: time
      weekday:
      - sat      
      - sun
    action:
    - data:
        entity_id: vacuum.r2d2
      service: vacuum.start

#################################################################
#                                                               #
#                            script                             #
#                                                               #
#################################################################
script:
  vacuum_set_quiet:
    sequence:
      service: vacuum.set_fan_speed
      data:
        entity_id: vacuum.r2d2
        fan_speed: Quiet

  vacuum_set_balanced:
    sequence:
      service: vacuum.set_fan_speed
      data:
        entity_id: vacuum.r2d2
        fan_speed: Balanced

  vacuum_set_turbo:
    sequence:
      service: vacuum.set_fan_speed
      data:
        entity_id: vacuum.r2d2
        fan_speed: Turbo
 
  vacuum_set_max:
    sequence:
      service: vacuum.set_fan_speed
      data:
        entity_id: vacuum.r2d2
        fan_speed: Max

#################################################################
#                                                               #
#                            zones                              #
#                                                               #
#################################################################
#
#Create in valetudo and use http://rockrobo/api/get_config to get coordinates.
#
  vacuum_home:
    sequence:
    - service: vacuum.xiaomi_clean_zone
      data:
        entity_id: vacuum.r2d2
        repeats_template: '{{states.input_number.vacuum_passes.state|int}}'
        zone: [[-6470, -9970, 6785, 7129]]
    
  vacuum_kitchen:
    sequence:
    - service: vacuum.xiaomi_clean_zone
      data:
        entity_id: vacuum.r2d2
        repeats_template: '{{states.input_number.vacuum_passes.state|int}}'
        zone: [[953,-5035,-2160,333],[-2160,-3720,-6441,333],[-2160,-5035,-2845,-3720]]

  vacuum_living_room:
    sequence:
    - service: vacuum.xiaomi_clean_zone
      data:
        entity_id: vacuum.r2d2
        repeats_template: '{{states.input_number.vacuum_passes.state|int}}'
        zone: [[1115, -7514, 6743, -3009]]

  vacuum_room1_room:
    sequence:
    - service: vacuum.xiaomi_clean_zone
      data:
        entity_id: vacuum.r2d2
        repeats_template: '{{states.input_number.vacuum_passes.state|int}}'
        zone: [[-6401, -6430, -1879, -3637]]

  vacuum_bedroom:
    sequence:
    - service: vacuum.xiaomi_clean_zone
      data:
        entity_id: vacuum.r2d2
        repeats_template: '{{states.input_number.vacuum_passes.state|int}}'
        zone: [[-3957, -9735, 899, -6422]]

  vacuum_hallway:
    sequence:
    - service: vacuum.xiaomi_clean_zone
      data:
        entity_id: vacuum.r2d2
        repeats_template: '{{states.input_number.vacuum_passes.state|int}}'
        zone: [[-3947, 348, -2576, 3930],[-6538, 2526, -3947, 7165]]

#################################################################
#                                                               #
#                          customize                            #
#                                                               #
#################################################################
homeassistant:
  customize:
    switch.vacuum:
      icon: mdi:robot-vacuum
    input_select.vacuum_fan_speed_list:
      icon: mdi:speedometer
    input_select.vacuum_zone:
      icon: mdi:map-marker
    input_number.vacuum_passes:
      name: Pass
      icon: mdi:shuffle-disabled

and this is what I have in ui-lovelace.yaml:

#################################################################
#                                                               #
#                           vacuum                              #
#                                                               #
#################################################################
  - title: R2D2
    name: R2D2
    icon: mdi:robot-vacuum
    type: horizontal
    cards:
      - type: custom:compact-custom-header
      - type: custom:card-modder
        card:
          type: picture-elements
          image: /local/icons/roborock/static/xiaomirobot3.png
          elements:
          - type: image
            entity: input_boolean.vacuum_zone_settings
            tap_action: 
              action: toggle
            hold_action: 
              action: toggle
            image: /local/lovelace/vacuum/map.png
            state_image:
              'on': /local/lovelace/vacuum/map.png
            state_filter:
              'on': brightness(200%) saturate(1.8)
              'off': brightness(80%) saturate(0.8)
            style:
              top: 90%
              left: 65%
              width: 4.5%
          - type: icon
            icon: mdi:information
            tap_action: 
              action: more-info
            entity: vacuum.r2d2
            style:
              top: 90%
              left: 75%
          - type: icon
            icon: mdi:bell-ring
            tap_action: 
              action: call-service
              service: vacuum.locate
            entity: vacuum.r2d2
            style:
              top: 90%
              left: 55%
              "--paper-item-icon-color": rgb(115, 122, 130)
          - type: icon
            tap_action: 
              action: call-service
              service: vacuum.return_to_base
            icon: mdi:home
            entity: vacuum.r2d2
            style:
              top: 90%
              left: 45%
              "--paper-item-icon-color": rgb(115, 122, 130)
          - type: icon
            icon: mdi:play
            tap_action: 
              action: call-service
              service: vacuum.start
            entity: vacuum.r2d2
            style:
              top: 90%
              left: 35%
              "--paper-item-icon-color": rgb(115, 122, 130)
          - type: icon
            icon: mdi:stop
            tap_action: 
              action: call-service
              service: vacuum.stop
            entity: vacuum.r2d2
            style:
              top: 90%
              left: 25%
              "--paper-item-icon-color": rgb(115, 122, 130)
          ## Main Brush ##
          - type: state-label
            entity: sensor.vacuum_main_brush
            style:
              top: 5%
              right: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              text-shadow: 1px 1px black
              font-size: 90%
              font-weight: bold
              opacity: 0.8


          - type: state-label
            entity: sensor.vacuum_side_brush
            style:
              top: 15%
              right: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              font-size: 90%
              font-weight: bold
              opacity: 0.8

          - type: state-label
            entity: sensor.vacuum_filter
            style:
              top: 25%
              right: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              font-size: 90%
              font-weight: bold
              opacity: 0.8

          - type: state-label
            entity: sensor.vacuum_sensor
            style:
              top: 35%
              right: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              font-size: 90%
              font-weight: bold
              opacity: 0.8

          - type: state-label
            entity: vacuum.r2d2
            style:
              top: 10%
              right: 41%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              text-shadow: 1px 1px black
              font-size: 148%
              font-weight: bold
              opacity: 0.8              
              
          - type: state-label
            entity: sensor.vacuum_battery
            style:
              top: 55%
              right: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              font-size: 90%
              font-weight: bold
              opacity: 0.8
   
          - type: state-label
            entity: sensor.vacuum_weekdays
            style:
              top: 75%
              left: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              font-size: 90%
              font-weight: bold
              opacity: 0.8
          - type: state-label
            entity: sensor.vacuum_weekend
            style:
              top: 60%
              left: 1%
              color: rgb(255, 255, 255)
              transform: translate(0%,-50%)
              pointer-events: none
              font-size: 90%
              font-weight: bold
              opacity: 0.8


          - type: image
            entity: automation.vacuum_schedule_cleaning_on_weekdays
            tap_action: 
              action: toggle
            image: /local/lovelace/vacuum/timer-off.png
            state_image:
              'on': /local/lovelace/vacuum/timer.png
            state_filter:
              'on': brightness(200%) saturate(1.8)
              'off': brightness(80%) saturate(0.8)
            style:
              top: 90%
              left: 84%
              width: 4.5%


          - type: image
            entity: automation.vacuum_schedule_cleaning_on_weekends
            tap_action: 
              action: toggle
            image: /local/lovelace/vacuum/timer-off.png
            state_image:
              'on': /local/lovelace/vacuum/timer.png
            state_filter:
              'on': brightness(200%) saturate(1.8)
              'off': brightness(80%) saturate(0.8)
            style:
              top: 90%
              left: 92%
              width: 4.5%


        style:                 
          border-radius: 20px
          border: solid 1px rgba(100,100,100,0.3)
          box-shadow: 3px 3px rgba(0,0,0,0.4)    
          overflow: hidden

#################################################################
#                                                               #
#                 vacuum start time hour minutes card           #
#                                                               #
#################################################################
      - type: vertical-stack
        cards:        
          - type: custom:card-modder
            card:
              type: conditional
              conditions:
                - entity: automation.vacuum_schedule_cleaning_on_weekdays
                  state: "on"
              card:
                type: entities
                entities:
                  - sensor.vacuum_start_time_weekdays
                  - input_number.vacuum_start_hour_weekdays
                  - input_number.vacuum_start_minutes_weekdays
            style:                 
              background-image: url("/local/lovelace/background/cardbackk.png")
              background-repeat: no-repeat
              background-color: rgba(50,50,50,0.3)
              background-size: 100% 200px
              border-radius: 20px
              border: solid 1px rgba(100,100,100,0.3)
              box-shadow: 3px 3px rgba(0,0,0,0.4)

#################################################################
#                                                               #
#                 vacuum start time hour minutes card           #
#                                                               #
#################################################################
      - type: vertical-stack
        cards:        
          - type: custom:card-modder
            card:
              type: conditional
              conditions:
                - entity: automation.vacuum_schedule_cleaning_on_weekends
                  state: "on"
              card:
                type: entities
                entities:
                  - sensor.vacuum_start_time_weekend
                  - input_number.vacuum_start_hour_weekend
                  - input_number.vacuum_start_minutes_weekend
            style:                 
              background-image: url("/local/lovelace/background/cardbackk.png")
              background-repeat: no-repeat
              background-color: rgba(50,50,50,0.3)
              background-size: 100% 200px
              border-radius: 20px
              border: solid 1px rgba(100,100,100,0.3)
              box-shadow: 3px 3px rgba(0,0,0,0.4)

#################################################################
#                                                               #
#         vacuum - turns on zone settings value card            #
#                                                               #
#################################################################
          - type: custom:card-modder
            card:
              type: conditional
              conditions:
                - entity: input_boolean.vacuum_zone_settings
                  state: "on"
              card:
                type: vertical-stack
                cards:
                  - type: entities
                    entities:
                      - input_select.vacuum_fan_speed_list
                      - input_number.vacuum_passes
                      - input_select.vacuum_zone 
            style:                 
              background-image: url("/local/lovelace/background/cardbackk.png")
              background-repeat: no-repeat
              background-color: rgba(50,50,50,0.3)
              background-size: 100% 130px
              border-radius: 20px
              border: solid 1px rgba(100,100,100,0.3)
              box-shadow: 3px 3px rgba(0,0,0,0.4)

#################################################################
#                                                               #
#                    vacuum - zone fan card                     #
#                                                               #
#################################################################
      - type: vertical-stack
        cards:             
          - type: custom:card-modder
            card:
              type: glance
              entities:
                - entity: input_boolean.vacuum_zone_settings
                  name: Zone indstillinger
                - entity: input_select.vacuum_fan_speed_list
                  name: Styrke
            style:                 
              background-image: url("/local/lovelace/background/cardbackk.png")
              background-repeat: no-repeat
              background-color: rgba(50,50,50,0.3)
              background-size: 100% 130px
              border-radius: 20px
              border: solid 1px rgba(100,100,100,0.3)
              box-shadow: 3px 3px rgba(0,0,0,0.4)

Can anyone help point me in the right direction as to how to get this working?

1 Like