Media Player volume up/down steps - JSON problem help please!

Hi,

I’m using a JSON payload to control volume on a media player. The volume_up and volume_down attributes move the volume in 10% increments. I’d like to change this to 5% increments. I’m using the following JSON payload with the volume_set attribute for HA is throwing an error in my syntax. I’m using lots of other JSON API calls successfully so I know it’s not a problem with my authorization, etc. Can anyone tell me why this isn’t working:

/api/services/media_player/volume_set

{"entity_id": "media_player.ceiling_speakers", "volume_level": {{ state_attr('media_player.ceiling_speakers', 'volume_level') | float + 0.05} }}

Your template needs to be in quotes. You’re also missing the last }. This of course is assuming that the json you posted is your service data.

1 Like

Hi @petro

Thanks for the suggestions.

I updated as follows and am still getting an error

{"entity_id": "media_player.ceiling_speakers", "volume_level": "{{ state_attr('media_player.ceiling_speakers', 'volume_level') | float + 0.05}" }}

but still getting the same error. I don’t think I was missing any } in the original code…

I’m not sure what what you mean by “the JSON you posted is your service data”. Can you elaborate?

Thank you!

Your edits are wrong, it should look like this:

{"entity_id": "media_player.ceiling_speakers", "volume_level": "{{ state_attr('media_player.ceiling_speakers', 'volume_level') | float + 0.05 }}" }

1 Like

Thank you @petro again. It’s still throwing the same HTTP 400 error that I get when syntax is wrong.

Not sure what I’m doing wrong! I don’t think it’s a problem elsewhere because this payload works:

{"entity_id": "media_player.ceiling_speakers", "volume_level": 0.2}

how are you calling the service?

I’m using a network resource on an ISY, which is a home automation hub (mainly for insteon based networks). It is programmed to send an http POST request to the HA box on port 8123 to /api/services/media_player/volume_set with a 500 ms timeout using the c escaped characterset.

Other calls with the same programming (eg. volume set to 0.2) are working perfectly. I’m not sure why this one won’t work!

If anyone is looking into this in the future, I found a work around. For whatever reason this JSON call was not working but I made a script:

alias: CeilingVolDn
sequence:
  - data_template:
      volume_level: '{{ states.media_player.ceiling_speakers.attributes.volume_level - 0.05}}'
    entity_id: media_player.ceiling_speakers
    service: media_player.volume_set
mode: single

and I am able to call that script using the RESTful interface:

/api/services/script/turn_on

{"entity_id": "script.ceilingvoldn"}
1 Like