Ok, the goal I am trying to achieve is to create a Mute button for a Sonos device, where I can define which sonos device when creating the button. It seems that sonos devices to not respond well to the standard media_player.volume_mute as this funtion will only change the device to unmuted but when run again will not unmute, so…
I started by creating a script which when called would inquire as to whether the state attribute of a sonos device is curently muted or not and then change that attribute appropriately:
alias: Toggle Sonos Mute
sequence:
- alias: Toggle Sonos Mute
sequence:
- data_template:
entity_id: media_player.living
is_volume_muted: >
{% if is_state_attr('media_player.living', 'is_volume_muted', true)
%}
false
{% else %}
true
{% endif %}
action: media_player.volume_mute
description: ""
(sorry if poorly formatted - first post )
Once I had that up and running - I added form variables to the code and got this:
sequence:
- alias: Toggle Sonos Mute
sequence:
- data_template:
entity_id: "{{sonosdevice}}"
is_volume_muted: |
{% if is_state_attr('"{{sonosdevice}}"', 'is_volume_muted', true) %}
false
{% else %}
true
{% endif %}
action: media_player.volume_mute
alias: Toggle Sonos Mute
description: ""
icon: mdi:volume-mute
fields:
sonosdevice:
selector:
entity:
multiple: true
name: sonosdevice
description: Select Sonos device.
required: true
And it seems to work in as much as it will mute the device intended in the form when I create a button which when clicked will “Perform Action” of this script on the selected device, but it does not seem to be evaluating the embedded template?
{% if is_state_attr(‘“{{sonosdevice}}”’, ‘is_volume_muted’, true) %}
Does this have to do with the fact that this is an embedded template? What am I doing wrong? It seems like all the script does now is target the device listed in the entity_id: but no longer evaluates the true/false logic?
Thank you so much in advance, fairly new to HA and looking to expand my understanding. Any tips or better ways to attack this problem would be great.