Xiaomi Vacuum cleaner Card

Dumb question…how would I build the sensor template to get hours in total cleaning time and cleaned are in m²….?

Mine looks like this with appddaemon hadashboard

2 Likes

If you want get area and time for last cleaning session:

sensor:
  - platform: template
    sensors:
      vacuum_cleaned_area:
        friendly_name: "Area cleaned"
        unit_of_measurement: 'm2'
        value_template: "{{ state_attr('vacuum.<your_name>', 'cleaned_area') }}"
      vacuum_cleaning_time:
        friendly_name: "Time cleaned"
        unit_of_measurement: 'm'
        value_template: "{{ state_attr('vacuum.<your_name>', 'cleaning_time') }}"

Note that cleaning time is in minutes - if you indeed want this to be in hours, you will have to make conversion additionally to time format you prefer.

If you indeed want total time and area that has been cleaned by vacuums since the century it remembers itself from :slight_smile: you can use total_cleaning_time and total_cleaned_area attributes respectively.

1 Like

Thanks for zour response. I already have all thise template sensors set up WHat I want is just the right conversation for it :slight_smile:

Will share my config soon, trying to make it smaller and more compact :slight_smile:

1 Like

Looking forward to it!

1 Like

So this is my card:

Here’s my code,a bit messy tho:
Lovalace UI:

          - type: custom:vertical-stack-in-card
            cards:
            - type: picture-elements
              title: Vacuum
              image: '/local/vacuum1.jpg'
              elements:
                - type: icon
                  icon: mdi:bell-ring
                  tap_action: call-service
                  entity: vacuum.xiaomi_vacuum_cleaner
                  service: vacuum.locate
                  style:
                   top: 90%
                   left: 80%
                   color: '#3090C7'
                - type: icon
                  icon: mdi:crosshairs
                  tap_action: call-service
                  entity: vacuum.xiaomi_vacuum_cleaner
                  service: vacuum.clean_spot
                  style:
                   top: 90%
                   left: 65%
                   color: '#3090C7'
                - type: icon
                  tap_action: call-service
                  icon: mdi:home
                  entity: vacuum.xiaomi_vacuum_cleaner
                  service: vacuum.return_to_base
                  style:
                   top: 90%
                   left: 50%
                   color: '#3090C7'
                - type: icon
                  icon: mdi:stop
                  tap_action: call-service
                  entity: vacuum.xiaomi_vacuum_cleaner
                  service: vacuum.stop
                  style:
                   top: 90%
                   left: 35%
                   color: '#3090C7'
                - type: icon
                  icon: mdi:play
                  tap_action: call-service
                  entity: vacuum.xiaomi_vacuum_cleaner
                  service: vacuum.start
                  style:
                   top: 90%
                   left: 20%
                   color: '#3090C7'
                - type: state-label
                  entity: sensor.vacuum_operation
                  style:
                   top: 10%
                   left: 1%
                   color: rgb(255, 255, 255)
                   transform: translate(0%,-50%)
                   pointer-events: none
                   font-family: Trebuchet MS
                   font-size: 90%
                   font-weight: bold
                   border-color: rgb(34, 154, 210)
                   background-color: '#3090C7'
                   border-radius: 6px
                - type: state-label
                  entity: sensor.vacuum_accessories
                  style:
                   top: 10%
                   right: 1%
                   color: rgb(255, 255, 255)
                   transform: translate(0%,-50%)
                   pointer-events: none
                   font-family: Trebuchet MS
                   font-size: 90%
                   font-weight: bold
                   border-color: rgb(34, 154, 210)
                   background-color: '#3090C7'
                   border-radius: 6px
                - type: state-label
                  tap_action: more-info
                  entity: vacuum.xiaomi_vacuum_cleaner
                  style:
                   top: 14%
                   right: 38%
                   color: rgb(255, 255, 255)
                   transform: translate(0%,-50%)
                   font-family: Trebuchet MS
                   font-size: 150%
                   font-weight: bold
                   border-color: rgb(34, 154, 210)
                   border-radius: 6px
                   background-color: '#cccccc'
                - type: state-label
                  entity: sensor.vacuum_cleanmainbrush
                  style:
                    top: 35%
                    right: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 76%
                    font-weight: bold
                    border-right-style: solid
                    border-color: rgb(34, 154, 210)
                - type: state-label
                  entity: sensor.vacuum_cleansidebrush
                  style:
                    top: 45%
                    right: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 76%
                    font-weight: bold
                    border-right-style: solid
                    border-color: rgb(34, 154, 210)
                - type: state-label
                  entity: sensor.vacuum_cleanfilter
                  style:
                    top: 55%
                    right: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 76%
                    font-weight: bold
                    border-right-style: solid
                    border-color: rgb(34, 154, 210)
                    opacity: 0.8
                - type: state-label
                  entity: sensor.vacuum_sensordirtyleft
                  style:
                    top: 65%
                    right: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 76%
                    font-weight: bold
                    border-right-style: solid
                    border-color: rgb(34, 154, 210)
                - type: state-label
                  entity: sensor.vacuum_status
                  style:
                    top: 40%
                    left: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 80%
                    font-weight: bold
                    border-left-style: solid
                    border-color: '#3090C7'
                - type: state-label
                  entity: sensor.vacuum_battery
                  style:
                    top: 50%
                    left: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 80%
                    font-weight: bold
                    border-left-style: solid
                    border-color: rgb(34, 154, 210)
                - type: state-label
                  entity: sensor.vacuum_fan_speed
                  style:
                    top: 60%
                    left: 1%
                    color: '#ffffff'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 80%
                    font-weight: bold
                    border-left-style: solid
                    border-color: rgb(34, 154, 210)
                - type: state-label
                  entity: sensor.vacuum_cleaned_area
                  prefix: "Area:"
                  style:
                    top: 79%
                    left: 31%
                    color: '#84a6ba'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 80%
                    font-weight: bold
                - type: state-label
                  entity: sensor.vacuum_cleaning_time
                  prefix: "Time:"
                  style:
                    top: 79%
                    left: 51%
                    color: '#84a6ba'
                    transform: translate(0%,-50%)
                    pointer-events: none
                    font-family: Trebuchet MS
                    font-size: 80%
                    font-weight: bold
            - type: entities
              entities:
              - entity: input_select.vacuum_room
            - type: glance
              columns: 2
              entities:
              - entity: input_boolean.disable_dustbin_notification
                name: Disable Notification
              - entity: input_boolean.disable_daily_vacuum
                name: Disable Daily Cleanup

