Deprecated Calendar Example
jleinenbach opened this issue · comments
Jens Leinenbach commented
Thank your for your great integration.
I use the following code as a replacement for the calendar events example:
- calendar.list_events is deprecated.
- There is no need to limit to a special calendar, just let it choose from all visible calendars.
- FYI: This does not work with the ical Sensor integration as integrated calendars don't have a unique id.
- spec:
name: get_events
description: Use this function to get list of calendar events.
parameters:
type: object
properties:
entity_id:
type: string
description: The entity ID of the calendar
start_date_time:
type: string
description: The start date time in '%Y-%m-%dT%H:%M:%S%z' format
end_date_time:
type: string
description: The end date time in '%Y-%m-%dT%H:%M:%S%z' format
required:
- entity_id
- start_date_time
- end_date_time
function:
type: script
sequence:
- service: calendar.get_events
data:
start_date_time: "{{start_date_time}}"
end_date_time: "{{end_date_time}}"
target:
entity_id: "{{entity_id}}"
response_variable: _function_result
Min Jekal commented
Thanks for sharing your example!
In this way, it would be more flexible if you have multiple calendars.
Jens Leinenbach commented
Here's another one.
Features:
- multiple calenders
- multiple calenders at once with label_id
- using anyOf and oneOf (I have no idea if this is documented somewhere)
- more error handling
- spec:
name: get_events
description: Use this function to get a list of calendar events.
parameters:
type: object
properties:
target:
type: object
anyOf:
- properties:
entity_id:
type: string
description: The entity_id of the calendar. label_id or entity_id required.
required:
- entity_id
- properties:
label_id:
type: string
description: The label_id of calendars. label_id or entity_id required.
required:
- label_id
start_date_time:
type: string
description: The start date time in '%Y-%m-%dT%H:%M:%S%z' format.
final_time:
type: object
oneOf:
- properties:
end_date_time:
type: string
description: The end date time in '%Y-%m-%dT%H:%M:%S%z' format.
required:
- end_date_time
- properties:
duration:
type: object
description: Return active events from start_date_time until the specified duration. Expressed as a dictionary with days, hours, or minutes.
required:
- duration
required:
- start_date_time
- final_time
- target
function:
type: composite
sequence:
- type: script
sequence:
- variables:
target_data: >
{% set data = {} %}
{% if target.entity_id is defined and 'entity_id' in target and target.entity_id.split('.')[0] == 'calendar' %}
{% set data = dict(data, **{'entity_id': target.entity_id}) %}
{% endif %}
{% if target.label_id|default('') in labels() %}
{% set data = dict(data, **{'label_id': target.label_id}) %}
{% endif %}
{{ data | tojson }}
event_data: >
{% set data = {} %}
{% set data = dict(data, **{'start_date_time': start_date_time}) %}
{% if 'end_date_time' in final_time and final_time.end_date_time %}
{% set data = dict(data, **{'end_date_time': (final_time.end_date_time | default(none))}) %}
{% elif 'duration' in final_time and final_time.duration %}
{% set data = dict(data, **{'duration': (final_time.duration | default(none))}) %}
{% endif %}
{{ data | tojson }}
data_filled: >
{% set target_dict = (target_data | from_json) if target_data is string else target_data %}
{% set event_dict = (event_data | from_json) if event_data is string else event_data %}
{{ target_dict | length > 0 and event_dict | length > 0 }}
- condition: template
value_template: "{{ data_filled }}"
- service: calendar.get_events
data: "{{ event_data }}"
target: "{{ target_data }}"
response_variable: _function_result
Jens Leinenbach commented
@jekalmin
I just realized that you already fixed it in the example file, but it's still the deprecated service in the README file.
https://github.com/jekalmin/extended_openai_conversation/blob/main/README.md