Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save oquno/c94c0d25cf95bf3f720bd51aedbffd90 to your computer and use it in GitHub Desktop.

Select an option

Save oquno/c94c0d25cf95bf3f720bd51aedbffd90 to your computer and use it in GitHub Desktop.
Home Assistant script to adjust a media player's volume in small relative steps. Useful for fine-grained volume control from buttons, dashboards, or automations.
alias: Media Player Volume Fine Adjustment
description: >
Adjusts the volume of a selected media player in small increments.
The volume is increased or decreased relative to the current level
and clamped to the valid range (0.0–1.0).
icon: mdi:volume-high
mode: parallel
fields:
target_player:
name: Media Player
description: Media player entity to adjust the volume for
required: true
selector:
entity:
domain: media_player
volume_step:
name: Volume Step
description: "Volume change per execution (e.g. 0.01 = +1%, -0.01 = -1%)"
default: 0.01
selector:
number:
min: -1
max: 1
step: 0.01
mode: box
sequence:
- target:
entity_id: "{{ target_player }}"
action: media_player.volume_set
data:
volume_level: >
{# Get current volume level (fallback to 0 if unavailable) #}
{% set current = state_attr(target_player, 'volume_level') | float(0) %}
{# Requested adjustment step #}
{% set step = volume_step | float(0) %}
{# Calculate new volume level #}
{% set next_vol = current + step %}
{# Clamp to valid range (0.0–1.0) #}
{{ [ [next_vol, 1.0] | min, 0.0 ] | max }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment