mike2ns
(Mike2ns)
1
With a little bit of my own work and Chat GPT I’ve got stuck on filtering just the event summary from a calendar entry. Here is my automation
alias: New Automation
description: ""
triggers:
- command:
- What bin day is it
trigger: conversation
conditions: []
actions:
- target:
entity_id: calendar.refuse_bin_calendar
data:
start_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0, microsecond=0)
%} {% set days_until_thursday = (3 - today.weekday() + 7) % 7 %} {% set
next_thursday = today + timedelta(days=days_until_thursday) %} {{
next_thursday.strftime('%Y-%m-%dT00:00:00') }}
end_date_time: >
{% set today = now().replace(hour=0, minute=0, second=0, microsecond=0)
%} {% set days_until_thursday = (3 - today.weekday() + 7) % 7 %} {% set
next_thursday = today + timedelta(days=days_until_thursday) %} {{
next_thursday.strftime('%Y-%m-%dT23:59:59') }}
response_variable: calendar_events
action: calendar.get_events
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.roam
message: "{{ calendar_events }}"
target:
entity_id: tts.home_assistant_cloud
mode: single
When I look at the trace info, the information I want to announce is the event summary.
calendar_events:
calendar.refuse_bin_calendar:
events:
- start: '2024-11-21'
end: '2024-11-22'
summary: Refuse Bin Collection
How do I pass through the event summary to TTS?
There’s no reason to calculate everything twice:
alias: New Automation
description: ""
triggers:
- command:
- What bin day is it
trigger: conversation
conditions: []
actions:
- variables:
today: "{{ today_at() }}"
days_until_thursday: "{{ (10 - today.weekday()) % 7 }}"
next_thursday: "{{ today + timedelta(days=days_until_thursday) }}"
- target:
entity_id: calendar.refuse_bin_calendar
data:
start_date_time: "{{ next_thursday }}"
end_date_time: "{{ next_thursday + timedelta(days=1, seconds=-1) }}"
response_variable: calendar_events
action: calendar.get_events
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.roam
message: "{{ calendar_events['calendar.refuse_bin_calendar']['events'][0].summary }}"
target:
entity_id: tts.home_assistant_cloud
mode: single
2 Likes
mike2ns
(Mike2ns)
3
Hey, thanks for the edit. I ran the new code through but I get this error.
Error: UndefinedError: ‘str object’ has no attribute ‘weekday’
Do I need to declare weekday?
Thanks,
Mike
armedad
4
i think @Didgeridrew just had a small issue. change the today.weekday() to now().weekday():
alias: New Automation
description: ""
triggers:
- command:
- What bin day is it
trigger: conversation
conditions: []
actions:
- variables:
today: "{{ today_at() }}"
days_until_thursday: "{{ (10 - now().weekday()) % 7 }}"
next_thursday: "{{ today + timedelta(days=days_until_thursday) }}"
- target:
entity_id: calendar.refuse_bin_calendar
data:
start_date_time: "{{ next_thursday }}"
end_date_time: "{{ next_thursday + timedelta(days=1, seconds=-1) }}"
response_variable: calendar_events
action: calendar.get_events
- action: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.roam
message: "{{ calendar_events['calendar.refuse_bin_calendar']['events'][0].summary }}"
target:
entity_id: tts.home_assistant_cloud
mode: single
That shouldn’t be an issue since today
should hold a datetime object. But, after testing, I agree it does seem to be the cause…
@mike2ns
You can update the variables as follows to work around the fact that they aren’t passing the datetime object:
- variables:
days_until_thursday: "{{ (10 - today_at().weekday()) % 7 }}"
next_thursday: "{{ today_at() + timedelta(days=days_until_thursday) }}"
....