Configuration yaml areas,

sensor:
 platform: template
    sensors:
      vacuum_status:
        friendly_name: Status
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Status: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.status }}'
        icon_template: >
          {% set val =  states.vacuum.xiaomi_vacuum_cleaner.attributes.status  %}
          {% if val == 'Charging' %}
            mdi:battery-charging
          {% elif val == 'Cleaning' %}
            mdi:move-resize
          {% elif val == 'Returning home' %}
            mdi:keyboard-return
          {% elif val == 'Idle' %}
            mdi:dots-horizontal
          {% elif val == 'Paused' %}
            mdi:pause-circle
          {% else %}
            mdi:help-circle
          {% endif %}
      vacuum_fan_speed:
        friendly_name: Fan Speed
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Mode: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.fan_speed }}'
        icon_template: 'mdi:speedometer'
      vacuum_battery:
        friendly_name: Vacuum Battery
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Battery: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.battery_level }}'
        unit_of_measurement: '%'
        icon_template: '{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.battery_icon }}'
      vacuum_cleaning_time:
        friendly_name: Time of Last Cycle
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: '{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.cleaning_time }}'
        icon_template: 'mdi:timer'
      vacuum_cleaned_area:
        friendly_name: Area of Last Cycle
        unit_of_measurement: 'm ²'
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: '{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.cleaned_area }}'
        icon_template: 'mdi:ruler'
      vacuum_cleanmainbrush:
        friendly_name: Replace main brush
        unit_of_measurement: 'h'
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Main Brush: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.main_brush_left }}'
        icon_template: 'mdi:screwdriver'
      vacuum_cleansidebrush:
        friendly_name: Replace side brush
        unit_of_measurement: 'h'
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Side brush: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.side_brush_left }}'
        icon_template: 'mdi:screwdriver'
      vacuum_cleanfilter:
        friendly_name: Replace filter
        unit_of_measurement: 'h'
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Filter: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.filter_left }}'
        icon_template: 'mdi:screwdriver'
      vacuum_sensordirtyleft:
        friendly_name: Replace filter
        unit_of_measurement: 'h'
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: 'Sensor: {{ states.vacuum.xiaomi_vacuum_cleaner.attributes.sensor_dirty_left }}'
        icon_template: 'mdi:screwdriver'
      vacuum_do_not_disturb:
        friendly_name: Do Not Disturb
        entity_id:
          - vacuum.xiaomi_vacuum_cleaner
        value_template: '{{ states.vacuum.xiaomi_vacuum_cleaner.attributes.do_not_disturb }}'
        icon_template: >
          {% set val =  states.vacuum.xiaomi_vacuum_cleaner.attributes.do_not_disturb  %}
          {% if val == 'on' %}
            mdi:do-not-disturb
          {% else %}
            mdi:do-not-disturb-off
          {% endif %}
      vacuum_operation:
        value_template: 'Operation'
      vacuum_accessories:
        value_template: 'Maintenance'

