Media Player Volume Sensitivity

Hi all

I have an Ikea Tradfri switch in one of my that I am in the process of setting up as a volume up/down controller for the Sonos ceiling speaker in that room. I have the following automation which works:

# Automation to handle Sonos Control by Bathroom Switch
- id: '1237'
  alias: 'Bathroom Switch Volume Up'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 1002
  action:
    - service: media_player.volume_up
      entity_id: media_player.bathroom
- id: '1238'
  alias: 'Bathroom Switch Volume Down'
  initial_state: 'on'
  trigger:
    platform: event
    event_type: deconz_event
    event_data:
      id: bathroom_switch
      event: 2002
  action:
    - service: media_player.volume_down
      entity_id: media_player.bathroom

Unfortunately, it takes a million button presses to make any meaninful difference to the volume level. The media_player volume_up/down methods do not seem to have any configuration for sensitivity. I was wondering what the best way of achieving this would be. Putting it in a script seems a bit messy and I would rather keep it in the YAML. Am I able to loop the action maybe so one button press triggers 5-10 volume up commands?

Any help much appreciated.

What about using volume_set service with a template which reads the current volume and adds 10 for the value part?

Do you have any kind of example of how I would go about this? I haven’t tried to build anything using templates yet

You could change your action to use media_player.set_volume instead of media_player.volume_up. Then you take the current state of the media players volume and add/subtract your desired value.

Something like this for increasing volume by 5 percent:

service: media_player.volume_set
entity_id: media_player.bathroom
data_template:
  volume_level: "{{ state_attr('media_player.bathroom', 'volume_level') | float + 0.05 }}"
7 Likes

Magic. That works perfectly. Thanks for your help @rak and @Burningstone

This could use a native data input such as “step_size”/“increment_size” where we can calibrate how much it goes up or down.

1 Like