Can You please maka a step by step what did you done to make it work?
I cant make this button to work any way
Should I have some additional lines in config.yaml and/or automations.yaml ?
I also have Denon - but want to make a simple separate lovelace button to toggle and display MUTE state of my Denon media player. (or ALL of my media players)
Expected a value of type `{action,navigation_path,url_path,service,service_data} | undefined` for `tap_action.data_template` but received `{"entity_id":"media_player.denon","is_volume_muted":"{{ not state_attr('media_player.denon', 'is_volume_muted') }}"}`.
And info after pressing button:
Failed to call service media_player/volume_mute. required key not provided @ data['is_volume_muted']
Hi, can you please explain to me the syntax here?
What is ‘not state_attr’?
How do I know when to use it?
For example, if I want to toggle power, is it with the same string?
state_attr gets an attribute from an entity. The attribute mentioned in the other posts is_volume_muted is a boolean. This means the attribute is either true or false. When using the method state_attr to get is_volume_muted, it will return the value of the attribute; i.e. true or false. When adding the not in front of it, it inverts the true/false value. So true becomes false and false becomes true.
This depends on a lot. What are entity are you working with and what are you trying to create?
Regarding the power.
I have a denon receiver.
I want to create a script that toggle the power the same it toggles mute function.
Any idea what should the template compare?
But the error i get is the following when i push the button:
“Failed to call service media_player/volume_mute. invalid boolean value {{ not state_attr(‘media_player.living_room_speaker’, ‘is_volume_muted’) }} for dictionary value @ data[‘is_volume_muted’]”
So this to me suggests lovelace is accepting templates but the output of the template is not in the right format. Now when i go to the developer tools → templates and put this in, it is giving me the proper ‘True’ and ‘False’ but it also says that the result is a string as opposed to boolean. It almost suggests that the function “state_attr” is pumping out a string result and the button card is not accepting that string result. I also cannot see any way to convert it to a true boolean. I may try to convert it to 1 and 0 and see what happens there. Anyone run into this?
Hello @petro i have read some of your other posts in similar topics… Super helpful.
Ya i had may have tried what you provided there because i think i saw something you posted in another thread. I will try it again tho.
Its very strange. I have this working now but im using a script to do it (again this may have come from you):
mute_toggle:
fields:
media_player:
description: Media Player that will be mute or unmuted
sequence:
- service: media_player.volume_mute
target:
entity_id: "{{ media_player }}"
data:
is_volume_muted: "{{ not state_attr(media_player , 'is_volume_muted') }}"
So then i tried to do the same thing with a media_player toggle which should turn the media player (this case a google home) on and off. So i used a modification of the script like this (almost identical):
power_toggle:
fields:
media_player:
description: Media Player that will be toggled
sequence:
- service: media_player.toggle
target:
entity_id: "{{ media_player }}"
The weird thing is that it will only turn on the media_player but not turn it off. However, if i use the services developer tools and call the same media_player.toggle call with this same entity, it too will only turn it on but not off… HOWEVER if i create a basic entities card with teh media player (google home) and hit the power button on that (default media player i suppose), it will turn on and off all day long. There is something weird going on. I was thinking maybe it was a button card issue now but with the developer tools call not working now im not sure.