vacuum:
    platform: xiaomi_miio
    host: yourvacuumip!
    token: yourtoken!

input_boolean:
  daily_vacuum_first_run:
    name: Daily Vacuum First Run
    initial: 'off'
  disable_daily_vacuum:
    name: Disable Daily Vacuum Automation
    initial: 'off'
  disable_dustbin_notification:
    name: Disable Dustbin Notification
    initial: 'off'

input_select:
  vacuum_room:
    name: Choose a room to clean
    options:
      - Select Input
      - bedroom
      - guest room
      - dining room
      - kitchen
      - living room

Automations yaml:

    alias: Send alert after daily vacuum to empty the dustbin
    trigger:
    - platform: state
      entity_id: device_tracker.galaxy_note_fan_edition
      to: 'home'
      for:
        minutes: 5
    condition:
      condition: and
      conditions:
      - condition: state
        entity_id: input_boolean.daily_vacuum_first_run
        state: 'on'
      - condition: time
        after: '08:30:00'
        before: '23:30:00'
      - condition: template
        value_template: >
          {% if states.automation.send_alert_after_daily_vacuum_to_empty_the_dustbin.last_triggered is not none %}
            {% if as_timestamp(now()) | int   -  as_timestamp(states.automation.send_alert_after_daily_vacuum_to_empty_the_dustbin.attributes.last_triggered) | int > 1800 %} true {% else %} false
            {% endif %}
          {% else %}
          false
          {% endif %}
      - condition: state
        entity_id: input_boolean.disable_dustbin_notification
        state: 'off'
    action:
      - service: media_player.volume_set
        data_template:
          entity_id: media_player.living_room_speaker_3
          volume_level: 0.7
      - service: tts.google_say
        entity_id: media_player.living_room_speaker_3
        data_template:
          message: 'Hey, the vacuum dustbin needs to be emptied!'
          cache: false

    alias: Reset Daily Vacuum First Run state at midnight
    trigger:
    - platform: time
      at: '0:00:00'
    action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.daily_vacuum_first_run

    alias: Start Cleaning Room
    hide_entity: True
    trigger:
    - platform: state
      entity_id: input_select.vacuum_room
      from: 'Select Input'
    action:
    - service: script.turn_on
      data_template:
        entity_id: >
          {% if is_state("input_select.vacuum_room", "bedroom") %}
            script.vacuum_bedroom
          {% elif is_state("input_select.vacuum_room", "guest room") %}
            script.vacuum_guestroom
          {% elif is_state("input_select.vacuum_room", "dining room") %}
            script.vacuum_dining_room
          {% elif is_state("input_select.vacuum_room", "kitchen") %}
            script.vacuum_kitchen
          {% elif is_state("input_select.vacuum_room", "living room") %}
            script.vacuum_living_room
          {% else %}
          {% endif %}
    - service: input_select.select_option
      entity_id: input_select.vacuum_room
      data_template:
        option: "Select Input"
        
    alias: Start Daily Vacuum
    trigger:
    - platform: time
      minutes: '/45'
      seconds: 00
    condition:
      condition: and
      conditions:
      - condition: state
        entity_id: device_tracker.galaxy_note_fan_edition
        state: 'not_home'
      - condition: state
        entity_id: input_boolean.daily_vacuum_first_run
        state: 'off'
      - condition: time
        after: '11:00:00'
        before: '21:00:00'
      - condition: state
        entity_id: input_boolean.disable_daily_vacuum
        state: 'off'
    action:
    - delay: '00:00:15'
    - service: vacuum.turn_on
      entity_id: vacuum.xiaomi_vacuum_cleaner
    - service: homeassistant.turn_on
      entity_id: input_boolean.daily_vacuum_first_run

Scripts yaml:

  vacuum_bedroom:
        alias: "Vacuum Bedroom"
        sequence:
          - service: vacuum.send_command
            data:
              entity_id: vacuum.xiaomi_vacuum_cleaner
              command: app_zoned_clean
              params: [[17500,18000,21800,21000,1]]
  vacuum_dining_room:
        alias: "Vacuum Dining Room"
        sequence:
          - service: vacuum.send_command
            data:
              entity_id: vacuum.xiaomi_vacuum_cleaner
              command: app_zoned_clean
              params: [[22750,23500,26000,26300,1]]
  vacuum_kitchen:
        alias: "Vacuum Kitchen"
        sequence:
          - service: vacuum.send_command
            data:
              entity_id: vacuum.xiaomi_vacuum_cleaner
              command: app_zoned_clean
              params: [[18800,21500,25500,27500,1]]
  vacuum_living_room:
        alias: "Vacuum Living Room"
        sequence:
          - service: vacuum.send_command
            data:
              entity_id: vacuum.xiaomi_vacuum_cleaner
              command: app_zoned_clean
              params: [[19500,21180,26000,26300,1]]
  vacuum_guestroom:
        alias: "Vacuum Guestroom"
        sequence:
          - service: vacuum.send_command
            data:
              entity_id: vacuum.xiaomi_vacuum_cleaner
              command: app_zoned_clean
              params: [[17500,18000,21800,21000,1]]

Here’s the image for my card:

36 Likes

Really nice work :+1:

1 Like

Hi,

Where did you get params to zone cleanup?

You need to get it manually, either get the map from your vacuum or take a screenshot of the map then start plotting the coordinates. Something like 25500,25500 is the starting coordinates.
I can’t recall the measurement but a 1000 is equal to a meter or so, you’ll need to do some Google for that.

Plan B, start doing trial and error. Send the command on Hassio with the coordinates and check at the same time in Mi Home app, the “zone” will show up in the map once the vacuum receives the command.

Then you can hook it up with IFTTT to manage it with Google Assistant via a webhook. “Hey Google, clean my bedroom” or the kitchen, etc. IFTTT receives the command from Google Assistant and sends a HTTP post/request (webhook), which in HA will trigger an specific script to clean an area.

3 Likes

Thank you very much!

thanks!
I keep getting Entity not available: input_select.vacuum_room.

any hints?

is this the part that was missing:

configuration.yaml

input_select:
  vacuum_room:
    options:
      - "bedroom"
      - "guestroom"
      - "living_room"
      - "kitchen"
      - "dining_room"

1 Like

Yes, that’s the part I missed. I just added it to my post. Well, your input_select is loading so it must be something else. Either way here’s the part I missed in my post:

input_select:
  vacuum_room:
    name: Choose a room to clean
    options:
      - Select Input
      - bedroom
      - guest room
      - dining room
      - kitchen
      - living room

Here’s my :slight_smile:
I use packages. I’ve uploaded the code to whoever wants to:

https://gist.github.com/abeksis/e5bc33ba5ee5f4235f7040bcfc255652

Background picture:

5 Likes

I like your layout. can you share the lovelace config?

It’s not possible to select rooms with the first generation vacuum cleaner, right? Only for the roborock

https://hackernoon.com/how-i-set-up-room-cleaning-automation-with-google-home-home-assistant-and-xiaomi-vacuum-cleaner-9149e0267e6d

3 Likes

Gen1 has exactly the same features as Roborock. Only difference is the improved sensors (which to be honest is hard to tell the difference in real life usage, the navigation is identical), detection of rugs, the mopping and slightly higher clearance (I haven’t had any issues on rugs). I also set up the room cleaning.

If the difference is negligible in price for you, go for Roborock. Some people say the reliability on Gen1 isn’t the best and the vacuum stops working or refuses to clean due to the sensor on top failing which is a bit expensive to replace, aside from that nothing else. I have had it for over a year already, haven’t had any issues at all, I think the same goes for many people :slight_smile:

You can’t go wrong with either one, both are a far better purchase than any other robo vacuum out there.

1 Like

I made also a small vacuum cleaner card.
Not with the picture element but with the glance element

The “Wartung” section can be collapsed

2 Likes

I like how it looks! How did you make the section collapsible? Can you share your config?