I would like to modify or replace this script to allow me to select from a list of messages rather than just send the one. The “message number” can be an entity or attribute value…whichever is easier.
The following is also working, but again, only one message.
sequence:
- service: notify.alexa_media_ma_office
data_template:
message: 'Current outside temperature is {{ states(''sensor.acurite_temperature_3'')
}} degrees the humidity is {{ states(''sensor.acurite_humidity_3'')
}} percent:::: and it feels like {{ states(''sensor.comfort'')
}} degrees'
target: media_player.ma_office
data:
type: tts
I’ve seen examples where people select random messages, but haven’t found one where you can select which message to send.
how about an input_select you read from to select your message?
Then you based on the value of input_select you can do an if then else or better still wait for 0.113 and use the choose function…
#script:
speak_wakeup_message:
alias: Speak Wakeup Message
description: 'Make Alexa speak a specified wakeup message."
fields:
msg_no:
description: 'The message number to be spoken. The number 0 represents the first message.'
example: 1
sequence:
service: notify.alexa_media_ma_office
data_template:
data:
type: tts
target: media_player.ma_office
message: >
{% set messages =
[ "Good morning Doug!",
"Welcome back!",
"Good to see you again!",
"It's carpe diem time!" ] %}
{{ messages[msg_no] if 0 <= msg_no < messages|length else "I'm sorry Dave but I can't do that." }}
The script contains a list of messages. When you call the script, you specify which message you want to play. If you specify an invalid number (anything less than 0 or greater than the number of items in the list, which is zero-based) it will play the HAL 9000 message.
For example, if you wanted the script to play the third message (“Good to see you again!”) you would call it like this: