your automation doesn’t have the is_volume_muted attribute. If you read the error it says "required key not provided ‘is_volume_muted’. Take a look at your automation/script and verify that it still exists.
Also, this is a streamlined version of @bbrendon’s method.
I really wasn’t able to understand the error message. So in my case is the denonavr component that is not supplying the is_volume_muted attribute? It should, as it is listed and has a value in its states list:
Sorry for that, my mistake copying/pasting here at the forum. In the code that’s actually running it was correct, but still doesn’t work.
Or I’m doing something really wrong, or denonavr component is unable to read the parameter from the device, no matter the flavour of the code in the template - the original if/then/else/endif statement or your more elegant way negating the attribute value.
The states dev-tools page can see the correct parameter value, so it’s there!!
Thanks for your help, I’ll continue looking into this.
The service will be called correctly, obviously muting or unmuting according to what is passed on the is_volume_mute parameter.
When replacing service_data for data_template and writing an expression that must be evaluated on is_volume_mute then it stops working. For some reason the code is not being interpreted.
So I’m trying to do this via an automation but it doesn’t seem to work - I’m trying to toggle mute when an ad plays when I’m listening to music. However, when I use the above on a call_service call in the automation, I get the following error:
Error while executing automation automation.mute_music_when_ad_plays. Invalid data for call_service at pos 2: invalid boolean value {{ not state_attr('media_player.front_rooms', 'is_volume_muted') }} for dictionary value @ data['is_volume_muted']
but as this would toggle mute, I don’t want to hard code a value for is_volume_muted
Yep, then it’ll work. Also put your entity_id inside data_template too.
EDIT: To clarify…
Whenever you use a template {{ }} or {% %} etc, you need to use it in a template field. data is not a template field, data_template is. It essentially tells home assitant to treat all fields inside data_template as templates. It doesn’t matter if the field is a template or not.
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']