Hi!
Have just started using home assistant, mainly so I can expose and integrate all my devices to HomeKit. I have been looking online for a solution to exposing my roborock s7 to HomeKit, however all the results I found were using Homebridge to expose it as a fan and I don’t want to set up homebridge just for this use. I also couldn’t find any updated topics on home assistant about this (taking advantage of preset modes particularly) so here’s my hacky code i made for this. I know it’s very possible to make this more efficient, however this is my first time making a template. (Also first post here).
Also, I haven’t included speed at all in this as I have configured custom speeds and suction for each room using the mi home app.
#configuration.yaml
#for tracking preset mode
input_select:
roborock_s7_preset_mode:
name: "Roborock preset mode"
options:
- "no bedroom clean"
- "full clean"
- "cleaning kitchen"
- "cleaning x room"
fan:
-platform: template
fans:
roborock_s7:
friendly_name: "Ron Sweepsley"
value_template: "{%if states('vacuum.robovac') == 'cleaning' %}on{%elif states('vacuum.robovac') == 'paused' %}on{%else %}off{% endif %}"
preset_mode_template: "{{ states('input_select.roborock_s7_preset_mode') }}"
# turn_on and turn_off both dock vacuum as turn_on would activate when disabling a preset.
turn_on:
service: vacuum.return_to_base
data: {}
target:
device_id: device id
turn_off:
service: vacuum.return_to_base
data: {}
target:
device_id: device id
# calls a script to process a different cleaning command depending on preset mode
set_preset_mode:
service: script.roborock_clean
data:
preset_mode: "{{ preset_mode }}"
preset_modes:
- "no bedroom clean"
- "full clean"
- "cleaning kitchen"
- "cleaning x bedroom"
And then below is the scipt.roborock_clean that is called when activating a preset mode. This was made in visual editor, probably can also be more efficient.
sequence:
- service: input_select.select_option
target:
entity_id: input_select.roborock_s7_preset_mode
data:
option: '{{ preset_mode }}'
- choose:
- conditions:
- condition: state
entity_id: input_select.roborock_s7_preset_mode
state: no bedroom clean
sequence:
- service: xiaomi_miio.vacuum_clean_segment
target:
device_id: deviceid
data:
segments:
- 16
- 21
- 23
- 24
- 25
- conditions:
- condition: state
entity_id: input_select.roborock_s7_preset_mode
state: full clean
sequence:
- service: vacuum.start
target:
device_id: deviceid
data: {}
- conditions:
- condition: state
entity_id: input_select.roborock_s7_preset_mode
state: cleaning kitchen
sequence:
- service: xiaomi_miio.vacuum_clean_segment
data:
segments: 24
target:
device_id: deviceid
# below is for a specific bedroom
- conditions:
- condition: state
entity_id: input_select.roborock_s7_preset_mode
state: cleaning x bedroom
sequence:
- service: xiaomi_miio.vacuum_clean_segment
data:
segments: 17
target:
device_id: deviceid
default: []
- service: fan.set_preset_mode
data: 'null'
target:
entity_id: fan.roborock_s7
mode: queued
alias: Roborock Clean
max: 10
Anyway, I hope this helps someone who’s trying to do what i did. Any suggestions to improve this are welcome .