Last active
August 3, 2023 14:21
-
-
Save bruxy70/ea10d440117abe90009769268effe90c to your computer and use it in GitHub Desktop.
Check a local calendar for events (in the next 365 days) colliding with a public holiday. Create a persistent notification with the list of colliding holidays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Create Calendar Events with Offset Holidays in Week | |
description: >- | |
Check a local calendar for events (in the next 365 days) colliding | |
with a public holiday. Create a persistent notification | |
with the list of colliding holidays. | |
domain: script | |
source_url: https://gist.github.com/bruxy70/ea10d440117abe90009769268effe90c | |
fields: | |
source_calendar: | |
name: Source calendar | |
description: Calendar with the events to be copied from | |
required: true | |
selector: | |
entity: | |
filter: | |
integration: local_calendar | |
public_holidays: | |
name: Public Holidays | |
description: Calendar with the public holidays to be avoided | |
required: true | |
selector: | |
entity: | |
filter: | |
integration: holidays | |
sequence: | |
- service: calendar.list_events | |
data: | |
duration: | |
days: 365 | |
target: | |
entity_id: "{{ source_calendar }}" | |
response_variable: source | |
- service: calendar.list_events | |
data: | |
duration: | |
days: 365 | |
target: | |
entity_id: "{{ public_holidays }}" | |
response_variable: holidays | |
- variables: | |
holiday_dates: |- | |
{%- set ns = namespace(dates={}) %} | |
{%- if holidays.events %} | |
{%- for event in holidays.events %} | |
{%- set ns.dates = dict(ns.dates, **{event.start:event.summary}) %} | |
{%- endfor %} | |
{%- endif %} | |
{{ ns.dates }} | |
- service: persistent_notification.create | |
data: | |
title: Calendar collisions | |
message: |- | |
{%- set ns = namespace(collisions=[]) %} | |
{%- if source.events %} | |
{%- for event in source.events %} | |
{%- if event.start in holiday_dates %} | |
{%- set collision = event.start + " (" + holiday_dates[event.start] + ")" %} | |
{%- set ns.collisions = ns.collisions + [ collision ] %} | |
{%- endif %} | |
{%- endfor %} | |
{%- endif %} | |
{%- if ns.collisions == [] %} | |
No collisions | |
{%- else %} | |
{{ ns.collisions }} | |
{%- endif %} | |
mode: single | |
icon: mdi:calendar-alert-outline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment