Last active
July 23, 2023 03:06
-
-
Save zsarnett/4e18e92238da6b0f07a6762dabae39cf to your computer and use it in GitHub Desktop.
Open AI Notification on Motion to Speaker
This file contains hidden or 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: OpenAI - Speaker Notification on Motion | |
description: | |
Conversation agent generates a notification based on the upcoming calendar | |
agenda, location, and weather. | |
author: Zack Barett (Allen Porter) | |
domain: automation | |
input: | |
motion: | |
name: Motion Device | |
description: This will be how you trigger Jarvis to tell you about your day | |
selector: | |
entity: | |
device_class: motion | |
start_time: | |
name: Time to start looking for motion | |
description: This will be the time the automation starts looking for motion | |
default: "07:00:00" | |
selector: | |
time: | |
end_time: | |
name: Time to stop looking for motion | |
description: This will be the time the automation stops looking for motion (Recommendation - 3-4 hours between start and end) | |
default: "11:00:00" | |
selector: | |
time: | |
speaker: | |
name: Speaker | |
description: The speaker you want the notification to speak on | |
selector: | |
entity: | |
domain: media_player | |
language: | |
name: Language | |
default: "en-CA" | |
selector: | |
select: | |
options: | |
- "en-CA" | |
- "en" | |
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 | |
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 | |
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 | |
default: |- | |
Please generate text for a notification that will be sent to the users | |
smartphone with helpful information. The notification should be as close to normal language as possible as if you were talking human to human | |
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 | |
- Include Weather details like the high and lows + precipitation | |
variables: | |
motion: !input motion | |
motion_device: "{{ device_id(motion) }}" | |
start_time: !input start_time | |
end_time: !input end_time | |
language: !input language | |
speaker: !input speaker | |
weather_entity: !input weather_entity | |
calendar_entity: !input calendar_entity | |
zone_entity: !input zone_entity | |
calendar_duration: !input calendar_duration | |
prompt: !input prompt | |
trigger: | |
type: motion | |
platform: device | |
domain: binary_sensor | |
device_id: motion_device | |
entity_id: !input motion | |
condition: | |
- condition: time | |
weekday: | |
- mon | |
- tue | |
- wed | |
- thu | |
- fri | |
- sat | |
- sun | |
before: !input end_time | |
after: !input start_time | |
- condition: template | |
value_template: "{{as_timestamp(this.attributes.last_triggered)|timestamp_custom('%-d') != as_timestamp(now())|timestamp_custom('%-d')}}" | |
action: | |
- alias: Fetch Calendar Agenda | |
service: calendar.list_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() }} | |
{%- 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 forecast = state_attr(weather_entity, 'forecast')[0] %} | |
{%- set temperature_unit = state_attr(weather_entity, 'temperature_unit') -%} | |
Weather: {{ forecast.condition }} ({{ forecast.temperature }}{{ temperature_unit }}, {{ forecast.precipitation }}% precipitation) | |
{%- endif %} | |
Weather Details: {{states.weather.home.attributes.forecast}} | |
Calendar "{{ state_attr(calendar_entity, 'friendly_name') }}" events for the next {{ calendar_duration.hours }}: | |
{%- if 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 %} | |
{{ prompt }} | |
agent_id: !input conversation_agent | |
response_variable: agent | |
- alias: "Send notification" | |
service: tts.cloud_say | |
data: | |
entity_id: !input speaker | |
language: 'en-CA' | |
message: "{{ agent.response.speech.plain.speech }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment