Skip to content

Instantly share code, notes, and snippets.

@dskindell
Last active June 26, 2024 21:58
Show Gist options
  • Save dskindell/3e480ba37590972dd4f071d6da13a18a to your computer and use it in GitHub Desktop.
Save dskindell/3e480ba37590972dd4f071d6da13a18a to your computer and use it in GitHub Desktop.
home_assistant-notify_agent_agenda.yaml
blueprint:
name: Conversation agent agenda notification
description:
Conversation agent generates a notification based on the upcoming calendar
agenda, location, and weather.
author: allenporter
domain: automation
input:
triggers:
name: Custom Triggers
description: List of triggers
selector:
trigger:
default: []
conditions:
name: Conditions
description: List of conditions
selector:
condition:
default: []
notify_service:
name: Notify service name
description:
The name of the notify service where the notification should be
sent.
selector:
text:
multiline: false
multiple: false
default: notify.notify
notify_title:
name: Notification Title
description: Title of the sent notification
selector:
text:
multiline: false
multiple: false
default: Daily Summary Report
calendar_entity:
name: Calendar
description: The calendar entity to use for finding upcoming calendar events.
selector:
entity:
multiple: false
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
hourly_weather_entity:
name: Hourly Weather entity
description: The weather entity to use for upcoming weather forecast.
selector:
entity:
multiple: false
filter:
- domain:
- weather
hourly_forecast_entries:
name: Hourly Forecast Entries
description: The max number of hourly forecast entries to use
selector:
number:
min: 1
max: 24
grass_pollen_entity:
name: Grass pollen entity
description: The entity to use for today's grass pollen amount
selector:
entity:
multiple: false
filter:
- domain:
- sensor
ragweed_pollen_entity:
name: Ragweed pollen entity
description: The entity to use for today's ragweed pollen amount
selector:
entity:
multiple: false
filter:
- domain:
- sensor
mold_pollen_entity:
name: Mold pollen entity
description: The entity to use for today's mold pollen amount
selector:
entity:
multiple: false
filter:
- domain:
- sensor
tree_pollen_entity:
name: Tree pollen entity
description: The entity to use for today's tree pollen amount
selector:
entity:
multiple: false
filter:
- domain:
- sensor
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
description:
"The conversation agent to use for generating the notification
text.
This should be a OpenAI conversation agent for this Blueprint to work."
selector:
conversation_agent: {}
prompt:
name: Conversation agent prompt
selector:
text:
multiline: true
type: text
multiple: false
default: |-
Please generate text for a notification that will be sent to the users
smartphone with helpful information.
You are a helpful personal agent that generates text for the user:
- 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")
- How much time remaining until their first meeting
- Anything that may be special or unique, such as celebrating a birthday
source_url: https://www.home-assistant.io/blueprints/blog/2023-07/notify_agent_agenda.yaml
mode: single
trigger: !input triggers
condition: !input conditions
action:
- variables:
hourly_weather_entity: !input hourly_weather_entity
hourly_forecast_entries: !input hourly_forecast_entries
grass_pollen_entity: !input grass_pollen_entity
ragweed_pollen_entity: !input ragweed_pollen_entity
mold_pollen_entity: !input mold_pollen_entity
tree_pollen_entity: !input tree_pollen_entity
calendar_entity: !input calendar_entity
zone_entity: !input zone_entity
calendar_duration: !input calendar_duration
prompt: !input prompt
- alias: Fetch Hourly Weather Forecast
service: weather.get_forecasts
data:
type: hourly
target:
entity_id: !input hourly_weather_entity
response_variable: hourly_forecasts
- alias: Update Calendar
service: homeassistant.update_entity
target:
entity_id: !input calendar_entity
data: {}
- alias: Fetch Calendar Agenda
service: calendar.get_events
data:
duration: !input calendar_duration
target:
entity_id: !input calendar_entity
response_variable: agenda
- alias: Conversation Agent Notification Text
service: conversation.process
data:
text: |-
Time: {{ now().strftime("%A %B %d %H:%M %p") }}
{%- if zone_entity is defined %}
Latitude: {{ state_attr(zone_entity, 'latitude') | round(1) }}
Longitude: {{ state_attr(zone_entity, 'longitude') | round(1) }}
{% endif %}
{%- set hourly_weather = hourly_forecasts[hourly_weather_entity].forecast[0] %}
{%- set temperature_unit = '°F' -%}
{% set next_forecasts = hourly_forecasts[hourly_weather_entity].forecast[:hourly_forecast_entries] %}
Hourly Weather Forecast for the next {{ ((next_forecasts[-1].datetime|as_timestamp - utcnow()|as_timestamp) / 3600) | int }} hours:
{%- for forecast in next_forecasts %}
- Date & Time: {{ forecast.datetime|as_timestamp|timestamp_local }}
{%- if forecast.condition is defined %}
Condition: {{ forecast.condition }}
{%- endif %}
Temperature: {{ forecast.temperature }} {{ temperature_unit }}
{%- if forecast.apparent_temperature is defined %}
RealFeel Temperature: {{ forecast.apparent_temperature }} {{ temperature_unit }}
{%- endif %}
{%- if forecast.precipitation_probability is defined %}
Chance of Precipitation: {{ forecast.precipitation_probability }}%
{%- endif %}
{%- if forecast.wind_speed is defined %}
Wind Speed: {{ forecast.wind_speed }} mph
{%- endif %}
{%- if forecast.cloud_coverage is defined %}
Cloud Cover Percentage: {{ forecast.cloud_coverage }}%
{%- endif %}
{%- if forecast.uv_index is defined %}
UV Index: {{ forecast.uv_index }}
{%- endif %}
{%- endfor %}
Calendar "{{ state_attr(calendar_entity, 'friendly_name') }}" events for the next {{ calendar_duration.hours }} hours:
{%- if agenda[calendar_entity].events %}
{%- for event in agenda[calendar_entity].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 %}
{{ prompt }}
agent_id: !input conversation_agent
response_variable: agent
- alias: Send notification
service: !input notify_service
data:
title: "{{ notify_title }} {{ now().strftime('%A') }}"
message: "{{ agent.response.speech.plain.speech }}"
data:
sticky: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment