Volume set - expected float for dictionary value

Hi

I’m trying to change the volume on a media player from the UI, in a tap_action of a mushroom chips card. I have tried multiple configs, as there are many posts about this kind of issue over the forum, but I can’t get it figured out.

The default media_player.volume_up uses steps of 10% with my speakers, thus going from 5% to 15%. There seems to be no way to adapt this step size from the UI menu’s as far as I can see.
There’s the option to create a script, but I would like to have everything in the UI config itself instead of having scripts of just 2 lines. This means I end up with this code:

type: custom:mushroom-chips-card
chips:
  - type: entity
    entity: media_player.beneden
    hold_action:
      action: none
    double_tap_action:
      action: none
    tap_action:
      action: perform-action
      perform_action: media_player.volume_set
      target:
        entity_id: media_player.beneden
      data:
        volume_level: {{ (state_attr("media_player.beneden", "volume_level")|float(0) + 0.05)|round(2) }}

When using a fixed value for the volume_level in data, it works perfectly fine and the volume changes to that specific value. I want to increase per 5% (0.05 in this case), so I read the current volume and add 0.05 to it.

This gives me the classic error:

Failed to perform the action media_player/volume_set. expected float for dictionary value @ data[‘volume_level’]

How do I solve this issue? There had been solutions to use data_template, but since that’s deprecated I can’t seem to figure out how to get this to work.

Thanks in advance!

I think in a tap action templates are not allowed. Maybe set up a script and call that?

You’re doing 2 things wrong.

  1. Templates typically aren’t usable in the frontend as Edwin eluded.
  2. If you were able to use templates, your template would need to be quoted.

So, with that being said, do what Edwin is suggesting. Make a script and call the script.

You can even make it generic.

volume_up:
  fields:
    media_player:
  sequence:
  - action: media_player.volume_set
    target:
      entity_id: "{{ media_player }}"
    data:
      volume_level: "{{ state_attr(media_player, "volume_level") + 0.05 }}"

then

type: custom:mushroom-chips-card
chips:
  - type: entity
    entity: media_player.beneden
    hold_action:
      action: none
    double_tap_action:
      action: none
    tap_action:
      action: perform-action
      perform_action: script.volume_up
      data:
        media_player: media_player.beneden