Xiaomi Vacuum Custom Reminders Part 1

We love our Roborock S5 smart vacuum, but the Mi Home app is missing some key automations for us. The two most important activities we rely on are (1) remembering to run a cleanup, and (2) remembering to empty the dust bin and clean out the brush head.

The first point is forgivable since most people run their vacuum on a schedule, but we have pets and we don't want to accidentally paint the floors with poop, so we run ours manually. The lack of a dust bin reminder however seems like an oversight – the Roborock even has a dust bin sensor, but you can't check the status manually and it won't remind you to empty it after a cleanup. The only time the dust bin sensor is engaged is in the middle of a cleanup when it becomes full, causing the cleanup to stall out. We like to start a cleanup when we are on our way out the door so that we can come home to a clean house, but that doesn't work when the vacuum stops halfway because the bin is full.

It's also worth mentioning how important it is to regularly empty the dust bin and clean the brush head. When they get gunked up, the vacuum does not work as well as it should. There is additional strain on the motors and the battery as well. It's well worth going the extra mile to keep everything clear of debris and tangles, and the Mi Home app does not help you to remember these things.

Luckily, Home Assistant enabled us to create custom reminders that go beyond what the Mi Home app offers. Using the xiaomi_miio platform we can glean enough information to create our own custom notifications that show up on the front end and as notifications on our phones.

API Parameters

If you are setting up your vacuum for the first time, follow the official Home Assistant instructions to retrieve your access token and integrate your devices.

Once you get it set up, you can see all of the available attributes in the States panel.

Vacuum State Attributes

Part 1 - Dust Bin and Brush Head Reminders

Entity filter glance card for custom vacuum reminders

The first automation we needed was reminders to empty the dust bin and clean the brush head. We want to see dismissible notifications in the HA front-end and we want to see push notifications on our phone when service is due. We'll define our reminders using boolean flags and we'll use automation rules to control when the flags are set/cleared.

Check out Part 2 to see how we set up cleanup reminders.

Back-end and Lovelace UI Setup

The first step is to define booleans for our reminders. Add the following to configuration.yaml:

input_boolean: !include booleans.yaml

You only have to do this if you haven't used booleans before. I prefer keeping these in a separate yaml file.

Then add a new file in your config folder called booleans.yaml and add the following:

isuck_dust_bin_full:       # Name entity whatever you want
    name: iSuck Dust Bin   # Friendly name
    icon: mdi:robot-vacuum # Default front-end icon

isuck_brush_dirty:         # Name entity whatever you want
    name: iSuck Brush      # Friendly name
    icon: mdi:robot-vacuum # Default front-end icon

The booleans will show up in the States panel after you restart HA. By default, HA will persist the boolean values between restarts.

Now that the booleans are set up, we need automations to turn them on. We'll use a state trigger to fire off the automation when a cleanup is complete. We will also need conditions to make sure the reminders only trigger when a large enough area was cleaned. You will probably want to tweak these values for your own setup.

Add the following to automations.yaml:

- alias: iSuck Large Clean Complete
  trigger:
    platform: state
    entity_id: vacuum.isuck  # Make sure this matches your vac's entity id
    from: cleaning
    to: returning
  condition:
  - condition: template
    value_template: '{{ state_attr(''vacuum.isuck'', ''cleaned_area'') > 70 }}'
  action:
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.isuck_brush_dirty

- alias: iSuck Medium Clean Complete
  trigger:
    platform: state
    entity_id: vacuum.isuck # Make sure this matches your vac's entity id
    from: cleaning
    to: returning
  condition:
  - condition: template
    value_template: '{{ state_attr(''vacuum.isuck'', ''cleaned_area'') > 10 }}'
  action:
  - service: input_boolean.turn_on
    data:
      entity_id: input_boolean.isuck_dust_bin_full

These automations track the state of the vacuum. The vacuum cycles through the states docked -> cleaning -> returning -> docked. The transition from cleaning to returning has proven to be a reliable trigger when a cleanup is complete.

The cleaned_area attribute is reset to zero whenever a cleanup begins, and it counts up square meters until the cleanup is complete. We can use this attribute to define rules for setting our booleans. I found that 10 sqm was a large enough space that I should empty the dust bin before starting the next cleanup, so any cleanup greater than 10 sqm will trip the dust bin flag. This condition will be true for full house cleanups, and for the common zone cleanups that we run, but it will be false for smaller spot-cleanups.

A full cleanup of our house is about 90 sqm. Sometimes areas are closed off, so I set a safer value of 70 to detect a full house cleanup. I prefer to clean the brush head after each full cleaning, so any cleaning over 70 sqm will trip the brush head flag (in addition to tripping the dust bin flag).

This completes the back end setup. Now you can display your booleans in the front end however you want. Below is an example card using an entity-filter glance card.

Add to ui-lovelace.yaml:

