Hi,
I have a script that when someone rings the front door bell, if my TV is on, I get the live footage of the frontdoor in my TV. After a timeout, it will switch source back to ‘whatever it was’ and pause the broadcast (since my TV resumes it by default when the source is changed). I am setting an input_text that holds the last_source before it changes to the live cam. The script works but it does not change the source back to “Netflix, YouTube, etc.”, it pauses the live footage instead so I can tell that it reached to the end.
When I check {{ states(‘input_text.last_source’) }} in developer tools > template after running the script, I see that the value is indeed the last boradcast service I was watching. However, when I call the service below in developer tools > services;
- service: media_player.select_source
data_template:
source: input_text.last_source
target:
entity_id: media_player.living_room_tv
I get an error that says value should be string for a dictionary value @data[‘source’]. I’ve tried different combinations with data:, data_template: but none of them seem to be working. When I put “Netflix” in the source and call it, it switches to Netflix as expected. So, I guess, I cannot pass the variable input_text.last_source to the media_player.select_source as string. I thought calling the “input_text” value in the source of media_player.select_source would be enough because the value itself is already a string.
Here is my script. What am I missing here?
alias: show frontdoor live in the TV
sequence:
- service: input_text.set_value
data:
value: '{{ state_attr(''media_player.living_room_tv'', ''source'') }}'
target:
entity_id: input_text.last_source
- service: camera.play_stream
data:
media_player: media_player.chromecastultra
entity_id: camera.frontdoorcam
- wait_for_trigger:
- type: not_opened
platform: device
device_id: d5ceadbb0db67454bd03f5ce1c703af6
entity_id: binary_sensor.openclose_3
domain: binary_sensor
continue_on_timeout: true
timeout: '10'
- service: media_player.select_source
data_template:
source: input_text.last_source
target:
entity_id: media_player.living_room_tv
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: media_player.media_pause
target:
entity_id: media_player.living_room_tv
mode: single