Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andrew-codechimp/44689d6766e3e151dce1e9ae3d261730 to your computer and use it in GitHub Desktop.

Select an option

Save andrew-codechimp/44689d6766e3e151dce1e9ae3d261730 to your computer and use it in GitHub Desktop.
Octopus Free Electricity Calendar Events
alias: Octopus Energy New Free Energy Session
description: ""
triggers:
- event_type: octopus_energy_new_octoplus_free_electricity_session
trigger: event
conditions:
- condition: template
value_template: "{{ as_datetime(trigger.event.data.event_start) > now() }}"
alias: Is in the future
actions:
- action: script.add_unique_calendar_event
metadata: {}
data:
calendar: calendar.system
summary: Free electricity
start_time: "{{ as_datetime(trigger.event.data[\"event_start\"]) }}"
end_time: "{{ as_datetime(trigger.event.data[\"event_end\"]) }}"
mode: queued
max_exceeded: silent
max: 20
description: "Modify actions to your own needs"
mode: single
triggers:
- trigger: calendar
entity_id: calendar.system
event: start
offset: "-1:0:0"
id: starting_soon
- trigger: calendar
entity_id: calendar.system
event: start
offset: "0:0:0"
id: start
- trigger: calendar
entity_id: calendar.system
event: end
offset: "0:0:0"
id: end
conditions:
- condition: template
value_template: "{{ trigger.calendar_event.summary | lower == 'free electricity' }}"
actions:
- choose:
- conditions:
- condition: trigger
id:
- starting_soon
sequence:
- action: persistent_notification.create
metadata: {}
data:
message: Octopus free electricity session starting in one hour
- conditions:
- condition: trigger
id:
- start
sequence:
- action: persistent_notification.create
metadata: {}
data:
message: Octopus free electricity session started
- conditions:
- condition: trigger
id:
- end
sequence:
- action: persistent_notification.create
metadata: {}
data:
message: Octopus free electricity session has ended
alias: Add unique calendar event
mode: single
icon: mdi:clipboard-list
sequence:
- action: calendar.get_events
target:
entity_id: "{{ calendar }}"
data:
start_date_time: "{{ start_time }}"
end_date_time: "{{ end_time }}"
response_variable: calendar_events
- if:
- condition: template
value_template: >-
{{
calendar_events[calendar]['events']|selectattr('summary','search',summary)|list|count
== 0 }}
then:
- action: calendar.create_event
data:
summary: "{{ summary }}"
start_date_time: "{{ start_time }}"
end_date_time: "{{ end_time }}"
target:
entity_id: "{{ calendar }}"
fields:
calendar:
selector:
entity:
filter:
- domain: calendar
name: Calendar
required: true
description: The calendar
summary:
selector:
text: null
name: Summary
description: The summary of the event
required: true
start_time:
selector:
datetime: {}
name: Start time
required: true
end_time:
selector:
datetime: {}
name: End time
required: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment