-
-
Save ophilips/116a2cda6d4e10825826af9640a92199 to your computer and use it in GitHub Desktop.
# 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 |
Hey @lasry1, you have to copy the code above to your home assistant configuration.yaml
file. The vacuum itself should already be configured in home assistant.
@slwl, I think the vacuum integration is already well documented at the home assistant website. I had that code in an earlier version but decided to leave it out for better readability.
thanks a lot! i did it however can't see the presets on homekit but at least i can control it! thanks again
The fan slider (0-100) in HomeKit will be translated to the the corresponding vacuum presets or speeds (off, Quiet, Balanced, Turbo, Max). HomeKit doesn’t support steps or drop down menus. If you are interested how the values are calculated check the fan section here: https://www.home-assistant.io/components/homekit/#supported-components
How can I locate the vacuum? or show battery level? With your code, all the other stuff worked but wanted to see if it was possible to show battery level and locate.
Hey @lvdfrnt, Thanks for your suggestions. It could be possible to create a dummy sensor and connect it using linked_battery_sensor
within the homekit:
configuration. I will check that later when I will be back at home.
@lvdfrnt, I got the battery sensor running and updated the config, but you have to reset the device in your homekit:
section. To reset your device you have to insert
filter:
exclude_entities:
- fan.xiaomi_fan
in your homekit:
config and restart home assistant so that it gets shown as a new device. After that you have to delete the filter.
You'll then find the battery status by clicking on the device settings symbol:
@lvdfrnt, I got the battery sensor running and updated the config, but you have to reset the device in your
homekit:
section. To reset your device you have to insertfilter: exclude_entities: - fan.xiaomi_fan
in your
homekit:
config and restart home assistant so that it gets shown as a new device. After that you have to delete the filter.You'll then find the battery status by clicking on the device settings symbol:
Finally got around to doing it and works flawlessly! thank you so much man. The instructions definitely helped!
Hello, is it possible to configurate more than one cleaner?
Hey @ThomasBoettner, You just have to use different names for each vacuum, fan and sensor like xiaomi_fan_01
instead of xiaomi_fan
. You could also use one cleaner and configure zones so that every room has its own virtual vacuum.
@ophilips Great work! Do you know if I can integrate Zones into the templates? I would like to get a vacuum for differents zones of my flats... I use homebridge for that but I will rather use Home assitant instead directly which will help to get a fre raspberry Pi to use for something else (-:
Hey @cobch, thanks for your great feedback; I will check how to configure zones in the next days. In theory it should work but it may be necessary to add "dummy" vacuums.
@ophilips I will be happy to test it. Keep in touch!
@ophilips Any news about the test with zones?
Hey @cobch, I had to generate all the coordinates for my rooms in the last days but zoned cleaning should work now by changing the code to:
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]]
You can add as many zones into the array as you like. If you want to have one vacuum for each room you just have to copy the whole config within fans:
like xiaomi_fan_01:
,xiaomi_fan_02:
etc. but with different names. One thing you should also change are the speed presets as the names changed in one of the last home assistant updates:
speeds:
- 'off'
- 'Silent'
- 'Standard'
- 'Medium'
- 'Turbo'
I hope that you can get it running with this "preview".
Hey @ophilips,
I have tested the zones configuration and the config above is working great. To make the mopping function of the S5 working I had to change the fan speed according to the following:
- 'Gentle'
- 'Silent'
- 'Standard'
- 'Medium'
- 'Turbo'
What I do not managed to make working is:
- the "battery status" is always set to 0% even after resetting the device as you mentioned above.
- Charging is always showing "No"
Any tips that will help me?
Further ideas: A play/pause function and a sensor to know whether the vacuum is docked or not. See picture below:
@cobch, About the battery status: Do you get a reading for your battery sensor in home assistant if you add the new sensor entity?
I just checked the home assistant documentation about your speed settings. You should always add an off
value to your list. Check this link and search for fan: https://www.home-assistant.io/integrations/homekit/
So you should change your list to the following when using the S5:
speeds:
- 'off'
- 'Silent'
- 'Standard'
- 'Medium'
- 'Turbo'
- 'Gentle'
@cobch. I tested it with a pause function before but it is extremely difficult to control because there are so many different resume modes. Resume going back to dock, resume cleaning, etc.
@ophilips I find a mistake in my code in the battery section. The battery sensor is working now (-: The charging is nevertheless still always to "No".
Could you send the code for the pause that I try?
@ophilips I find a mistake in my code in the battery section. The battery sensor is working now (-: The charging is nevertheless still always to "No".
The charging status is not supported at the moment in home assistant. It just gets added when a battery value is linked to your device. So i couldn‘t use that feature.
I will check the pause function again because there were so many changes in the xiaomi integration like the speed settings.
Ok, thanks and keep in touch!
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'
speeds:
- 'off'
- 'Silent'
- 'Standard'
- 'Medium'
- 'Turbo'
- 'Gentle'
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:
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.
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
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?
i don't undestand this, where do i place the "xiaomi_fan_configuration.yaml" file?