feat(roborock): make smart cleaning automation robust and deterministic
- Replace fragile `for:` trigger with timestamp-based empty-house logic - Add input_datetime to track when house became empty - Introduce time_pattern polling (every 5 min) to avoid missed triggers - Add retry mechanism (up to 3 attempts) for starting cleaning - Improve vacuum state handling (docked/idle/charging) - Add race-safe stop automation when someone returns home - Split logic into dedicated automations (tracking, reset, start, stop) - Ensure daily run limit via input_number Fixes issue where cleaning was not triggered due to presence sensor flapping/unavailable states.
This commit is contained in:
@@ -1,74 +1,107 @@
|
|||||||
- id: roborock_smart_cleaning
|
- id: track_house_empty_time
|
||||||
alias: Roborock Smart Cleaning
|
alias: Track House Empty Time
|
||||||
mode: single
|
mode: restart
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
- id: house_empty
|
- platform: state
|
||||||
platform: state
|
|
||||||
entity_id: binary_sensor.family_presence
|
entity_id: binary_sensor.family_presence
|
||||||
to: "off"
|
to: "off"
|
||||||
for: "00:30:00"
|
|
||||||
|
|
||||||
- id: someone_home
|
condition:
|
||||||
platform: state
|
- condition: template
|
||||||
entity_id: binary_sensor.family_presence
|
value_template: "{{ trigger.from_state.state != 'unavailable' }}"
|
||||||
to: "on"
|
|
||||||
|
|
||||||
- id: midnight
|
action:
|
||||||
platform: time
|
- service: input_datetime.set_datetime
|
||||||
|
target:
|
||||||
|
entity_id: input_datetime.house_became_empty
|
||||||
|
data:
|
||||||
|
timestamp: "{{ now().timestamp() }}"
|
||||||
|
|
||||||
|
- id: roborock_reset_daily_counter
|
||||||
|
alias: Roborock Reset Daily Counter
|
||||||
|
trigger:
|
||||||
|
- platform: time
|
||||||
at: "00:00:00"
|
at: "00:00:00"
|
||||||
|
|
||||||
action:
|
action:
|
||||||
- choose:
|
|
||||||
|
|
||||||
# 🔹 Reset daglig tæller ved midnat
|
|
||||||
- conditions:
|
|
||||||
- condition: trigger
|
|
||||||
id: midnight
|
|
||||||
sequence:
|
|
||||||
- service: input_number.set_value
|
- service: input_number.set_value
|
||||||
target:
|
target:
|
||||||
entity_id: input_number.roborock_auto_runs_today
|
entity_id: input_number.roborock_auto_runs_today
|
||||||
data:
|
data:
|
||||||
value: 0
|
value: 0
|
||||||
|
|
||||||
# 🔹 Start rengøring hvis huset har været tomt i 30 min
|
- id: roborock_smart_cleaning_start
|
||||||
- conditions:
|
alias: Roborock Smart Cleaning Start
|
||||||
- condition: trigger
|
mode: single
|
||||||
id: house_empty
|
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
# Tjek løbende mens huset er tomt
|
||||||
|
- platform: time_pattern
|
||||||
|
minutes: "/5"
|
||||||
|
|
||||||
|
condition:
|
||||||
|
# Huset er tomt
|
||||||
|
- condition: state
|
||||||
|
entity_id: binary_sensor.family_presence
|
||||||
|
state: "off"
|
||||||
|
|
||||||
|
# Har været tomt i 30 min (robust)
|
||||||
|
- condition: template
|
||||||
|
value_template: >
|
||||||
|
{{ states('input_datetime.house_became_empty') not in ['unknown','unavailable',''] and
|
||||||
|
(as_timestamp(now()) - as_timestamp(states('input_datetime.house_became_empty'))) > 1800 }}
|
||||||
|
|
||||||
|
# Max 2 gange dagligt
|
||||||
- condition: numeric_state
|
- condition: numeric_state
|
||||||
entity_id: input_number.roborock_auto_runs_today
|
entity_id: input_number.roborock_auto_runs_today
|
||||||
below: 2
|
below: 2
|
||||||
|
|
||||||
- condition: state
|
# Støvsuger klar (robust state check)
|
||||||
entity_id: vacuum.roborock_s8_pro_ultra
|
- condition: template
|
||||||
state: docked
|
value_template: >
|
||||||
|
{{ states('vacuum.roborock_s8_pro_ultra') in ['docked','idle','charging'] }}
|
||||||
|
|
||||||
|
# Batteri OK
|
||||||
- condition: numeric_state
|
- condition: numeric_state
|
||||||
entity_id: vacuum.roborock_s8_pro_ultra
|
entity_id: vacuum.roborock_s8_pro_ultra
|
||||||
attribute: battery_level
|
attribute: battery_level
|
||||||
above: 20
|
above: 20
|
||||||
|
|
||||||
|
action:
|
||||||
|
- alias: "Start cleaning (retry op til 3 gange)"
|
||||||
|
repeat:
|
||||||
|
count: 3
|
||||||
sequence:
|
sequence:
|
||||||
- service: button.press
|
- service: button.press
|
||||||
target:
|
target:
|
||||||
entity_id: button.roborock_s8_pro_ultra_kokken_bryggers
|
entity_id: button.roborock_s8_pro_ultra_kokken_bryggers
|
||||||
|
|
||||||
|
- delay: "00:00:20"
|
||||||
|
|
||||||
|
- condition: state
|
||||||
|
entity_id: vacuum.roborock_s8_pro_ultra
|
||||||
|
state: "cleaning"
|
||||||
|
|
||||||
- service: input_number.increment
|
- service: input_number.increment
|
||||||
target:
|
target:
|
||||||
entity_id: input_number.roborock_auto_runs_today
|
entity_id: input_number.roborock_auto_runs_today
|
||||||
|
|
||||||
# 🔹 Stop robotten hvis nogen kommer hjem
|
- id: roborock_stop_when_home
|
||||||
- conditions:
|
alias: Roborock Stop When Someone Comes Home
|
||||||
- condition: trigger
|
mode: restart
|
||||||
id: someone_home
|
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
- platform: state
|
||||||
|
entity_id: binary_sensor.family_presence
|
||||||
|
to: "on"
|
||||||
|
|
||||||
|
condition:
|
||||||
- condition: state
|
- condition: state
|
||||||
entity_id: vacuum.roborock_s8_pro_ultra
|
entity_id: vacuum.roborock_s8_pro_ultra
|
||||||
state: cleaning
|
state: "cleaning"
|
||||||
|
|
||||||
sequence:
|
action:
|
||||||
- service: vacuum.return_to_base
|
- service: vacuum.return_to_base
|
||||||
target:
|
target:
|
||||||
entity_id: vacuum.roborock_s8_pro_ultra
|
entity_id: vacuum.roborock_s8_pro_ultra
|
||||||
|
|||||||
Reference in New Issue
Block a user