I have two scripts that work well individually, but I don’t understand how to make Alexa/HA understand that “media on” should run one script while “media off” should run another.
“alexa media on” results in Alexa replying “I have a couple’a things that share that name, ‘media off’ and ‘media on’, which one do you want?” I would like “alexa media on” to run the “media on” script directly.
configuration.yaml looks something like this:
alexa:
smart_home:
...
filter:
include_entities:
- script.media_devices_on
- script.media_devices_off
and scripts.yaml
has code like this in it:
media_devices_on:
alias: "media on"
description: "Turns on AMP, TV, and Media Boxes"
sequence:
...
...
media_devices_off:
alias: "media off"
description: "Turns off AMP, TV, and Media Boxes"
sequence:
...
...
I get the idea that this should be an “automation”, but I don’t see what the trigger and/or condition should be. Any advice is greatly appreciated. I am a stupid newbie, but I swear I have searched high and low.
Please note that I do need separate scripts because the devices need to be turned off in the reverse order from being turned on.
Thanks!
Kerry
Version: core-2021.11.5, Installation Type: Home Assistant Supervised
I use emulated hue to expose scripts to Alexa. I just call them alexa hook one, two, three etc, because removing them is a pain and this way I can repurpose easily if my needs change.
Then I create a routine in the Alexa app so that I can say “Alexa, ask Alfred to clean the kitchen” (or whatever pre arranged phrase I want) and it’ll call the script.
Makes for a much easier experience in my book, but ymmv.
When asking questions about Alexa + HA make sure to include what method you are using to expose Home Assistant to Alexa (Nabu Casa, HA Custom Alexa Skill, HAASKA, Emulated Hue, Node-Red, etc).
The two methods I have found work best to avoid getting that message from Alexa are to both done in the Alexa app. You can either add the device to the group with the Echo or set up a routine.
If you go the device-in-group option, you may want to create a template switch in Home Assistant, expose that switch to Alexa and then add it to the room group.
If you go the routine option you will need one routine for “turn on” and one for “turn off”. You can access your scripts in the Alexa routine editor under Add Action>Smart Home>Control Scene.
For the benefit of anybody else who might find this in their search result, here’s how I resolved it:
First, I turned my scripts into a switch:
switch:
- platform: template
switches:
lounge_media:
friendly_name: "media"
turn_on:
service: script.media_devices_on
turn_off:
service: script.media_devices_off
and then I exposed the switch to Alexa:
alexa:
smart_home:
...
...
filter:
include_entities:
- switch.lounge_media
So now I can say “Alexa, Media on”, or “Alexa, Media off”, and the appropriate script is executed. Hurrah!
5 Likes