Media_player.volume_set with volume_level: 0.29 fails

I can not get any media player to land on a volume level of 0.29, it persistantly rounds down to 0.28.

I discovered this when I created a script to fade the volume to target volume over x amount of seconds in a repeat: loop and tested fading up from below 0.28 to anything above than 0.29, the traces timeline would stick at trying to set it to 0.29. So I created an event: action to catch the data in case my logic was off and “listened” for it in dev tools, this is when I discovered it was in an endless loop trying to set the volume to 0.29.

Poor dev tools got l l a a g g g g y y A F.

Next step was to try and set the volume via dev tools > actions, that failed and rounded to 0.28. Then I powered on all available media_player entities, 3 native Music Assistant (1 Airplay and 2 Chromecast) and 2 native Google Cast, queued them up in dev tools > actions, and hit submit… not one of them landed on 0.29.

Like W.T.F? In dev tools > states Music Assistant entities showed volume_level: 0.28 and Google Cast entities showed volume_level: 0.28999999165534973 (which I thought odd considering that I’m filtering with |round(2).

Anyone else have this? Anyone have any insight? Help appreciated, thanks.

Dev tools > actions yaml:

action: media_player.volume_set
target:
  entity_id:
    - media_player.livingroom_stereo
    - media_player.wiim_with_chromecast
    - media_player.nest_mini
    - media_player.living_room_speaker
    - media_player.livingroom_sound
data:
  volume_level: "{{ (0.29)|round(2) }}"

Script issue was discovered in:

script:
  fade_volume:
    alias: "Fade Volume"
    description: "Fade Volume Over Time -
      Required:
      `player: media_player.id`
      Optional:
      `duration: seconds` (default: 10)
      `target_volume: 0 - 1` (default: 0)"
    sequence:
      - if: "{{ player is not defined }}"
        then:
          stop: "The action `script.fade_volume` requires `player: media_player.id` to be passed to it within the `data:` object"
      - variables:
          # Define optional input values
          target_volume: "{{ target_volume|float if target_volume is defined else 0 }}"
          duration: "{{ duration|int if duration is defined else 10 }}"
          # Define dynamic values
          start_volume: "{{ state_attr(player, 'volume_level') }}"
          range: "{{ (start_volume - target_volume if start_volume is greaterthan target_volume else target_volume - start_volume)|round(2) }}"
          delay: "{{ ((duration * 1000) / ((range * 100) if range is lessthan 0.51 else (range * 50)))|round }}"
          step: "{{ 0.01 if range is lessthan 0.51 else 0.02 }}"
          direction: "{{ 'up' if target_volume is greaterthan start_volume else 'down' }}"
      - if: "{{ direction is equalto 'down' }}"
        then:
          - repeat:
              until: "{{ state_attr(player, 'volume_level') <= target_volume }}"
              sequence:
                - event: TEST_VARIABLES
                  event_data:
                    volume: "{{ state_attr(player, 'volume_level') }}"
                    target_volume: "{{ target_volume }}"
                    current_volume_set: "{{ state_attr(player, 'volume_level') - step }}"
                    step: "{{ step }}"
                - action: media_player.volume_set
                  target:
                    entity_id: "{{ player }}"
                  data:
                    volume_level: "{{ (state_attr(player, 'volume_level') - step)|round(2) }}"
                - delay:
                    milliseconds: "{{ delay }}"
        else:
          - repeat:
              until: "{{ state_attr(player, 'volume_level') >= target_volume }}"
              sequence:
                - event: TEST_VARIABLES
                  event_data:
                    volume: "{{ state_attr(player, 'volume_level') }}"
                    target_volume: "{{ target_volume }}"
                    current_volume_set: "{{ (state_attr(player, 'volume_level') + step)|round(2) }}"
                    step: "{{ step }}"
                - action: media_player.volume_set
                  target:
                    entity_id: "{{ player }}"
                  data:
                    volume_level: "{{ (state_attr(player, 'volume_level') + step)|round(2) }}"
                - delay:
                    milliseconds: "{{ delay }}"
      - if: "{{ state_attr(player, 'volume_level') is not equalto target_volume }}"
        then:
          - action: media_player.volume_set
            target:
              entity_id: "{{ player }}"
            data:
              volume_level: "{{ target_volume }}"

Does Dev Tools give you an error with this?

action: media_player.volume_set
target:
  entity_id:
    - media_player.livingroom_stereo
    - media_player.wiim_with_chromecast
    - media_player.nest_mini
    - media_player.living_room_speaker
    - media_player.livingroom_sound
data:
  volume_level: 0.29

There is no error, not even in my logs… it simply refuses to land on 0.29. And it doesn’t matter how I set the value, using

action: media_player.volume_set
target:
  entity_id:
    - media_player.livingroom_stereo
    - media_player.wiim_with_chromecast
    - media_player.nest_mini
    - media_player.living_room_speaker
    - media_player.livingroom_sound
data:
  volume_level: 0.29

It still rounds down…



This is from just now. Are you able to set a media player volume to 0.29? Is it really just me? I’m perplexed.

have you tried a multiplier

{{ (state_attr('media_livingroom_stereo', 'volume_level') *100) | round(0)}}

to represent a percentage?

In what way? dev tools > actions won’t accept that as input (tried {{ (state_attr('media_player.livingroom_stereo', 'volume_level') *100) | round(0) + 1 }} and {{ (state_attr('media_player.livingroom_stereo', 'volume_level') *100) | round(0) + 0.01 }}), which makes sense as it would evaluate to 29 and media players have a max volume value of 1.

Besides setting the volume by any standard supported way works for every other value that I’ve tried, just not 0.29.

action: media_player.volume_set
data:
     volume_level: "{{ (state_attr('media_player.livingroom_stereo', 'volume_level')  *100) /100 }}"
target:
  entity_id: media_player.xxxxxxx

Use a second device for the target to see if they sync

Works for me across two devices

It may only serve as cold comfort but I observed the same behavior.

I set one of my Sonos speakers to the following volume levels using media_player.volume_set (via Developer Tools → Actions).

0.09
0.19
0.29
0.39
0.49

All values were successfully set except for 0.29. The speaker’s volume level reported 0.28 (in Developer Tools → States). :thinking: :man_shrugging:

I can get .29 on my LG monitor

Dev tools shows volume_level: 0.29

odd?? Step value issue when addressing multiple devices?

I think it is a device specific issue. My Nvidia Shield won’t do .29

The spread is .7

Your screenshot shows the result of a template.

After executing the action, go to Developer Tools → States and confirm that the value of volume_level is 0.29 for media_player.monitor.

If it is 0.29 then it may imply the speaker’s underlying integration may be responsible for the quirk that the OP and I have observed.

The OP appears to be observing the quirk for speakers based on several integrations.

I did Dev tools shows volume_level: 0.29

Then it may have something to do with how the value is handled by the integration. For your monitor’s integration, it doesn’t “tweak” 0.29.

Agreed. My android cast devices act completely different than the LG TVs.

No it steps by .01

I can get .27, .28, .29, .30 etc…

Me too. It reliably increments by 0.01 except for 0.29 which it reports as 0.28. Odd little quirk.

I’ll try merging a few media devices with different step values and see what I get.

Yes quirky

Well good to know it’s not just me, I can add a work around for this silly little niggle. Interestingly I just discovered that I can get it to 0.29 using media_player.volume_up and media_player.volume_down from plus or minus 0.5 of the target, just won’t work with media_player.volume_set.

Have you tried grouping the devices via a Helper?

FWIW, if I set it to 0.27 and then execute media_player.volume_up it increases by 0.02 and reports 0.29.

It’s possible to make it report 0.29 just not conveniently via media_player.volume_set. Odd little quirk indeed.

Nope I had no need for it as I really only use my WiiM into my full stereo to listen to music. Only tried the others because it borked on me, one at a time at first then as a list.

No worries, it doesn’t play well with groups that have different volume steps.

I think all devices need to be on a level playing field or the volume set action struggles