Hi All,
My apologies ahead of time for the long post, but I want to make sure I provide as much info as possible.
I have a script that currently runs as a Alexa scene to change my TV Live stream channel on my Roku device, and it works great!
Now I have several Roku devices in the house, and Alexa devices in each room.
I would like to take this script further by having it detect which Alexa device heard me, and depending on the Alexa device, populate a variable for my entity_id’s in the script with the proper Roku device.
Example: From my bedroom, “Alexa, turn on Hallmark Channel”, and Alexa runs the script. The script determines which Alexa device was called, and the entity_id is passed to a variable to make sure the correct Roku device has the channel changed.
I have done some research, and see that this can be accomplished using Alexa last_called attribute for the Alexa devices.
I already have a echo group yaml created for my Alexa devices:
echos:
name: All Echos
entities:
- media_player.master_bedroom_echo
- media_player.living_room_echo
- media_player.kitchen_echo_show
- media_player.guest_room_echo
- media_player.family_room_echo_dot
And have a sensor created:
template:
- sensor:
- name: last_alexa
state: >
{{ expand('group.echos') | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}
availability: >
{{ expand('group.echos') | selectattr('attributes.last_called','eq',True) | first is defined }}
My issue is that I just can’t seem to figure out how to make this work in my script.
What I do know is that the code should be placed before the if statement is called.
I have read through some posts, but I am unable to find anything close enough to what I am trying to do.
Here is my current script:
hallmark_channel:
alias: Hallmark Channel
sequence:
- if:
- condition: not
conditions:
- condition: state
entity_id: media_player.roku_streambar
attribute: app_name
state: Frndly TV
then:
- service: media_player.play_media
target:
entity_id: media_player.roku_streambar
data:
media_content_id: '298229'
media_content_type: app
metadata:
title: Frndly TV
thumbnail: !secret roku_streambar_thumbnail
media_class: app
children_media_class:
navigateIds:
- {}
- media_content_type: apps
media_content_id: ''
- delay:
hours: 0
minutes: 0
seconds: 6
milliseconds: 0
- service: remote.send_command
data:
command: down
num_repeats: 3
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: select
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: select
target:
entity_id: remote.roku_streambar
else:
- service: remote.send_command
data:
command: down
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: down
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: down
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: select
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 6
milliseconds: 0
- service: remote.send_command
data:
command: down
num_repeats: 3
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: select
target:
entity_id: remote.roku_streambar
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: remote.send_command
data:
command: select
target:
entity_id: remote.roku_streambar
mode: single
Can someone possibly point me in the right direction to get to my goal?
Any advice and help would be much appreciated.
Thanks in advance