Skip to content

Instantly share code, notes, and snippets.

@ophilips
Last active June 1, 2023 21:34
Show Gist options
  • Save ophilips/116a2cda6d4e10825826af9640a92199 to your computer and use it in GitHub Desktop.
Save ophilips/116a2cda6d4e10825826af9640a92199 to your computer and use it in GitHub Desktop.
Xiaomi Vacuum as "template fan" for Home Assistant/HomeKit. The fan slider (0-100) in HomeKit will be translated to the the corresponding vacuum presets or speeds (off, Silent, Standard, Medium, Turbo).
# Xiaomi HomeKit
fan:
- platform: template
fans:
xiaomi_fan:
friendly_name: "Xiaomi Vacuum"
value_template: "{%if states('vacuum.xiaomi_vacuum_cleaner') == 'cleaning' %}on{%elif states('vacuum.xiaomi_vacuum_cleaner') == 'paused' %}on{%else %}off{% endif %}"
speed_template: "{{ state_attr('vacuum.xiaomi_vacuum_cleaner', 'fan_speed') }}"
turn_on:
service: vacuum.start
entity_id: vacuum.xiaomi_vacuum_cleaner
# turn_on:
# service: xiaomi_miio.vacuum_clean_zone
# data_template:
# entity_id: vacuum.xiaomi_vacuum_cleaner
# repeats: 1
# zone: [[18724,22506,25440,24620],[23758,20813,24906,22506]]
turn_off:
service: vacuum.return_to_base
entity_id: vacuum.xiaomi_vacuum_cleaner
set_speed:
service: vacuum.set_fan_speed
data_template:
fan_speed: "{{ speed }}"
entity_id: vacuum.xiaomi_vacuum_cleaner
speeds:
- 'off'
- 'Silent'
- 'Standard'
- 'Medium'
- 'Turbo'
# - 'Gentle'
sensor:
- platform: template
sensors:
xiaomi_fan:
unit_of_measurement: '%'
value_template: "{{ state_attr('vacuum.xiaomi_vacuum_cleaner', 'battery_level') }}"
homekit:
entity_config:
fan.xiaomi_fan:
linked_battery_sensor: sensor.xiaomi_fan
@cobch
Copy link

cobch commented Mar 13, 2020

Hi again,

the followings speed settings are not working for me. I only manage to make the vacuum use Gentle or standard mode with these settings. Did anybody managed?

    speeds:
      - 'off'
      - 'Silent'
      - 'Standard'
      - 'Medium'
      - 'Turbo'

- 'Gentle'

@cobch
Copy link

cobch commented Mar 13, 2020

    speeds:
      - 'off'
      - 'Silent'
      - 'Standard'
      - 'Medium'
      - 'Turbo'
     - 'Gentle'

@WLines84
Copy link

Hello ophilips

my code is pretty basic but does the trick of showing the vacuum in the Homekit and having the on/off button:
#Xiaomi Mi Robot Vacuum
vacuum:

  • platform: xiaomi_miio
    host: ##########
    token: ###########
    name: To
    However would it be possible to have this information showing in the Home App in the iPhone? (the print is from the EVE app but the principle is the same)
    image

@ophilips
Copy link
Author

ophilips commented Jun 30, 2020

Hey @WLines84, by using your code (which is just the home assistant standard config) you only have access to the on/off switch in Apple Home. It is a new feature since version 0.110 https://www.home-assistant.io/blog/2020/05/20/release-110/#homekit
If you want to have more features like vacuum speed, zones etc. it is still necessary to add some more code to your config.

@cobch
Copy link

cobch commented Nov 29, 2021

Hi @ophilips

Long time ago (-:
I wonder if you have updated the code since the fan.speed service seems not to be working anymore. It would be nice to share a new code if you can.
Thanks

@TerrorSource
Copy link

Doesnt work anymore.

Deprecated services: fan.set_speed
source: https://www.home-assistant.io/integrations/fan/

Does anyone have a working config for Homekit with latest HA versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment