Hi
I wanted to make automation that would change my AVR (Yamaha) to HDMI2 for specific source on TV (LG CX) and to HDMI1 on any other source. I crafted automation that you see below but it doesn’t work - I’m getting errors in log…I’m clearly doing something wrong here but I’m not sure what exactly.
- id: 'avrsourceontv'
alias: AVR Source from TV
description: 'Change AVR source based on TV source'
trigger:
- platform: state
entity_id: media_player.lg_webos_smart_tv_2
attribute: source
action:
- service: media_player.select_source
data:
entity_id: media_player.yamaha_receiver
source: >
{% if is_state_attr('media_player.lg_webos_smart_tv_2', 'source', 'Panasonic') -%}
hdmi2
{%- else -%}
hdmi1
{%- endif %}
I think those two errors are relevant to this automation:
2021-02-10 20:00:29 ERROR (MainThread) [homeassistant.components.automation.avr_source_from_tv] AVR Source from TV: Error executing script. Unexpected error for call_service at pos 1:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 595, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 632, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 640, in async_select_source
await self.hass.async_add_executor_job(self.select_source, source)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/yamaha/media_player.py", line 357, in select_source
self.receiver.input = self._reverse_mapping.get(source, source)
File "/usr/local/lib/python3.8/site-packages/rxv/rxv.py", line 259, in input
assert input_name in self.inputs()
AssertionError
2021-02-10 20:00:29 ERROR (MainThread) [homeassistant.components.automation.avr_source_from_tv] While executing automation automation.avr_source_from_tv
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 404, in async_trigger
await self.action_script.async_run(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1033, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 246, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 254, in _async_step
await getattr(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1455, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1490, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 595, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 632, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 640, in async_select_source
await self.hass.async_add_executor_job(self.select_source, source)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/yamaha/media_player.py", line 357, in select_source
self.receiver.input = self._reverse_mapping.get(source, source)
File "/usr/local/lib/python3.8/site-packages/rxv/rxv.py", line 259, in input
assert input_name in self.inputs()
AssertionError