Volume_Down Multiple times in one service call

I’m trying to hack setting my Roku Volume. I now “how” i can do it by setting volume down multiple times (perhaps 100) and then up to set-point, but I don’t want to make 100 “volume down” service calls. There has to be a way to script the volume up/down portion so it’s mutiple steps/service calls in one configuration. Any ideas?

Well… I waited hopeing there was a better way, but got frusterated and just copied the service call 100x for volume down and X times for volume up and learned about splitting the configs as I didn’t want my scripts.yaml to look horrible.

I added the following to configuration.yaml

#script: !include scripts.yaml
#script: !include_dir_named scripts/
script: !include_dir_merge_named scripts/

then inside /scripts/{voldown100.yaml & volup20.yaml}

Eg:

voldown100.yaml

'100voldown':
  alias: VolDown100
  sequence:
  - data: {}
    entity_id: media_player.freesoftwareservers
    service: media_player.volume_down
  - data: {}
    entity_id: media_player.freesoftwareservers
    service: media_player.volume_down

x 100 repeats

And volume up is the opposite!

There has got to be a better way, but I don’t really understand yaml and how this coding language works TBH.

I won’t be accepting my answer as copying code blocks 100x is NOT what I was hoping to do. Here is where I will be updating on my site for what it’s worth.

https://www.freesoftwareservers.com/display/FREES/Split+Scripts+into+Multiple+Files+in+Directory+with+Home-Assistant

I don’t have a Roku but I suppose it’s a media player in HA so can’t you use the set volume or volume set. Not sure which it’s called.

@Hellis81 that’s correct because Roku API has no current volume/set volume function. But I just hated pasting 100x the same three lines of code. Felt like I was in high school!! This looks promising and I will update when I get around to cleaning up my code and the loop function is available.

Hazzarr!! Thanks @123 for the help I trimmed it down to the following and added the ability to pass volume up as an argument to the volume up script. Volume down will always be 100.

cat << 'EOF' >volup.yaml
  volup:
    sequence:
      repeat:
        count: '{{ count }}'
        sequence:
          - service: media_player.volume_up
            entity_id: media_player.freesoftwareservers
EOF

And:

cat << 'EOF' >voldown100.yaml
  100voldown:
    sequence:
      repeat:
        count: 100
        sequence:
          - service: media_player.volume_down
            entity_id: media_player.freesoftwareservers
EOF

https://www.freesoftwareservers.com/display/FREES/Roku+TV+-+Set+Volume+-+Home-Assistant

It can but you’re not taking advantage of it.

In the forum’s Editor menu, look for the icon that looks like this: </>
Select your code, then click that icon.

1 Like

@123 guess I was using the “Block Quote” button… I thought for sure I was doing it wrong, it sorta looked like a code block, but with bad formatting. I’ll admit I was way wrong on that one. Thankz again.

1 Like

Interesting solution for changing the volume up or volume down on the Roku device - thank you

Have you been able to find or develop any other workable solutions since last year ?
My biggest issue (at least for me) is how long it takes to make 100x calls to my Roku. Seems to be just over 5 minutes.
Thanks again

Update - Something I forgot to mention above…

  • Volume Down: appears to be a 1:1 ratio, by that I mean if you want to decrease your volume by 10, the count in your code should be 10.
  • Volume Up: appears to be a 2:1 ratio, if you want to increase the volume to 10, then the count in your code should be 20. Don’t ask me why that’s the way is is on mine.