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.
Thought I would come back to this, with two main updates:
remove the reliance on an input select list.
added ability to queue 1 room once cleaning has started.
First is the config.yaml part. The preset_mode_template does what I want it to do, however it doesn’t actually do it the way it’s written in code. I would like it do be indicative of the room it’s currently cleaning or queued to clean, but then reset to none or null when finished cleaning.
Somehow tho the error from this preset_mode_template means that preset mode is never changed, however can still be set, and therefore passed to the following script
#config
fan:
- platform: template
fans:
roborock_s7:
friendly_name: "Ron Sweepsley"
#value_template: shows status of vacuum
value_template: "{%if states('vacuum.robovac') == 'cleaning' %}on{%elif states('vacuum.robovac') == 'paused' %}on{%else %}off{% endif %}"
#prese_mode_template: this is the code I thought would make preset modes turn off when docked,
# however, it only works as is makes a specifically good error that resets the preset mode.. not quite sure how
preset_mode_template: "{%if states('vacuum.robovac') == 'docked' %}null{% else %}{{ this.preset_modes.roborock_s7 }}{% endif %}"
#return vacuum to base on turn on/off
turn_on:
service: vacuum.return_to_base
data: {}
target:
device_id: ____
turn_off:
service: vacuum.return_to_base
data: {}
target:
device_id: _____
# when preset mode set, calls script to start cleanings
set_preset_mode:
service: script.roborock_clean
data:
preset_mode: "{{ preset_mode }}"
# different preset modes for different rooms/zones
preset_modes:
- "room 1"
- "room 2"
- "room 3"
- "room 4"
- "room group 1"
- "room group 2"
- "room group 3"
- "full clean"
- "zone clean"
Here is the updated script as well, it is now run parallel, and can queue a room once cleaning has actually started. Also I have used template conditions here instead of the previous state conditions to remove reliance on the input_select.
Anyway as before if there are any templating geniuses who could get this running properly that would be awesome, I just haven’t found anything else that integrates a roborock into HomeKit with room control like this anywhere, so this is my wacky solution
Yeah nice work @poudenes , I have actually changed to be more similar to this. I’ve forgotten to update this thread for a while. I still use the script I shared here, however I don’t use the fan template thing at all. Instead I have just set up a bunch of different dummy switches that all trigger the script… I’ll try put it all together again to post sometime.
Out of curiosity @poudenes can you start multiple rooms at the same time and the vacuum will clean those rooms? Or will it only clean one?
Anyway, here is the script I currently use. There’s a few steps to set up… 1) you’ll have to make input_booleans in the helpers section of HA for each of your rooms 2) add them to the script by replacing “input_boolean.clean_room_x” for each occurrence in the script with your rooms 3) go through and change the segment numbers to be the appropriate room numbers for each room (there are better guides out there to determine these). 4) add the device ID for the vacuum in the appropriate spots 5) add the entity id for the vacuum in the appropriate spots 6) You can also add additional rooms as required by simply copying a choose condition with the condition of the input_boolean.
Benefit of this automation is that it allows you to flick as many rooms to clean as you want, and the vacuum should go through and clean each of them. Order is determined by either which is turned on first, and then by which is first in the CHOOSE action. Also I can skip/stop cleaning a room by turning it’s switch off
In homekit, I also set up scenes for Siri, so I can say “Hey Siri, ‘Start cleaning room 1’” in addition to the default “Hey Siri, ‘clean room 1’” which should work if your input_boolean is named “clean room 1”.
@xsas if your still interested in this and haven’t found a different solution, this should work for you better than the previous versions
alias: Roborock S7 All-in-one
description: ""
trigger:
- platform: state
entity_id: # rooms to set up as input_booleans
- input_boolean.clean_room_1
- input_boolean.clean_room_2
- input_boolean.clean_room_3
to: "on"
condition:
- condition: state
entity_id: # vacuum entity id
state:
- docked
- returning
action:
- repeat:
until:
- condition: state
entity_id: # vacuum entity id
state: docked
for:
hours: 0
minutes: 0
seconds: 0
sequence:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.clean_room_1
state: "on"
sequence:
- service: xiaomi_miio.vacuum_clean_segment
target:
device_id: # insert Device ID Here
data:
segments:
- # insert room number here
- wait_for_trigger:
- platform: state
entity_id:
- # vacuum entity id
to: returning
- platform: state
entity_id:
- input_boolean.clean_room_1
to: "off"
timeout:
hours: 2
minutes: 0
seconds: 0
milliseconds: 0
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.idx == '0' }}"
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.clean_room_1
- conditions:
- condition: template
value_template: "{{ wait.trigger.idx == '1' }}"
sequence:
- service: vacuum.return_to_base
data: {}
target:
entity_id: # vacuum entity id
default: []
- conditions:
- condition: state
entity_id: input_boolean.clean_room_2
state: "on"
sequence:
- service: xiaomi_miio.vacuum_clean_segment
data:
segments:
- # insert room number here
target:
device_id: # insert Device ID Here
- wait_for_trigger:
- platform: state
entity_id:
- # vacuum entity id
to: returning
- platform: state
entity_id:
- input_boolean.clean_room_2
to: "off"
timeout: "01:00:00"
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.idx == '0' }}"
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.clean_room_1
- conditions:
- condition: template
value_template: "{{ wait.trigger.idx == '1' }}"
sequence:
- service: vacuum.return_to_base
data: {}
target:
entity_id: # vacuum entity id
default: []
- conditions:
- condition: state
entity_id: input_boolean.clean_room_3
state: "on"
sequence:
- service: xiaomi_miio.vacuum_clean_segment
data:
segments:
- # insert room number here
target:
device_id: # insert Device ID Here
- wait_for_trigger:
- platform: state
entity_id:
- # vacuum entity id
to: returning
- platform: state
entity_id:
- input_boolean.clean_room_3
to: "off"
timeout: "01:00:00"
- choose:
- conditions:
- condition: template
value_template: "{{ wait.trigger.idx == '0' }}"
sequence:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.clean_room_1
- conditions:
- condition: template
value_template: "{{ wait.trigger.idx == '1' }}"
sequence:
- service: vacuum.return_to_base
data: {}
target:
entity_id: # vacuum entity id
default: []
default: []
mode: single
i tried using Home assistant recently for my roborock and i am not sure to tell you how it works, like i am not clear with the config , is it possible to simply add roborock to homekit using the MI Home app , as it supports siri on mi home app , 1. Select your Vacuum>Command Start Cleaning>Save>Add to Siri.
it works fine in home app but apple home , i am not sure of how to integrate it through this way -