Last active
March 6, 2024 15:21
-
-
Save Didgeridrew/edc1085c241459ed67dd7e4d64d400cc to your computer and use it in GitHub Desktop.
HA - A Trigger-based Template sensor extracting events from multiple calendars and sorting them by start
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
| template: | |
| - trigger: | |
| - platform: calendar | |
| event: start | |
| entity_id: calendar.a | |
| - platform: calendar | |
| event: start | |
| entity_id: calendar.b | |
| - platform: calendar | |
| event: end | |
| entity_id: calendar.a | |
| - platform: calendar | |
| event: end | |
| entity_id: calendar.b | |
| action: | |
| - service: calendar.get_events | |
| data: | |
| duration: | |
| hours: 72 | |
| target: | |
| entity_id: | |
| - calendar.a | |
| - calendar.b | |
| response_variable: calendars | |
| - variables: | |
| e: | | |
| {% set ns = namespace(cal_events=[]) %} | |
| {%- for key, value in calendars.items() %} | |
| {%- for event in value.events %} | |
| {%- set ns.cal_events = ns.cal_events + [event] %} | |
| {%- endfor %} | |
| {%- endfor %} | |
| {{ ns.cal_events | sort(attribute='start') | list }} | |
| sensor: | |
| - name: MultiCal 72 hour agenda | |
| state: "{{ e | count }}" | |
| attributes: | |
| events: "{{e}}" | |
| entity_id: | | |
| {{['calendar.a','calendar.b']}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please take a look because I did something wrong: