I’m missing something very obvious because I cannot figure this out and it seems like such an obvious use case it should almost be a checkbox option. I’ve got an automation that uses OpenAI Conversation. I say a sentence, do some magic, send it to OpenAI, it compiles a response. All that is working. All I want is for the response to reply in voice to the device that triggered the automation (a home assistant voice assist preview edition in my case). Im sure you all do this and I’m just picking the wrong action or something. Can someone show me the way?
Post the automation.
Here’s the automation but this is just the latest iteration that didn’t work. I also tried entity_id: “{{ trigger.entity_id }}” and it didn’t like that. I’m sure this is a really dumb mistake on my part but I can’t find any examples online (which tells me I’m doing it wrong).
alias: Forecast Tomorrow
description: ""
triggers:
- trigger: conversation
command:
- What's the forecast for {day_of_week}
conditions: []
actions:
- action: weather.get_forecasts
target:
entity_id: weather.xxxx
data:
type: twice_daily
response_variable: twice_daily
- action: conversation.process
metadata: {}
data:
text: >-
The weather forecast for my area for the next 14 periods
measured twice daily (so seven days of forecasted weather) is below. You
will determine which period to use to answer the question based on
today's date and which day of week the user is asking for, in this case
"{{ trigger.slots.day_of_week }}".
Each data period will include an is_daytime boolean. If it is false,
then the temperature and conditions for that period represent the
overnight conditions and low temperature. If the boolean is returning
true, then it represents the daytime conditions and high temperature.
Here is the data: "{{ twice_daily['weather.xxxx'].forecast }}". Once you
determine which data point relates to "{{ trigger.slots.day_of_week }}",
speak the forecast for that day. Be succinct. Give only the Fahrenheit
temperatures. Do not include disclaimers about weather changing.
agent_id: conversation.chatgpt
response_variable: chatgpt
- action: assist_satellite.announce
data:
device: "{{ trigger.device_id }}"
message: "{{ chatgpt.response.speech.plain.speech }}"
preannounce: false
mode: single
I don’t use AI, so this may not be correct… but for my Sentence-trigger based automations I generally use the set_conversation_response
action not assist_satellite.announce
. So, that would be the first thing I would try.
If that doesn’t work, check the automation’s trace to see if the assist_satellite.announce
action is actually being fired and what it, if anything, it is doing. It’s possible that the action is executing, but the chatgpt
variable isn’t populated, so you may need to use a wait action.
FWIW, you can do some pre-processing using templates to get the desired forecast to save yourself some tokens…
...
- variables:
day_of_week: "{{ trigger.slots.day_of_week | title }}"
merged: "{{merge_response(twice_daily)}}"
forecast: |
{%- macro weekday(dt_string) %}
{{- (dt_string|as_datetime).strftime('%A') }}
{%- endmacro %}
{% if day_of_week == "Today" %}
{{merged[0]}}
{% elif day_of_week == "Tomorrow" %}
{{merged | selectattr('datetime', 'match', (today_at()+timedelta(days=1)).date() | string) | first}}
{% else %}
{{ merged[(merged | map(attribute='datetime') | map('apply', weekday) | list).index(day_of_week)] }}
{% endif %}
...
Thanks for the tip on the pre-processing. I’ll play around with it. So if I use set_conversation_reponse do I not need to worry about where I’m directing it because it assumes the triggering device that originated the conversation?
Yes, it sends the response back to the initiating device.
That worked! I knew it was something like that. Most of the YouTubes I watched were using the Assist satellite: Announce action so I figured I must be doing it wrong. Thanks again!