Skip to content

Instantly share code, notes, and snippets.

@allenporter
Created September 24, 2023 22:46
Show Gist options
  • Save allenporter/1e958e86c659cf876ee53801db3beaed to your computer and use it in GitHub Desktop.
Save allenporter/1e958e86c659cf876ee53801db3beaed to your computer and use it in GitHub Desktop.
Old calendar location
- id: '1688397301915'
alias: Upcoming Calendar Event Locations
description: Update the upcoming location helpers based on the next upcoming event.
trigger:
- platform: time
at: 06:00:00
- platform: time
at: '12:00:00'
- platform: time
at: '18:00:00'
- platform: time
at: '22:00:00'
action:
- service: calendar.list_events
target:
entity_id: calendar.personal
data:
duration:
hours: 168
minutes: 0
seconds: 0
response_variable: agenda
- alias: Find upcoming locations with events
variables:
location_events: '{{ agenda.events | rejectattr(''location'', ''undefined'')
| list }}'
- alias: Determine if there are any upcoming location events
if:
- condition: template
value_template: '{{ location_events | length > 0 }}'
then:
- variables:
event: '{{ location_events | first }}'
- service: input_text.set_value
alias: Set upcoming event name
data:
value: '{{ event.summary }}'
target:
entity_id: input_text.upcoming_event_name
- service: input_text.set_value
alias: Set upcoming location
data:
value: '{{ event.location }}'
target:
entity_id: input_text.upcoming_event_location
- service: input_datetime.set_datetime
alias: Set upcoming location time
data:
datetime: '{{ event.start }}'
target:
entity_id: input_datetime.upcoming_event_start
else:
- service: input_text.set_value
alias: Clear upcoming location
data:
value: ''
target:
entity_id:
- input_text.upcoming_event_name
- input_text.upcoming_event_location
- service: input_datetime.set_datetime
alias: Clear upcoming location time
data:
datetime: '2023-01-01 00:00:00'
target:
entity_id: input_datetime.upcoming_event_start
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment