I’ve been really struggling with a mystery of an automation I have tried to create not working.
I want to be able to set the sound mode of my AVR based on the type of content playing on a particular media player (a chromecast). The following script works, confirming that the sound mode can be changed:
denon_moviemode:
alias: Set Denon sound mode to movie
sequence:
- service: media_player.select_sound_mode
data:
entity_id: media_player.denon
sound_mode: 'MOVIE'
But this script does not work:
denon_automode:
alias: Set Denon sound mode automatically
sequence:
- service: media_player.select_sound_mode
data_template:
entity_id: media_player.denon
sound_mode: >-
{%- if states.media_player.terrorcast.attributes.media_content_type == 'music' -%}
'MCH STEREO'
{%- else -%}
'MOVIE'
{% endif %}
I’ve been able to confirm that the if statement is working as expected - either ‘MOVIE’ or ‘MCH STEREO’ shows up in the following error:
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 289, in _handle_service_platform_call
await getattr(entity, func)(**data)
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/media_player/denonavr.py", line 338, in select_sound_mode
return self._receiver.set_sound_mode(sound_mode)
File "/srv/homeassistant/lib/python3.6/site-packages/denonavr/denonavr.py", line 1464, in set_sound_mode
self._sound_mode_raw = self._sound_mode_dict[sound_mode][0]
KeyError: "'MOVIE'"
I have suspicions that this could be a whitespace issue causing the key ‘MOVIE’ or ‘MCH STEREO’ to not be able to be found in a dictionary that maps to the correct sound_mode_raw. But I’ve tried all sorts of things with no success.