-
-
Save Anto79-ops/92537f9f3ff07e079fd640256718feb4 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Conversation agent Agenda Notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Conversation agent Agenda Notification with tts on motion super | |
description: | | |
Conversation agent generates a personalized notification based on the | |
upcoming calendar agenda, tasks, birthday reminders, location, and weather information. | |
domain: automation | |
input: | |
language: | |
name: Language | |
description: Language of Assistant Response | |
selector: | |
language: | |
default: "en" | |
user: | |
name: User | |
description: User who is being addressed | |
selector: | |
entity: | |
multiple: false | |
filter: | |
domain: | |
- person | |
motion: | |
name: Motion Entity | |
description: Motion entity to trigger the process | |
selector: | |
text: {} | |
media_player: | |
name: Media Player | |
description: | |
The name of the media player for tts | |
selector: | |
text: {} | |
cpap_score: | |
name: CPAP Score | |
description: | |
CPAP Total myAir comprehensive score | |
selector: | |
text: {} | |
cpap_ahi_events: | |
name: CPAP AHI | |
description: | |
CPAP AHI events per hour | |
selector: | |
text: {} | |
notify_service: | |
name: Notify service name | |
description: The name of the notify service where the notification should be sent. | |
selector: | |
text: {} | |
default: notify.notify | |
notify_target: | |
name: Notify target | |
description: The target of the notify service. | |
selector: | |
text: {} | |
default: | |
task_entities: | |
name: Tasks | |
description: The tasks entities to use for finding upcoming todos. | |
selector: | |
entity: | |
multiple: true | |
filter: | |
domain: | |
- todo | |
calendar_entities: | |
name: Calendar | |
description: The calendar entities to use for finding upcoming calendar events. | |
selector: | |
entity: | |
multiple: true | |
filter: | |
domain: | |
- calendar | |
calendar_duration: | |
name: Calendar Event duration | |
description: How many hours ahead to look for upcoming calendar events. | |
selector: | |
duration: | |
default: | |
hours: 18 | |
birthday_calendar: | |
name: Birthday Calendar | |
description: The calendar entity to use for finding upcoming birthdays. | |
selector: | |
entity: | |
multiple: false | |
filter: | |
domain: | |
- calendar | |
birthday_duration: | |
name: Birthday Reminder duration | |
description: How many days ahead to look for upcoming birthdays. | |
selector: | |
duration: | |
enable_day: true | |
default: | |
days: 7 | |
weather_entity: | |
name: Weather Entity | |
description: The weather entity to use for upcoming weather forecast. | |
selector: | |
entity: | |
multiple: false | |
filter: | |
domain: | |
- weather | |
zone_entity: | |
name: Home Zone Entity | |
description: The zone entity to use to determine approximate location for understanding typical weather. | |
selector: | |
entity: | |
multiple: false | |
filter: | |
domain: | |
- zone | |
conversation_agent: | |
name: Conversation Agent | |
selector: | |
conversation_agent: | |
user_prompt_task: | |
name: Conversation Agent Task | |
selector: | |
text: | |
multiline: true | |
type: text | |
default: |- | |
Please generate text for a notification that will be sent to the users smartphone and smart speaker with helpful information. | |
Please do not use special characters like * or asterisks. | |
Do not mention task(s) if No Tasks are listed. | |
trigger: | |
platform: state | |
entity_id: !input motion | |
to: "on" | |
condition: | |
- condition: template | |
value_template: >- | |
{{(as_timestamp(now()) - | |
as_timestamp(state_attr("automation.conversation_agent_agenda_notification_with_tts_on_motion_super", | |
"last_triggered") | default(0)) | int > 7201 )}} | |
- condition: time | |
after: "07:00:00" | |
before: "09:00:00" | |
action: | |
- variables: | |
language: !input language | |
user: !input user | |
weather_entity: !input weather_entity | |
task_entities: !input task_entities | |
calendar_entities: !input calendar_entities | |
zone_entity: !input zone_entity | |
calendar_duration: !input calendar_duration | |
birthday_calendar: !input birthday_calendar | |
birthday_duration: !input birthday_duration | |
user_prompt_task: !input user_prompt_task | |
cpap_score: !input cpap_score | |
cpap_ahi_events: !input cpap_ahi_events | |
- alias: Fetch Tasks | |
service: todo.get_items | |
data: | |
status: | |
- needs_action | |
target: | |
entity_id: !input task_entities | |
response_variable: tasks_responses | |
- alias: Fetch Calendar Agenda | |
service: calendar.get_events | |
data: | |
duration: !input calendar_duration | |
target: | |
entity_id: !input calendar_entities | |
response_variable: events_responses | |
- alias: Fetch Birthday Calendar | |
service: calendar.get_events | |
data: | |
duration: !input birthday_duration | |
target: | |
entity_id: !input birthday_calendar | |
response_variable: birthday_responses | |
- alias: Get Weather Forecast | |
service: weather.get_forecasts | |
data: | |
type: daily | |
target: | |
entity_id: !input weather_entity | |
response_variable: weekly_weather_forecast | |
- alias: "Prepare Prompt" | |
variables: | |
prompt: |- | |
# You are a helpful personal agent that generates notifications for the user: | |
- You should respond in the RFC 5646 language: "{{language}}" | |
- Your answers are helpful, friendly, warm, insightful. | |
- Your answers are not technical, and do not include Home Assistant internal details such as entities in responses. | |
- Your messages help the user prepare for their day, for example: | |
- Making note of unusual weather for the location and time of year (but not mundane details like "0% chance of precipitation"). | |
- Do not tell the user his location or the current time. | |
- How much time remaining until their first meeting | |
- Anything that may be special or unique, such as celebrating a birthday (but not that there are no birthdays) | |
- Comment briefly on the users quality of sleep based on the CPAP Total myAir Score and Hourly CPAP Apnea-Hypopnea Index or AHI | |
# Information to include in the notification: | |
Name of User: {{ state_attr(user, "friendly_name") }} | |
Time: {{ now().time().isoformat('minutes') }} | |
{%- if zone_entity is defined %} | |
Latitude: {{ state_attr(zone_entity, 'latitude') | round(1) }} | |
Longitude: {{ state_attr(zone_entity, 'longitude') | round(1) }} | |
{% endif %} | |
{%- if weather_entity is defined %} | |
{%- set temperature_unit = state_attr(weather_entity, 'temperature_unit') -%} | |
{%- set todays_forecast = weekly_weather_forecast[weather_entity]['forecast'][0] %} | |
Weather: {{ todays_forecast.condition }} daily high ({{ todays_forecast.temperature }}{{ temperature_unit }}, {{ todays_forecast.precipitation }}% precipitation) | |
{%- endif %} | |
# Tasks Lists: | |
{%- for task_entity in task_entities %} | |
Upcoming tasks for today on list "{{ state_attr(task_entity, 'friendly_name') }}": | |
{%- for task in tasks_responses[task_entity]['items'] | selectattr('due', 'defined') | selectattr('due', 'eq', now().date() | string) | map(attribute='summary') | list or ['No Tasks'] %} | |
- {{ task }} | |
{%- endfor %} | |
Upcoming tasks with no due date: | |
{%- for task in tasks_responses[task_entity]['items'] | selectattr('due', 'undefined') | map(attribute='summary') | list or ['No Tasks'] %} | |
- {{ task }} | |
{%- endfor %} | |
{%- endfor %} | |
# Calendar Events: | |
{%- for calendar_entity in calendar_entities %} | |
Calendar "{{ state_attr(calendar_entity, 'friendly_name') }}" events for the next {{ calendar_duration.hours }} hours: | |
{%- set agenda = events_responses[calendar_entities[loop.index0]] %} | |
{%- if "events" in agenda and agenda.events %} | |
{%- for event in agenda.events %} | |
- Summary: {{ event.summary }} | |
Start-End: {% if event.start is defined %}{{ event.start }} to {{ event.end }}{% else %}All Day{% endif %} | |
{%- if event.descripton is defined %} | |
Descripton: {{ event.descripton }} | |
{% endif -%} | |
{%- if event.location is defined %} | |
Location: {{ event.location }} | |
{% endif -%} | |
{%- endfor %} | |
{%- else %} | |
- No upcoming events. | |
{%- endif %} | |
{%- endfor %} | |
# Upcoming birthdays: | |
{%- set birthdays = birthday_responses[birthday_calendar] %} | |
{%- if "events" in birthdays and birthdays.events %} | |
{%- for event in birthdays.events %} | |
- Birthday Reminder: {{ event.summary }} on {{ event.start }} | |
{%- endfor %} | |
{%- else %} | |
- No upcoming birthdays. | |
{%- endif %} | |
{%- if cpap_score is defined %} | |
CPAP Sleep Score: {{ states('sensor.cpap_total_myair_score') }} | |
{%- endif %} | |
{%- if cpap_ahi_events is defined %} | |
Hourly CPAP Apnea-Hypopnea Index: {{ states('sensor.cpap_ahi_events_per_hour') }} | |
{%- endif %} | |
# Task: | |
{{ user_prompt_task }} | |
- alias: "Conversation Agent Notification Text" | |
service: conversation.process | |
data: | |
text: "{{ prompt }}" | |
agent_id: !input conversation_agent | |
response_variable: agent | |
- alias: "Send notification" | |
service: !input notify_service | |
data: | |
target: !input notify_target | |
title: "{{ now().strftime('%A') }} Agenda" | |
message: "{{ agent.response.speech.plain.speech }}" | |
- service: tts.speak | |
data: | |
cache: false | |
media_player_entity_id: !input media_player | |
message: |- | |
{% if (agent.response.response_type == 'action_done') %} | |
{{agent.response.speech.plain.speech | trim | replace('\"','')}} | |
{% else %} | |
No agenda today. | |
{% endif %} | |
target: | |
entity_id: tts.piper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment