text: !include alexa_confirm.yaml only works within the HA intent_script integration where there is
speech:
text: ...
It does not work for message: within an automation or script when calling the related service.
The intent_script integration works with Google, Home Assist (I think) or an Alexa custom skill you’ve created which has intents and where you have to say “Alexa, ask Home Assistant to…”.
Hi! Can anyone please post a working solution for random text pick for TTS, working with last HA release? It’s looks like it should be possible to use helpers for this purpose, but I was unable to create a working YAML.
Can anyone share a working solution? Thanks!
have this type of code in your TTS message section:
message: >
'{{ ["Kingsleys flea treatment is due", "Its that time again, Kingsley
wants his flea treatment chew", "Kingsley loves a good flea treatment.
The time has come"] | random }}'
Thank you for for your sample! However, it will be a mess to handle say 50 text entries. I believe it’s possible to utilize input-select helper to work with easy manageable list of entries.
You can split the text out so each one is on it’s own line which would neaten it up. Using an input text helper should be doable but I haven’t tried so don’t have an example. I’ll see if I can figure it out though.
yeah cool, but it’s not really much easier than my option, I mean you still can’t edit the list via the UI so a restart is likely required for any changes. I liked your idea of a text helper because it would mean editing from the frontend without any restart/reload required.
How can make it not saying the same option if it said it that before for example if it say “Halloween 1” the for the next 10 minutes not say it again. Thanks!!!
So I took slightly different approach to ‘random’, instead of building the list of predefined sentences, I ask OpenAI to generate message for me. This way I have one automation, but endless selection of random text. Here is sample code for entering/leaving specific zone.
- alias: zone ChatGPT TTS notifications
id: zone_chatgpt_tts_notifications
mode: queued
initial_state: true
trigger:
- platform: zone
entity_id: person.mirek_malinowski, person.dorota_malinowska
zone: zone.home
event: enter
- platform: zone
entity_id: person.mirek_malinowski, person.dorota_malinowska
zone: zone.home
event: leave
# More zones goes here
action:
- service: conversation.process
data:
agent_id: id_redacted
text: |
{% if (trigger.event) == "leave" %}
Prepare humorous notification about {{ trigger.to_state.attributes.friendly_name }} being now outside of {{ trigger.zone.attributes.friendly_name }}, using no more than 15 words and not using emoji.
{% else %}
Prepare humorous notification about {{ trigger.to_state.attributes.friendly_name }} being now close to {{ trigger.zone.attributes.friendly_name }}, using no more than 15 words and not using emoji.
{% endif %}
response_variable: chatgpt
- service: tts.cloud_say
data_template:
entity_id: media_player.google_home_mini
language: pl-PL
message: |
{{chatgpt.response.speech.plain.speech | trim | replace('\"','')}}
Would you consider pulling this chatgpt random script together into a ‘Community Guideline’ and adding it to the Cookbook we are creating here on the forums? The Home Assistant Cookbook - Index.
I think it would be a fantastic addition, and since it is your code and idea, I ddn’t want to just copy you to get it there.
(It might also make a really nice script blueprint to share as you already have the code debugged…)
Using @mirekmal’s example, I created a script called Get ChatGPT response with field values for parts of the chatgpt prompt so I can seamlessly reuse the script within my automations.
I couldn’t figure out how to pass the script response directly into another action, so I created an Input Text helper first to house the ChatGPT response each time.
alias: Get ChatGPT response
sequence:
- service: conversation.process
data:
agent_id: id_redacted
text: >-
Prepare a {{tone}} notification about "{{subject}}" using no more than
{{length}} words and not using any emoji.
response_variable: chatgpt
alias: ChatGPT Prompt
enabled: true
- service: input_text.set_value
metadata: {}
data:
value: "{{chatgpt.response.speech.plain.speech | trim | replace('\\\"','')}}"
target:
entity_id: input_text.chatgpt_response
fields:
subject:
selector:
text: null
name: subject
description: What do you want to do?
required: true
tone:
selector:
text: null
name: tone
description: Describes the tone you want to add to the ChatGPT request.
required: true
length:
selector:
text: null
name: length
description: How many words do you want to limit the response to?
default: "15"
required: true
icon: mdi:robot-excited
mode: single
In my automations, I first call the script above, then add the following template wherever I want to include the response: "{{ states('input_text.chatgpt_response') }}"