Open jleinenbach opened 3 months ago
Thanks for sharing your example! In this way, it would be more flexible if you have multiple calendars.
Here's another one.
Features:
- 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
@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
Thank your for your great integration. I use the following code as a replacement for the calendar events example: