Skip to content

Instantly share code, notes, and snippets.

@jbruening
Last active October 9, 2020 21:12
Show Gist options
  • Select an option

  • Save jbruening/69e9c9577286af5b3c298a221c17d9c3 to your computer and use it in GitHub Desktop.

Select an option

Save jbruening/69e9c9577286af5b3c298a221c17d9c3 to your computer and use it in GitHub Desktop.
vacuum named segment webhook
- id: '1591476042770'
alias: Vacuum web trigger
description: ''
trigger:
- platform: webhook
webhook_id: WEBHOOK SECRET ID GOES HERE
condition: []
action:
- service: python_script.vacuum_named_segment
data_template:
entity_id: vacuum.mr_clean
room_name: "{% if trigger is defined and trigger.json is defined and trigger.json.room_name\
\ is defined %}\n {{ trigger.json.room_name }}\n{% else %}\n {{ states('input_select.room_names')\
\ }}\n{% endif %}\n"
name_map:
bathroom: 16
study: 17
living: 18
living room: 18
hallway: 20
dining: 22
dining room: 22
kitchen: 23
"""
automation:
- alias: Light 15min Fade to 100% starting an hour before sunset
trigger:
platform: sun
event: sunset
offset: "-01:00:00"
action:
- service: python_script.vacuum_named_segment
data:
entity_id: vacuum.mr_clean
room_name: hallway
name_map:
"bathroom": 16
"""
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text # or whatever
entity_id = data.get('entity_id')
room_name = data.get('room_name')
room_map = data.get('name_map')
room_name = remove_prefix(room_name.strip(), 'the').strip()
room_id = room_map[room_name]
if room_id is not None:
service_data = {"entity_id": entity_id, "command": "app_segment_clean", "params": [room_id]}
hass.services.call("vacuum", "send_command", service_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment