I have a script that pauses an Amazon Firestick when run standalone, but does not work when called from another script. It pauses an LG TV OK. Copying the pause script into the other script does not work either.
In detail;
- I have an LG 65OLEDB9 television with an Amazon Firestick plugged into HDMI4. I mostly use the Firestick rather than LG apps because it is much better at interacting with Alexa (that is not the subject of this thread BTW!).
- Before HA I operated them both using a universal remote in a Smart Life scene called by Alexa.
- When I introduced HA, I put it between Alexa and Smart Life. For each Smart Life scene in HA I have a matching script to call it, to circumvent the bug (reported elsewhere) that Smart Life scenes are not persisted to Alexa over a system restart, whereas Scripts are.
- All scripts are exposed to Alexa via Nabu Casa and Alexa Media Player is used to play the responses (as notifications)
- More recently, I added both the LG TV and the Android TV (configured as Fire TV) integrations.
- The default dashboard cards work fine.
- Because I want âAlexa, TV Pauseâ to work for either the native TV apps or the Firestick, I wrote a script that tests the source, and then pauses the appropriate media player. That script works if I say âAlexa, TV pauseâ whilst playing either device.
- Now, I have a script âGoing to the toiletâ that lights the path to the toilet from the room in which the command is heard only if it is night time; if the room is Living Room and the TV is on it pauses it. A sister script âBack from the toiletâ turns the lights off again and plays the TV or Firestick if applicable.
- These scripts works fine if watching the TV on an LG app, but if watching via the Firestick, is is not paused or played. Uh??
BTW I only test that the TV is on because the test on status âplayingâ does not work with the LG TV.
- Night time sensor (works fine)
### Night time
- binary_sensor:
- name: Night time
unique_id: "99571c18-c3e5-4e2a-8e5e-94bc3f030ff9"
state: "{{ state_attr('sun.sun', 'elevation') < 10 }}"
- Pause script (works fine when run manually or called by Alexa)
ha_tv_pause:
alias: TV pause
sequence:
- choose:
- conditions:
- condition: state
entity_id: media_player.audrey_s_tv
attribute: source
state: Firestick
sequence:
- service: media_player.media_pause
data: {}
target:
entity_id: media_player.fire_tv
default:
- service: media_player.media_pause
data: {}
target:
entity_id: media_player.audrey_s_tv
mode: parallel
- Play script (works fine when run manually or called by Alexa)
ha_tv_play:
alias: TV play
sequence:
- choose:
- conditions:
- condition: state
entity_id: media_player.audrey_s_tv
attribute: source
state: Firestick
sequence:
- service: media_player.media_play
data: {}
target:
entity_id: media_player.fire_tv
default:
- service: media_player.media_play
data: {}
target:
entity_id: media_player.audrey_s_tv
mode: single
- Going to the toilet script (works with LG but fails to pause the Firestick)
going_to_the_toilet:
alias: Going to the toilet
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ states(''sensor.last_alexa_area'') == ''Main bedroom''}}'
sequence:
- if:
- condition: state
entity_id: binary_sensor.night_time
state: 'on'
then:
- service: notify.alexa_media_main_bedroom_echo
data:
message: I'm lighting the path for you. Let me know when you get back
and I'll turn the lights off again.
- service: light.turn_on
data: {}
target:
entity_id:
- light.path_to_toilet_from_main_bedroom
else:
- service: notify.alexa_media_main_bedroom_echo
data:
message: It's daytime now so you don't need the lights. Take care.
- conditions:
- condition: template
value_template: '{{ states(''sensor.last_alexa_area'') == ''Living room''}}'
sequence:
- if:
- condition: state
entity_id: binary_sensor.night_time
state: 'on'
then:
- if:
- condition: template
value_template: '{{ states(''media_player.audrey_s_tv'') == ''on'' }}'
then:
- service: notify.alexa_media_living_room_echo
data:
message: I'll pause the TV and light the path for you. When you get
back I'll turn the lights off again and restart the TV
- service: light.turn_on
data: {}
target:
entity_id: light.path_to_toilet_from_living_room
- service: script.ha_tv_pause
data: {}
else:
- service: notify.alexa_media_living_room_echo
data:
message: I'll light the way for you. Let me know when you get back and
I'll turn the lights off again.
- service: light.turn_on
data: {}
target:
entity_id: light.path_to_toilet_from_living_room
else:
- if:
- condition: template
value_template: '{{ states(''media_player.audrey_s_tv'') == ''on'' }}'
then:
- service: notify.alexa_media_living_room_echo
data:
message: 'I''ll pause the TV for you. Take care, and let me know when
you get back. '
- service: script.ha_tv_pause
data: {}
else:
- service: notify.alexa_media_living_room_echo
data:
message: 'Take care. See you soon. '
- conditions:
- condition: template
value_template: '{{ states(''sensor.last_alexa_area'') == ''Guest bedroom''}}'
sequence:
- if:
- condition: state
entity_id: binary_sensor.night_time
state: 'on'
then:
- service: notify.alexa_media_guest_room_echo
data:
message: I will light your path to the bathroom
- service: light.turn_on
data: {}
target:
entity_id: light.path_to_bathroom_from_guest_bedroom
else:
- service: notify.alexa_media_guest_room_echo
data:
message: 'Thanks for sharing, but I think you can find the bathroom without
my help. '
mode: parallel
icon: mdi:ceiling-light-multiple-outline
max: 10
- Back from the toilet script (works with LG but fails to play the Firestick)
back_from_the_toilet:
alias: Back from the toilet
sequence:
- choose:
- conditions:
- condition: template
value_template: '{{ states(''sensor.last_alexa_area'') == ''Main bedroom''}}'
sequence:
- if:
- condition: state
entity_id: binary_sensor.night_time
state: 'on'
then:
- service: notify.alexa_media_main_bedroom_echo
data:
message: 'OK, I''ll turn all the lights off again. Sleep well. '
- service: light.turn_off
data: {}
target:
entity_id: light.path_to_toilet_from_main_bedroom
else:
- service: notify.alexa_media_main_bedroom_echo
data:
message: Glad you made it. Welcome back.
- conditions:
- condition: template
value_template: '{{ states(''sensor.last_alexa_area'') == ''Living room''}}'
sequence:
- if:
- condition: state
entity_id: binary_sensor.night_time
state: 'on'
then:
- if:
- condition: template
value_template: '{{ states(''media_player.audrey_s_tv'') == ''on'' }}'
then:
- service: notify.alexa_media_living_room_echo
data:
message: OK I'll turn the lights back off. Relax and enjoy the TV show.
- service: light.turn_off
data: {}
target:
entity_id: light.path_to_toilet_from_living_room
- service: script.ha_tv_play
data: {}
else:
- service: notify.alexa_media_living_room_echo
data:
message: OK. I'll turn the lights off again and let you rest your eyes.
- service: light.turn_off
data: {}
target:
entity_id: light.path_to_toilet_from_living_room
else:
- if:
- condition: template
value_template: '{{ states(''media_player.audrey_s_tv'') == ''on'' }}'
then:
- service: notify.alexa_media_living_room_echo
data:
message: Good. Now relax and enjoy the programme.
- service: script.ha_tv_play
data: {}
else:
- service: notify.alexa_media_living_room_echo
data:
message: 'Glad to hear it. Have a great day. '
- conditions:
- condition: template
value_template: '{{ states(''sensor.last_alexa_area'') == ''Guest bedroom''}}'
sequence:
- if:
- condition: state
entity_id: binary_sensor.night_time
state: 'on'
then:
- service: notify.alexa_media_guest_room_echo
data:
message: OK. Lights out. Sleep tight.
- service: light.turn_off
data: {}
target:
entity_id: light.path_to_bathroom_from_guest_bedroom
mode: single
icon: mdi:ceiling-light-multiple