- type: entity-filter
  entities:
  - entity: input_boolean.isuck_dust_bin_full
    name: Empty Dust Bin
    hold_action:
      action: toggle
  - entity: input_boolean.isuck_brush_dirty
    name: Clean Brush
    hold_action:
      action: toggle
  show_empty: false
  state_filter:
    - "on"
  card:
    type: glance
    title: Reminders
    show_state: false

The reminders will show up when their respective booleans are set, and you can long press to clear the flag and dismiss the reminders. I used long-press instead of tap to avoid accidental dismissals.

Push Notifications

Android Push Notifications

Now we will add push notifications for our reminders. HA will publish notifications whenever the flags are set. We can also build in extra automations to clear the booleans when the notifications are dismissed, and visa versa. In this case we are using html5 notifications on android, but this setup should work for iOS as well.

Start by adding two new automations to automations.yaml:

- alias: iSuck Dust Bin Boolean Turns On - Push Notification
  trigger:
  - entity_id: input_boolean.isuck_dust_bin_full
    platform: state
    from: 'off'
    to: 'on'
  action:
  - data:
      title: iSuck Dust Bin Full
      message: iSuck dust bin is full. Empty it before next cleanup.
      data:
        url: /lovelace/vacuum
        actions:
        - action: complete_isuck_dust_bin
          title: Mark Complete
        tag: "isuck-dust-bin-full"
    service: notify.html5_notifications

- alias: iSuck Brush Boolean Turn On - Push Notification
  trigger:
  - entity_id: input_boolean.isuck_brush_dirty
    platform: state
    from: 'off'
    to: 'on'
  action:
  - data:
      title: iSuck Brush Dirty
      message: iSuck brush is dirty. Clean it before next cleanup.
      data:
        url: /lovelace/vacuum
        actions:
        - action: complete_isuck_brush_dirty
          title: Mark Complete
        tag: "isuck-brush-dirty"
    service: notify.html5_notifications

Make sure to rename the entity_id and url to match your setup. The tag field is important to make sure only one notification appears even if multiple copies are published. You can name the action whatever you want.

Now when the booleans switch from off to on, notifications will be published. The notifications will include an action button to clear the flag so you don't have to go into Home Assistant. You can wire up the action buttons by adding two more automations to automations.yaml:

- alias: iSuck Brush Boolean Notification Complete Event - Turn Off Boolean
  trigger:
  - event_data:
      action: complete_isuck_brush_dirty
    event_type: html5_notification.clicked
    platform: event
  action:
  - data:
      entity_id: input_boolean.isuck_brush_dirty
    service: input_boolean.turn_off
    
- alias: iSuck Dust Bin Boolean Notification Complete Event - Turn Off Boolean
  trigger:
  - event_data:
      action: complete_isuck_dust_bin
    event_type: html5_notification.clicked
    platform: event
  action:
  - data:
      entity_id: input_boolean.isuck_dust_bin_full
    service: input_boolean.turn_off

Make sure the action names match the ones you defined in the notify parameters. Now you can test the notifications by using the States panel to turn on the booleans. You should get notifications on your device, and if you click Mark Complete it should clear the booleans.

The final step is to set up automations to dismiss the push notifications if the flag is cleared. This will ensure that if someone else clears the booleans, or if the booleans are cleared by another automation, that we automatically clean up all of our push notifications.

Add the following to automations.yaml:

- alias: iSuck Brush Boolean Turns Off - Dismiss Notification
  trigger:
  - platform: state
    entity_id: input_boolean.isuck_brush_dirty
    from: 'on'
    to: 'off'
  action:
  - service: notify.html5_dismiss
    data:
      data:
        tag: "isuck-brush-dirty"

- alias: iSuck Dust Bin Boolean Turns Off - Dismiss Notification
  trigger:
  - platform: state
    entity_id: input_boolean.isuck_dust_bin_full
    from: 'on'
    to: 'off'
  action:
  - service: notify.html5_dismiss
    data:
      data:
        tag: "isuck-dust-bin-full"

Make sure that the tag names match the ones defined in the notify parameters. You can test by using the state panel to turn the booleans on and off. Turning them on should publish notifications to your devices, and turning them off should dismiss the notifications.

That's it! Now whenever a cleanup is complete, we have entities in HA to track whether or not we remembered to empty the dust bin and clean the brush head. Cleanups can still be triggered from Mi Home or the button on the vacuum and HA will still perform its automations. When a large enough cleanup is complete we will get notifications on all of our devices to service the vacuum. When one device marks the reminder completed, it will clear the notifications for everyone else.

Here are some other automations I am considering:

  • Push Notifications to nag us once a day when we neglect to empty the dust bin or clean the brush head. Add an additional action button to suppress this notification. Next full cleanup will un-suppress it.
  • Push Notification if a cleanup is triggered while either of the flags are still set.
  • Interrupt cleanup if a cleanup is triggered while either of the flags are still set. Require that both flags are cleared

Check out Part 2 to see how to automate cleanup reminders.