Xiaomi Roborock vacuum as fan in HomeKit

I need some help with a template for my Xiaomi Roborock vacuum. To be able to implement as many functions as possible, and with the fact that HomeKit do not have support for vacuum cleaners in mind, I have tried to write a fan template.

As of now, it starts and stops (goes back to the dock) when I start the fan in the Home app, but no more than that. And primarily, I would like to be able to set the speed with the HomeKit fan speed slider, and it would also be nice if the fan in the Home app stops when the vacuum itself has stopped cleaning.

Currently, when I change the fan’s slider in the Home app, I get the following error in Home Assistant. It is ofcourse a good hint, but I haven’t been able to write an action that does what I want, and haven’t found anyone else who has solved it. Can anyone help me write an action for set_speed, and has any ideas on how to make the fan stop when the vacuum stops?

"Received invalid speed: 75. Expected: ['Quiet', 'Balanced', 'Turbo', 'Max']."

My current configuration for the fan template.

fan:
  - platform: template
    fans:
      homekit_roborock:
        friendly_name: "Jean Claude"
        value_template: "{{ is_state('vacuum.roborock', 'on') }}"
        speed_template: "{{ states.vacuum.roborock.attributes.fan_speed }}"
        turn_on:
          service: vacuum.start
          entity_id: vacuum.roborock
        turn_off:
          service: vacuum.return_to_base
          entity_id: vacuum.roborock
        speeds:
          - "Quiet"
          - "Balanced"
          - "Turbo"
          - "Max"

i think those names are not working , like quiet, balanced, …

i ended up with numbers like 50, 75 , 100
example script, that i push to google assistant, so i can say like hey google , turbo mode on , or something like that

vacuum_fan_speed1:
  alias: Normal mode
  sequence:
  - service: vacuum.set_fan_speed
    data:
      entity_id: vacuum.roborock
      fan_speed: 75

not sure what you are also trying todo? so if you set the FAN on, you also want to start cleaning?
also , if the vacuum is stopping or docked? why you want the fan be stopped/off ?
i use google assistant, no idea how homekit works, but do you see somekind of fan spinning then?
if yes, you could make an automation, so if vacuum = docked, then stop fan … ?

Not really understanding either. I have been able to integrate following these instructions:

And am able to set fan speed:

I was working on a similar solution and got it running with this script that I also published on GitHub:
Xiaomi Vacuum as “template fan” for Home Assistant/HomeKit

# 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_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'
          - 'Quiet'
          - 'Balanced'
          - 'Turbo'
          - 'Max'
2 Likes

Thanks, @poliver, that did the trick!

Hello, with the new update and the breaking change regarding the fans, I have many errors in the log, is it possible to change this template for the new version?

Yes, it would be great…

I would be interested as well