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
|
||||
alias: Roborock Smart Cleaning
|
||||
mode: single
|
||||
- id: track_house_empty_time
|
||||
alias: Track House Empty Time
|
||||
mode: restart
|
||||
|
||||
trigger:
|
||||
- id: house_empty
|
||||
platform: state
|
||||
- platform: state
|
||||
entity_id: binary_sensor.family_presence
|
||||
to: "off"
|
||||
for: "00:30:00"
|
||||
|
||||
- id: someone_home
|
||||
platform: state
|
||||
entity_id: binary_sensor.family_presence
|
||||
to: "on"
|
||||
condition:
|
||||
- condition: template
|
||||
value_template: "{{ trigger.from_state.state != 'unavailable' }}"
|
||||
|
||||
- id: midnight
|
||||
platform: time
|
||||
action:
|
||||
- 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"
|
||||
|
||||
action:
|
||||
- choose:
|
||||
|
||||
# 🔹 Reset daglig tæller ved midnat
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id: midnight
|
||||
sequence:
|
||||
- service: input_number.set_value
|
||||
target:
|
||||
entity_id: input_number.roborock_auto_runs_today
|
||||
data:
|
||||
value: 0
|
||||
|
||||
# 🔹 Start rengøring hvis huset har været tomt i 30 min
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id: house_empty
|
||||
- id: roborock_smart_cleaning_start
|
||||
alias: Roborock Smart Cleaning Start
|
||||
mode: single
|
||||
|
||||
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
|
||||
entity_id: input_number.roborock_auto_runs_today
|
||||
below: 2
|
||||
|
||||
- condition: state
|
||||
entity_id: vacuum.roborock_s8_pro_ultra
|
||||
state: docked
|
||||
# Støvsuger klar (robust state check)
|
||||
- condition: template
|
||||
value_template: >
|
||||
{{ states('vacuum.roborock_s8_pro_ultra') in ['docked','idle','charging'] }}
|
||||
|
||||
# Batteri OK
|
||||
- condition: numeric_state
|
||||
entity_id: vacuum.roborock_s8_pro_ultra
|
||||
attribute: battery_level
|
||||
above: 20
|
||||
|
||||
action:
|
||||
- alias: "Start cleaning (retry op til 3 gange)"
|
||||
repeat:
|
||||
count: 3
|
||||
sequence:
|
||||
- service: button.press
|
||||
target:
|
||||
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
|
||||
target:
|
||||
entity_id: input_number.roborock_auto_runs_today
|
||||
|
||||
# 🔹 Stop robotten hvis nogen kommer hjem
|
||||
- conditions:
|
||||
- condition: trigger
|
||||
id: someone_home
|
||||
- id: roborock_stop_when_home
|
||||
alias: Roborock Stop When Someone Comes Home
|
||||
mode: restart
|
||||
|
||||
trigger:
|
||||
- platform: state
|
||||
entity_id: binary_sensor.family_presence
|
||||
to: "on"
|
||||
|
||||
condition:
|
||||
- condition: state
|
||||
entity_id: vacuum.roborock_s8_pro_ultra
|
||||
state: cleaning
|
||||
state: "cleaning"
|
||||
|
||||
sequence:
|
||||
action:
|
||||
- service: vacuum.return_to_base
|
||||
target:
|
||||
entity_id: vacuum.roborock_s8_pro_ultra
|
||||
|
||||
Reference in New Issue
Block a user