Skip to content

Commit

Permalink
Vacuum specific room (#15)
Browse files Browse the repository at this point in the history
* Add python script
  • Loading branch information
oscarb authored Oct 18, 2020
1 parent 91057a6 commit 3e0b06d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
7 changes: 4 additions & 3 deletions automations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@
condition: []
action:
- alias: ''
entity_id: vacuum.robocop
data_template:
room_name: '{{ trigger.event.data.room }}'
service: script.vacuum_room
area: '{{ trigger.event.data.room }}'
service: python_script.vacuum_room
- id: '1577999538329'
alias: Send notification when Spotify playlist is updated
description: Sends a rich notification when a track has been added to a Spotify playlist, as detected by IFTTT
Expand Down Expand Up @@ -120,7 +121,7 @@
- data: {}
entity_id: group.office
service: light.turn_on
- id: '1585509334461'
- id: '1585509334462'
alias: Turn off office lights when PC turns off
description: ''
trigger:
Expand Down
5 changes: 4 additions & 1 deletion configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ homeassistant:

# Show links to resources in log and frontend
# introduction: false

# Enables the frontend
frontend:

Expand All @@ -28,6 +28,9 @@ config:
# Enables the mobile companion app
mobile_app:

# Enable python scripts
python_script:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:

Expand Down
10 changes: 10 additions & 0 deletions python_scripts/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# services.yaml
vacuum_room:
description: Vacuum specific room(s)
fields:
entity_id:
description: The vacuum to use for cleaning
example: vacuum.roborock
area:
description: A string of rooms to be selected for cleaning
example: "kitchen and the hallway"
26 changes: 26 additions & 0 deletions python_scripts/vacuum_room.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Vacuum a specific room

roomConfig = {
16: ["hallway"],
17: ["bedroom"],
18: ["entrance"],
19: ["kitchen"],
20: ["nursery", "kids room"],
22: ["living room"],
23: ["office"]
}

entity_id = data.get("entity_id")
area = data.get("area").lower()

roomsToClean = []

for roomNumber, roomNames in roomConfig.items():
for name in roomNames:
if name in area:
roomsToClean.append(int(roomNumber))
continue

if entity_id is not None and len(roomsToClean) > 0:
service_data = {"entity_id": entity_id, "command": "app_segment_clean", "params": roomsToClean}
hass.services.call("vacuum", "send_command", service_data, False)
22 changes: 0 additions & 22 deletions scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,6 @@ turn_computer_off:
ip: !secret computer_ip
timeout: 10

vacuum_room:
alias: Vacuum room
description: Start Roborock S6 room cleaning for a specific room
fields:
room_name:
description: Name of room to clean
example: kitchen
sequence:
- service: vacuum.send_command
data:
entity_id: vacuum.robocop
command: app_segment_clean
data_template:
params: >-
{% if 'kitchen' in room_name %}
[19]
{% elif 'living room' in room_name %}
[20]
{% else %}
[21]
{% endif %}
flic_button_lights_click:
alias: Flic button Lights click
sequence:
Expand Down

0 comments on commit 3e0b06d

Please sign in to comment.