I am playing around with the new calendar.list_events service call. I have the below script and its running without issue. I am wondering how to view the contents of the response_variable “Rockies”. Ultimately I would like to email this on a weekly basis.
service: calendar.list_events
data:
start_date_time: "2022-03-22T20:00:00.000Z"
end_date_time: "2022-03-22T22:00:00.000Z"
target:
entity_id: calendar.colorado_rockies_schedule
response_variable: Rockies
123
(Taras)
July 6, 2023, 4:39pm
2
From this section of the Calendar documentation :
- service: calendar.list_events
target:
entity_id: calendar.school
data:
duration:
hours: 24
response_variable: agenda
- service: notify.gmail_com
data:
target: [email protected]
title: Daily agenda for {{ now().date() }}
message: >-
Your agenda for today:
<p>
{% for event in agenda.events %}
{{ event.start}}: {{ event.summary }}<br>
{% endfor %}
</p>
Don’t forget that you have to reference the response_variable in the same script that creates it.
1 Like
The issue I was having is that the date was set to the past. When I change the date to from today to the future it worked. Thanks for the help.
It is not working with new (beta) calendar.get_events call service.
Response of the service is nested inside name of calendar.
What is the correct path in the object now?
123
(Taras)
November 30, 2023, 3:40pm
5
I don’t know.
I’m not testing the beta version and the beta documentation doesn’t yet contain a description of the new service call.
I suggest you wait until the documentation is available or ask its author. Here’s the Pull Request:
home-assistant:dev
← eifinger:migrate_calendar_service_calls
opened 05:55PM - 21 Oct 23 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Breaking change
<!--
If your PR contains a breaking change for existing users, it is important
to tell them what breaks, how to make it work again and why we did this.
This piece of text is published with the release notes, so it helps if you
write it towards our users, not us.
Note: Remove this section if this PR is NOT a breaking change.
-->
`calendar.list_events` uses an outdated response data format It is deprecated and will be removed in 2024.6.
Please use `calendar.get_events` which supports multiple entities instead.
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
As discussed in https://github.com/home-assistant/architecture/discussions/948.
Deprecates `calendar.list_events` and introduces new service `calendar.get_events` with the new response format instead.
Depends on: #96370
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [x] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] I have followed the [perfect PR recommendations][perfect-pr]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr
According to the beta release notes , the existing service call, calendar.list_events
, will be deprecated and won’t be removed until version 2024.6.0.
1 Like
Olivier1974
(Olivier Toussaint)
December 2, 2023, 11:49am
6
If you don’t know the name of the calendar, you can surround the for loop like so
{% for key, value in agenda.items() %}
{% for event in value.events %}
...
{% endfor %}
{% endfor %}
If you know the name, then it is easier
{% for event in agenda['calendar.school'].events %}
...
{% endfor %}
2 Likes
johntdyer
(John Dyer)
December 6, 2023, 1:56pm
7
but how do you test this in the developer tools ? Can you call a service into a variable like you can w/ the template resource?
The following worked for me w/ list_events
but switching to get_events
returns a nested response that I am unsure how to test in something like developer tools… any help would be appreciated
template:
- trigger:
- platform: event
event_type: household_events
sensor:
- name: Household events
unique_id: household_events
state: "{{ trigger.event.data.scheduled_events.events | count() }}"
attributes:
scheduled_events: "{{ trigger.event.data.scheduled_events }}"
icon: mdi:calendar
- trigger:
- platform: time_pattern
minutes: /1
action:
- service: calendar.list_events
data:
duration:
hours: 120
minutes: 0
seconds: 0
start_date_time: "{{ today_at() }}"
target:
entity_id: calendar.google_household
response_variable: scheduled_events
sensor:
- name: Calendar Scheduled Events
unique_id: calendar_scheduled_events
state: "{{ scheduled_events.events | count() }}"
attributes:
scheduled_events: "{{ scheduled_events.events }}"
icon: mdi:calendar'
broyuken1
(Broyuken)
December 6, 2023, 6:42pm
9
Olivier1974:
['calendar.school']
THANK YOU! I couldn’t figure it out after the beta change but that worked perfectly! My script is now back to working.
1 Like
johntdyer
(John Dyer)
December 6, 2023, 7:49pm
10
Thank you I appreciate the answer ! Any plans to eliminate the yaml to json step in the template tool? just thinking it might nice to be able to call a service and assign the output to a variable within the tool… thoughts? crazy talk?
1 Like
petro
(Petro)
December 6, 2023, 7:53pm
11
2023.12 added a copy button… but it’s yaml, so the steps remain the same.
1 Like
plaxtika
(Plaxtika)
December 14, 2023, 6:51pm
12
When I add this to output for a notification it works - if i use it for TTS it doesn’t work ? (with calendar.get_events)
message: |-
eingetragene Termine für heute:
{% for event in agenda['calendar.xxx'].events %}
{{ event.summary }}
{% endfor %}