forked from fixtse/blueprints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple_notify_agent_calendar_agenda.yaml
308 lines (299 loc) · 11.3 KB
/
multiple_notify_agent_calendar_agenda.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
blueprint:
name: Multi Calendar Conversation agent agenda notification
source_url: https://github.com/fixtse/blueprints/blob/main/multiple_notify_agent_calendar_agenda.yaml
description:
"# Multi Calendar Conversation Agent Agenda Notification\n **Version: 2.1.1**\n\n
Conversation agent generates a notification based on the upcoming calendars, agendas, location, and weather.\n\n
You can choose up to 3 calendars and 3 notify services to better fit your needs:\n\n
- Don't forget to check the *Conversation agent prompt* and the end and update it if needed.\n\n
- Adjust the maximum tokens to return in the OpenAI integration, if not sure what I'm talking about,\n Check up the **How to make it better** section of my video: [Click here](https://www.youtube.com/watch?v=rIFkGibePIw&t=283s) \n\n
Need help? or Just want to say hi \U0001F642? \n
Let me know what you think about this blueprint in the comments: [Click Here](https://fixtse.com/blog/openia-conversation-integration)\n\n"
author: fixtse
domain: automation
input:
notify_time:
name: Notification time
description: Time the automation is triggered to send the notification.
selector:
time: {}
default: 07:00:00
calendar_number:
name: How many calendars do you want to use?
description: Select the number
default: one
selector:
select:
options:
- label: "1"
value: one
- label: "2"
value: two
- label: "3"
value: three
multiple: false
custom_value: false
calendar_entity_1:
name: First Calendar
description: The first calendar entity to use for finding upcoming calendar events.
default: []
selector:
entity:
multiple: false
filter:
- domain:
- calendar
calendar_entity_2:
name: Second Calendar
description: The second calendar entity to use for finding upcoming calendar events.
default: []
selector:
entity:
multiple: false
filter:
- domain:
- calendar
calendar_entity_3:
name: Third Calendar
description: The third calendar entity to use for finding upcoming calendar events.
default: []
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
notify_number:
name: How many notify services do you want to use?
description: Select the number
default: one
selector:
select:
options:
- label: "1"
value: one
- label: "2"
value: two
- label: "3"
value: three
multiple: false
custom_value: false
notify_service_1:
name: First Notify service name
description:
The name of the first notify service where the notification should be
sent.
selector:
text: {}
default: notify.notify_1
notify_service_2:
name: Second Notify service name
description:
The name of the second notify service where the notification should be
sent.
selector:
text: {}
default: notify.notify_2
notify_service_3:
name: Third Notify service name
description:
The name of the third notify service where the notification should be
sent.
selector:
text: {}
default: notify.notify_3
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.
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:
- Each calendar belongs to a different person, use the calendar name to refer to them, provide individual recommendations for each calendar, and make special remarks if some events match in time and the title or description makes a mention between calendars
- 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
trigger:
platform: time
at: !input notify_time
action:
- variables:
weather_entity: !input weather_entity
calendar_number: !input calendar_number
calendar_entity_1: !input calendar_entity_1
calendar_entity_2: !input calendar_entity_2
calendar_entity_3: !input calendar_entity_3
notify_number: !input notify_number
zone_entity: !input zone_entity
calendar_duration: !input calendar_duration
prompt: !input prompt
- alias: Fetch First Calendar Agenda
service: calendar.get_events
data:
duration: !input calendar_duration
target:
entity_id: !input calendar_entity_1
response_variable: agenda_1
- if:
- condition: template
value_template: "{{ (calendar_number == 'two') or (calendar_number == 'three') }}"
then:
- alias: Fetch Second Calendar Agenda
service: calendar.get_events
data:
duration: !input calendar_duration
target:
entity_id: !input calendar_entity_2
response_variable: agenda_2
- if:
- condition: template
value_template: "{{ calendar_number == 'three'}}"
then:
- alias: Fetch Third Calendar Agenda
service: calendar.get_events
data:
duration: !input calendar_duration
target:
entity_id: !input calendar_entity_3
response_variable: agenda_3
- alias: Fetch Weather Forecast
service: weather.get_forecasts
data:
type: hourly
target:
entity_id:
- "{{ weather_entity }}"
response_variable: daily_forecast
- variables:
forecast_entity: "{{ daily_forecast[weather_entity] }}"
forecast: "{{ forecast_entity.forecast[0] }}"
- 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 %}
{%- if weather_entity is defined %}
{%- set temperature_unit = state_attr(weather_entity, 'temperature_unit') -%}
Forecast: {{ forecast.condition }} ({{ forecast.temperature }}{{ temperature_unit }}, {{ forecast.precipitation }}% precipitation)
{%- endif %}
Calendar "{{ state_attr(calendar_entity_1, 'friendly_name') }}" events for the next {{ calendar_duration.hours }} hours:
{%- set agenda = (agenda_1 | items | first)[1] %}
{%- 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.description is defined %}
Description: {{ event.description }}
{% endif -%}
{%- if event.location is defined %}
Location: {{ event.location }}
{% endif -%}
{%- endfor %}
{%- else %}
- No upcoming events.
{%- endif %}
{%- if (calendar_number == "two") or (calendar_number == "three") %}
Calendar "{{ state_attr(calendar_entity_2, 'friendly_name') }}" events for the next {{ calendar_duration.hours }} hours:
{%- set agenda = (agenda_2 | items | first)[1] %}
{%- 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.description is defined %}
Description: {{ event.description }}
{% endif -%}
{%- if event.location is defined %}
Location: {{ event.location }}
{% endif -%}
{%- endfor %}
{%- else %}
- No upcoming events.
{%- endif %}
{%- endif %}
{%- if (calendar_number == "three") %}
Calendar "{{ state_attr(calendar_entity_3, 'friendly_name') }}" events for the next {{ calendar_duration.hours }} hours:
{%- set agenda = (agenda_3 | items | first)[1] %}
{%- 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.description is defined %}
Description: {{ event.description }}
{% endif -%}
{%- if event.location is defined %}
Location: {{ event.location }}
{% endif -%}
{%- endfor %}
{%- else %}
- No upcoming events.
{%- endif %}
{%- endif %}
{{ prompt }}
agent_id: !input conversation_agent
response_variable: agent
- alias: "Send notification"
service: !input notify_service_1
data:
title: "{{ now().strftime('%A') }} Agenda"
message: "{{ agent.response.speech.plain.speech }}"
- if:
- condition: template
value_template: "{{ (notify_number == 'two') or (notify_number == 'three') }}"
then:
- alias: "Send notification"
service: !input notify_service_2
data:
title: "{{ now().strftime('%A') }} Agenda"
message: "{{ agent.response.speech.plain.speech }}"
- if:
- condition: template
value_template: "{{ notify_number == 'three'}}"
then:
- alias: "Send notification"
service: !input notify_service_3
data:
title: "{{ now().strftime('%A') }} Agenda"
message: "{{ agent.response.speech.plain.speech }}"