Daft
(Bram Diederik)
April 24, 2024, 8:37pm
1
Heya. I having fun with voice automations.
Here is my latest easy to share automation.
calendar query.
just ask calendar today/tomorrow or day of week and home assistant will respond with the items of that day ordered in time.
it queries the calendar
NOTE i have edited this automation to english with a editor my running system is dutch so i did not test the pasted version.
alias: voice agenda
description: ""
trigger:
- platform: conversation
command:
- agenda {day}
- calendar {day}
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.slots.day == \"today\" }}"
sequence:
- service: calendar.get_events
data:
start_date_time: "{{ now().strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ now().strftime('%Y-%m-%d 23:59:59') }}"
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- conditions:
- condition: template
value_template: "{{ trigger.slots.day == \"tomorrow\" }}"
sequence:
- service: calendar.get_events
data:
start_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 23:59:59') }}"
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
default:
- service: calendar.get_events
data:
start_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0,
microsecond=0) %}
{% set target_day = trigger.slots.day %}
{% set days_to_target = (7 + ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'].index(target_day.lower()) - today.weekday()) % 7 %}
{% set next_target_day = today + timedelta(days=days_to_target) %}
{{ next_target_day.strftime('%Y-%m-%d 00:00:00) }}
end_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0,
microsecond=0) %} {% set target_day = trigger.slots.dag %}
{% set days_to_target = (7 + ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'].index(target_day.lower()) - today.weekday()) % 7 %}
{% set next_target_day = today + timedelta(days=days_to_target) %}
{{ next_target_day.strftime('%Y-%m-%d 23:59:59') }}
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- set_conversation_response: |2-
{% set ns = namespace(items=[]) %} {% for event in data.values() |
map(attribute='events') | sum(start=[]) | sort(attribute='start') %} {% set
t = event.start | as_datetime | as_local %} {% if t.strftime('%H:%M') ==
'00:00' %} {% set ns.items = ns.items + [ event.summary ] %} {% else %} {%
set ns.items = ns.items + [ t.strftime('%H:%M - ') ~ event.summary ] %} {%
endif %} {% endfor %} {{ ns.items | join(', ') }}
mode: single
1 Like
Cao_Hoa
(Cao Hoa)
April 25, 2024, 3:32am
2
Your project is great. i used your automation but i use google home min - service: tts.google_translate_say data: entity_id: media_player.nha_duoi message: |- {% set ns = namespace(items= ) %} {% for event in data.values() | map(attribute=‘events’) | sum(start= ) | sort(attribute=‘start’) %} {% set t = event.start | as_datetime | as_local %} {% if t.strftime(‘%H:%M’) == ‘00:00’ %} {% set ns.items = ns.items + [ event.summary ] %} {% else %} {% set ns.items = ns.items + [ t.strftime('%H:%M - ‘) ~ event.summary ] %} {% endif %} {% endfor %} {{ ns.items | join(’, ') }} and I get this error
Daft
(Bram Diederik)
April 25, 2024, 7:03am
3
You cant run it in the template editor.
It requires data from the previous step.
Cao_Hoa
(Cao Hoa)
April 25, 2024, 2:56pm
4
Thank you very much. I will try again
Daft
(Bram Diederik)
April 25, 2024, 3:47pm
5
made it also work for the whole week or next week.
dutch version.
alias: voice agenda
description: ""
trigger:
- platform: conversation
command:
- agenda {dag}
- Achinda {dag}
- wat is er {dag}
- wat is de agenda van {dag}
- wat is de agenda voor {dag}
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.slots.dag == \"vandaag\" }}"
sequence:
- service: calendar.get_events
data:
start_date_time: "{{ now().strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ now().strftime('%Y-%m-%d 23:59:59') }}"
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- conditions:
- condition: template
value_template: "{{ trigger.slots.dag == \"morgen\" }}"
sequence:
- service: calendar.get_events
data:
start_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 23:59:59') }}"
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- conditions:
- condition: template
value_template: >-
{{ trigger.slots.dag in ['maandag', 'dinsdag', 'woensdag',
'donderdag', 'vrijdag', 'zaterdag', 'zondag'] }}
sequence:
- service: calendar.get_events
data:
start_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0,
microsecond=0) %}
{% set target_day = trigger.slots.dag %}
{% set days_to_target = (7 + ['maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag', 'zondag'].index(target_day.lower()) - today.weekday()) % 7 %}
{% set next_target_day = today + timedelta(days=days_to_target) %}
{{ next_target_day.strftime('%Y-%m-%d 00:00:01') }}
end_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0,
microsecond=0) %} {% set target_day = trigger.slots.dag %}
{% set days_to_target = (7 + ['maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag', 'zondag'].index(target_day.lower()) - today.weekday()) % 7 %}
{% set next_target_day = today + timedelta(days=days_to_target) %}
{{ next_target_day.strftime('%Y-%m-%d 23:59:59') }}
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- conditions:
- condition: template
value_template: "{{ trigger.slots.dag == \"deze week\" }}"
sequence:
- service: calendar.get_events
data:
start_date_time: >-
{{ (now() - timedelta(days=now().weekday())).strftime('%Y-%m-%d
00:00:00') }}
end_date_time: >-
{{ (now() + timedelta(days=(6 -
now().weekday()))).strftime('%Y-%m-%d 23:59:59') }}
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- conditions:
- condition: template
value_template: "{{ trigger.slots.dag == \"volgende week\" }}"
sequence:
- service: calendar.get_events
data:
start_date_time: >-
{{ (now() + timedelta(days=7 -
now().weekday())).strftime('%Y-%m-%d 00:00:00') }}
end_date_time: >-
{{ (now() + timedelta(days=(13 -
now().weekday()))).strftime('%Y-%m-%d 23:59:59') }}
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- if:
- condition: template
value_template: "{{ data is defined }}"
then:
- set_conversation_response: |2-
{% set ns = namespace(items=[]) %} {% for event in data.values() |
map(attribute='events') | sum(start=[]) | sort(attribute='start') %} {% set
t = event.start | as_datetime | as_local %} {% if t.strftime('%H:%M') ==
'00:00' %} {% set ns.items = ns.items + [ event.summary ] %} {% else %} {%
set ns.items = ns.items + [ t.strftime('%H:%M - ') ~ event.summary ] %} {%
endif %} {% endfor %} {{ ns.items | join(', ') }}
enabled: false
- set_conversation_response: >
{% set ns = namespace(items=[]) %}
{% set prev = namespace(day=[]) %}
{% set dagen_nl = {
'Monday': 'maandag',
'Tuesday': 'dinsdag',
'Wednesday': 'woensdag',
'Thursday': 'donderdag',
'Friday': 'vrijdag',
'Saturday': 'zaterdag',
'Sunday': 'zondag'
} %}
{% set maanden_nl = {
'January': 'januari',
'February': 'februari',
'March': 'maart',
'April': 'april',
'May': 'mei',
'June': 'juni',
'July': 'juli',
'August': 'augustus',
'September': 'september',
'October': 'oktober',
'November': 'november',
'December': 'december'
} %}
{% for event in data.values() | map(attribute='events') |
sum(start=[]) | sort(attribute='start') %}
{% set t = event.start | as_datetime | as_local %}
{% if prev.day == t.strftime('%d') %}
{% set ns.items = ns.items + [ ""] %}
{% else %}
{% set ns.items = ns.items + [ dagen_nl[t.strftime('%A')] ~ t.strftime(' %d ') ~ maanden_nl[t.strftime('%B')] ] %}
{% set prev.day = t.strftime('%d') %}
{% endif %}
{% if t.strftime('%H:%M') == '00:00' %}
{% set ns.items = ns.items + [ event.summary ] %}
{% else %}
{% set ns.items = ns.items + [ t.strftime('%H:%M - ') ~ event.summary ] %}
{% endif %}
{% endfor %}
{{ ns.items | join(' ') }}
else:
- set_conversation_response: Geen agenda punten voor {{ trigger.slots.dag }}
mode: single
1 Like
mike2ns
(Mike2ns)
November 16, 2024, 2:24pm
7
Hey, I’ve successfully imported the Dutch version but the English version won’t save. I get a red line on the left which I guess is an error.
The steps I went through was to replace your calendar entities with mine. Any ideas?
Daft
(Bram Diederik)
November 16, 2024, 2:26pm
8
If mine works and you fiddle and it doesnt work there is not much i can do.
Parse it trough an ai
mike2ns
(Mike2ns)
November 16, 2024, 3:07pm
9
Thanks for the AI tip, I pasted the unmodified English yaml in and it adjusted it.
alias: voice agenda
description: ""
trigger:
- platform: conversation
command:
- agenda {day}
- calendar {day}
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.slots.day == 'today' }}"
sequence:
- service: calendar.get_events
data:
start_date_time: "{{ now().strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ now().strftime('%Y-%m-%d 23:59:59') }}"
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- conditions:
- condition: template
value_template: "{{ trigger.slots.day == 'tomorrow' }}"
sequence:
- service: calendar.get_events
data:
start_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00') }}"
end_date_time: "{{ (now() + timedelta(days=1)).strftime('%Y-%m-%d 23:59:59') }}"
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
default:
- service: calendar.get_events
data:
start_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set target_day = trigger.slots.day %}
{% set days_to_target = (7 + ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'].index(target_day.lower()) - today.weekday()) % 7 %}
{% set next_target_day = today + timedelta(days=days_to_target) %}
{{ next_target_day.strftime('%Y-%m-%d 00:00:00') }}
end_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set target_day = trigger.slots.day %}
{% set days_to_target = (7 + ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'].index(target_day.lower()) - today.weekday()) % 7 %}
{% set next_target_day = today + timedelta(days=days_to_target) %}
{{ next_target_day.strftime('%Y-%m-%d 23:59:59') }}
target:
entity_id:
- calendar.persoonlijk
- calendar.verjaardagen_2
- calendar.feestdagen_in_nederland
response_variable: data
- set_conversation_response: |2-
{% set ns = namespace(items=[]) %}
{% for event in data.values() | map(attribute='events') | sum(start=[]) | sort(attribute='start') %}
{% set t = event.start | as_datetime | as_local %}
{% if t.strftime('%H:%M') == '00:00' %}
{% set ns.items = ns.items + [ event.summary ] %}
{% else %}
{% set ns.items = ns.items + [ t.strftime('%H:%M - ') ~ event.summary ] %}
{% endif %}
{% endfor %}
{{ ns.items | join(', ') }}
mode: single