Implement a better method for setting volume
JeffLIrion opened this issue · 13 comments
You can use the command:
media volume --show --stream 3 --set X
... to change the volume where X is 0 - 15
@i00 thanks for posting that command, I was unaware of it. I've got a few questions. Why is --show
necessary? Is it always --stream 3
or is it sometimes a different number? And you said that x is 0 - 15, but some devices have a max volume of 40, I believe, so I assume that the range would be 0 - 40?
Could you post the output from this command:
dumpsys audio | grep 'STREAM_MUSIC:' -A 12
It looks like this post answers the questions I had: https://stackoverflow.com/a/52949888
darcy:/ $ dumpsys audio | grep 'STREAM_MUSIC:' -A 12
- STREAM_MUSIC:
Muted: false
Min: 0
Max: 15
Current: 2 (speaker): 9, 4 (headset): 10, 8 (headphone): 10, 80 (bt_a2dp): 10, 400 (hdmi): 15, 1000 (digital_dock): 10, 4000000 (usb_headset): 3, 40000000 (default): 15
Devices: hdmi
- STREAM_ALARM:
Muted: false
Min: 1
Max: 7
Current: 2 (speaker): 4, 4 (headset): 5, 8 (headphone): 5, 80 (bt_a2dp): 5, 400 (hdmi): 7, 1000 (digital_dock): 5, 4000000 (usb_headset): 1, 40000000 (default): 7
Devices: speaker, hdmi
- STREAM_NOTIFICATION:
darcy:/ $ media volume --show --stream 3 --set 2
[v] will control stream=3 (STREAM_MUSIC)
[v] will set volume to index=2
[v] Connecting to AudioService
darcy:/ $ dumpsys audio | grep 'STREAM_MUSIC:' -A 12
- STREAM_MUSIC:
Muted: false
Min: 0
Max: 15
Current: 2 (speaker): 9, 4 (headset): 10, 8 (headphone): 10, 80 (bt_a2dp): 10, 400 (hdmi): 15, 1000 (digital_dock): 10, 4000000 (usb_headset): 3, 40000000 (default): 15
Devices: hdmi
- STREAM_ALARM:
Muted: false
Min: 1
Max: 7
Current: 2 (speaker): 4, 4 (headset): 5, 8 (headphone): 5, 80 (bt_a2dp): 5, 400 (hdmi): 7, 1000 (digital_dock): 5, 4000000 (usb_headset): 1, 40000000 (default): 7
Devices: speaker, hdmi
- STREAM_NOTIFICATION:
darcy:/ $
dumpsys audio | grep 'STREAM_MUSIC:' -A 12
@JeffLIrion ... Sorry but I am not in a position to test that command right now
I know you found the answer to your other questions...
but just to summarize:
3 = media volume ... this appears to be the only volume that Android TV actually uses
I didn't realize that the max was different for different devices ... I have several and all are 15 ... I guess you should check the min and max beforehand as show in in @raman325 reply, just to be safe.
--show will show the volume on the TV (rather than just changing it with no on-screen feedback)
It looks like it didn't work for @raman325 -- it looks like the volume stayed at 15. But as he wrote on discord:
I will have to check later but I may have disabled audio control on the android side, so you may want to find another tester
well, I just can't remember how I have it set up. I have a soundbar hooked into the TV via HDMI ARC and I can control volume from the shield remote
This set_volume_level
is implemented in this pull request: #150
But I’m hesitant to merge it if it only works for some devices.
I wonder what his CEC settings are for volume control ... I will see if that effects it ... but the command works on both of my TVs...
Maybe there could be a config entry to disable it?
@JeffLIrion - Yep appears to not work with CEC volume .. but this also seems to be the case with vol up / down ... including with the android remote! ... so maybe my TVs just don't work with the CEC volume standard? (they support other CEC commands) ... also I dont think that there is a CEC standard for setting a vol %
I found this post about CEC control in Android, but I don't know if it's relevant: https://stackoverflow.com/a/48082147
I don't see a need for a config entry to disable the volume_set
service, it just wouldn't do anything if the user called it. It would be nice if some explanation could be provided in the documentation as to why it works for some setups and not others.
Is it the case that if the volume up/down commands work, then this command will work? @raman325 do the volume up/down commands successfully adjust the volume for your setup?
Yes, the volume up/down service commands work, and I can confirm that I am using CEC for volume control
Well, the current set_volume_level
in this package isn't good, so I'll go ahead and merge #150.
I’ll make a pull request to Home Assistant after home-assistant/core#30994 gets merged. @raman325 would you mind reviewing that pull request? It's pretty simple.
@JeffLIrion are you asking me to review home-assistant/core#30994 or the next PR you are planning to submit?
And the merging of #150 means I will lose the ability to control the volume of my device when you make the corresponding changes in HA (control which I currently have). This is fine for me personally as I don't have a need to manage the volume in HA, but just pointing that out in case it wasn't clear earlier.
I was referring to home-assistant/core#30994, which you have since reviewed. Thanks!
You should still be able to control your volume with the volume up/down commands, right? The volume_set
service won’t work for you, but it’s not even available right now, so nothing lost and nothing gained.
This would be the change to the component: JeffLIrion/ha-androidtv@cf50900
Ah I see, did not realize this was just a change to that service, thought it applied globally. Then yes, not an issue for me!