Xiaomi Vacuum as segment cleaning switch in HomeKit

Hello everyone,

I want a switch in HomeKit and Lovelace that turns on my vacuum cleaner for two specific rooms.

For this purpose I have entered the following in my configuration.yaml:

homekit:
 auto_start: true
 filter: 
  include_entities: # Nur die Geräte in Homekit anzeigen, die hier aufgelistete sind
   - vacuum.xiaomi_vacuum_cleaner
   - ???.clean_kitchen_livingroom

switch:
  - platform: template
    switches:
      clean_kitchen_livingroom:
        turn_on:
          data:
            entity_id: vacuum.xiaomi_vacuum_cleaner
            service: xiaomi_miio.vacuum_clean_segment
            segment:
                - 16 # Wohnzimmer
                - 17 # Küchen
        turn_off:
          service: vacuum.return_to_base
          data:
            entity_id: vacuum.xiaomi_vacuum_cleaner

How is it done right?

Many thanks to those who help.
Greeting Tristan

I am quite late to the game, but I did exactly what you described, just somewhat different:

  • Create Scripts that load specific maps (ground floor and first floor)
  • Create binary sensors that react on the last loaded map
  • Create Scripts that start cleaning for a certain area after loading the necessary map if not already loaded
  • My scripts usually wait for the vacuum changing from “cleaning” to not (“cleaning” or “paused”). This leaves the button active until the cleaning is complete (however, it does not work perfectly with chained button presses)…

I exposed all scripts over the Homekit integration (done with the config UI, no yaml) and they appear as buttons. In Homekit you also can create custom scenes that activate a given script switch and use the scene name as kind of activation word, so I now can say something like “Hey Siri, the kitchen is dirty” and this in turn activates the vacuum and sends it to the kitchen.