I don’t see a new version of this, simply trying to have TTS piper read outloud my weather and calendar for next two days. Since I don’t know how to write Jinja, have been back and forth with AI and the simple script got more complicated. Any help would be appreciated!!!
Here is the script:
alias: Morning Briefing - Weather & Calendar via TTS
description: Announces the weather and calendar agenda at 7AM via Sonos using Piper TTS
triggers:
alias: Create briefing message
variables:
message: >-
{% set today = now().date() %} {% set tomorrow = (now() +
timedelta(days=1)).date() %} {% set summaries = namespace(today=‘’,
tomorrow=‘’) %} {% for entry in forecast_data[weather_entity].forecast
%}
{% set entry_time = entry.datetime | as_datetime | as_local %}
{% if entry_time.date() == today and entry_time.hour in [8, 17] %}
{% set summaries.today = summaries.today +
"- At " ~ (entry_time | timestamp_custom(‘%-I %p’)) ~ ": " ~ entry.condition ~
“, " ~ entry.temperature|string ~ temperature_unit ~
(”, " ~ entry.precipitation|string ~ “% chance of rain.” if entry.precipitation is defined and entry.precipitation > 0 else “.”) ~ “\n” %}
{% elif entry_time.date() == tomorrow and entry_time.hour in [8, 17] %}
{% set summaries.tomorrow = summaries.tomorrow +
"- At " ~ (entry_time | timestamp_custom(‘%-I %p’)) ~ ": " ~ entry.condition ~
“, " ~ entry.temperature|string ~ temperature_unit ~
(”, " ~ entry.precipitation|string ~ “% chance of rain.” if entry.precipitation is defined and entry.precipitation > 0 else “.”) ~ “\n” %}
{% endif %}
{% endfor %}
Good morning! It's {{ now().timestamp() | timestamp_custom('%A, %B %d')
}}.
{% if summaries.today %} Here's today's forecast: {{ summaries.today }}
{% endif %}
{% if summaries.tomorrow %} And here's a preview for tomorrow: {{
summaries.tomorrow }} {% endif %}
Now, for your calendar: {% if calendar_agenda[calendar_entity].events %}
{% for event in calendar_agenda[calendar_entity].events %}
- {{ event.summary }} at
{% if event.start is defined %}
{{ event.start | as_datetime | as_local | timestamp_custom('%A at %I:%M %p') }}
{% else %}
all day
{% endif %}
{% endfor %}
{% else %}
You have no events in the next two days.
{% endif %}
Thanks for coming here and asking a question.
Would you be so kind as to adjusting the format of your code so that we can read it properly & check the YAML spacing, etc. Editing your original is the preferred way. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
Use the </> button or this:
Here is an example of how to fix it from the site FAQ Page. How to help us help you - or How to ask a good question.
ChatGPT and the other bullshit engines are bad at Home Assistant and produce a lot of plausible-looking, non-functional configurations. HA updates frequently and the majority of available examples that LLMs can pull from are old and/or from people posting non-working configs here or on Reddit. Deciphering and correcting LLM slop often requires a higher level of knowledge than it would take to just create the config yourself from scratch.
I got this to work, at least it reads my events! Thank you for answering. Will now add Weather and look at the link you sent. Working on nicer Jinja. This short piece works for Calendar:
type or paste code here
alias: Calendar ONLY
description: ""
triggers: []
conditions: []
actions:
- data:
duration:
hours: 24
minutes: 0
seconds: 0
target:
entity_id:
- calendar.xxxxxxxxxxxxxxxx_com
- calendar.family
response_variable: calendar_data
action: calendar.get_events
- target:
entity_id: tts.piper
data:
media_player_entity_id: media_player.dining_room
message: >-
Hi Nacho. Here's your calendar for the next 24 hours. {% set
event_found = false %} {% for cal_id, cal in calendar_data.items() %}
{% for event in cal.events %}
{% set event_found = true %}
{{ event.summary }}
{% if event.start is defined %}
at {{ event.start | as_datetime | as_local | as_timestamp | timestamp_custom('%A at %I:%M %p') }}.
{% else %}
all day.
{% endif %}
{% endfor %}
{% endfor %} {% if not event_found %}
You have no events scheduled in the next 24 hours.
{% endif %}
action: tts.speak
This version works with KLOM (National Weather Service), and reads the weather for next 2 days and Google calendar events for next 2 days. You can add a trigger and condition to suit your needs. Need KLOM and google calendar intergration working. I have output through my Sonos speaker. Message changes whether (pun intended) is morning, afternoon or evening:
alias: Weather and Calendar Briefing next 24 hours
description: Reliable briefing with weather and calendar
triggers: []
conditions: []
actions:
- data:
duration: "24:00:00"
target:
entity_id:
- calendar.xxxxxxxxxxxxx_com
- calendar.family
response_variable: calendar_data
action: calendar.get_events
- action: nws.get_forecasts_extra
target:
entity_id:
- weather.klom
data:
type: twice_daily
response_variable: weather_data
- variables:
weather_report: >-
{% if 'weather.klom' in weather_data and weather_data['weather.klom'].forecast | length >= 2 %}
{% set today = weather_data['weather.klom'].forecast[0].detailed_description %}
{% set tomorrow = weather_data['weather.klom'].forecast[1].detailed_description %}
{% set today = today | regex_replace('MPH', 'miles per hour') %}
{% set tomorrow = tomorrow | regex_replace('MPH', 'miles per hour') %}
{% set today = today | regex_replace('mph', 'miles per hour') %}
{% set tomorrow = tomorrow | regex_replace('mph', 'miles per hour') %}
Your forecast for today is: {{ today }}.
And tomorrow is: {{ tomorrow }}.
{% else %}
Weather information is not available right now.
{% endif %}
calendar_report: >-
{% set ns = namespace(event_count=0, text="") %}
{% if calendar_data is defined %}
{% for cal in calendar_data.values() %}
{% for event in cal.events %}
{% set ns.event_count = ns.event_count + 1 %}
{% set event_time = event.start | as_datetime | as_local if event.start is defined and not event.start is string else None %}
{% set ns.text = ns.text + (". " if ns.event_count > 1 else "") + event.summary %}
{% if event_time %}
{% set ns.text = ns.text + " at " + event_time.strftime('%-I:%M %p') %}
{% endif %}
{% endfor %}
{% endfor %}
{{ ns.text if ns.event_count > 0 else "No scheduled events." }}
{% else %}
Could not access calendar.
{% endif %}
- target:
entity_id: tts.piper
data:
message: >-
{% set now = now() %}
Good {{ "morning" if now.hour < 12 else "afternoon" if now.hour < 18 else "evening" }} Name.
Here is your weather report: {{ weather_report }}
And your schedule for the next 24 hours: {{ calendar_report }}
media_player_entity_id: media_player.dining_room
action: tts.speak