I’m just starting to work with Home Assistant and I’m trying to work through some basics, but I’m having trouble. I’ve been at this for many hours, and I just can’t figure it out. What I’m doing seems simple, but I just can’t seem to glean the correct information from the documentation…
I want to turn off my TV and mute my receiver.
I have LIRC (working) for turning off my TV (and frankly, I could do the same thing for my receiver, but that’s just working around the problem instead of trying to understand what I’m doing).
#Lirc shell command:
shell_command:
tv_power: irsend send_once tv key_power
I have a Yamaha receiver that has entity_id: media_player.rxv477_b4f719. This receiver can be muted with media_player.volume_mute.
media_player.volume_mute takes the entity_id and the is_volume_muted value.
I imagine there are a number of ways to do this, but I first tried adding a template after “sequence:”. When that didn’t work, I tried to add a template to the data. When that didn’t work, I tried to simply template the value passed into is_volume_muted.
test1:
alias: TV Toggle
sequence: >
{% if is_state_attr("media_player.rxv477_b4f719", "is_volume_muted", "true") %}
- service: shell_command.tv_power
- service: media_player.volume_mute
data:
entity_id: media_player.rxv477_b4f719
is_volume_muted: "true"
{% else %}
- service: shell_command.tv_power
- service: media_player.volume_mute
data:
entity_id: media_player.rxv477_b4f719
is_volume_muted: "false"
{% endif %}
Next attempt:
test2:
alias: TV Toggle
sequence:
- service: shell_command.tv_power
- service: media_player.volume_mute
data_template: >
{% if is_state_attr("media_player.rxv477_b4f719", "is_volume_muted", "true") %}
entity_id: media_player.rxv477_b4f719
is_volume_muted: "true"
{% else %}
entity_id: media_player.rxv477_b4f719
is_volume_muted: "false"
{% endif %}
Next attempt:
test3:
alias: TV Toggle
sequence:
- service: shell_command.tv_power
- service: media_player.volume_mute
data_template:
entity_id: media_player.rxv477_b4f719
is_volume_muted: {{ states.media_player.rxv477_b4f719.attributes.is_volume_muted == False }}
In addition to these 3 attempts, I tried countless variations on formatting; most of which seemed congruous with the online documentation. Very frustrating.
I’ve reviewed the templates in the dev tool, and in each case it seems to give me the values I want. I’m thinking there’s something wrong with my syntax, but I just cannot figure it out in the documentation or through many searches through google and this forum. Help would be greatly appreciated.
Errors in the log (with some exceptions) say something to the effect of expected… got “{” (leading me to believe the initial curly bracket of the template is getting parsed in the yaml - meaning I formatted the template wrong somehow) or in the case of the last one: invalid key: “OrderedDict([(‘states.media_player.rxv477_b4f719.attributes.is_volume_muted == False’, None)])”.
Thanks!