New Appdaemon app: setting the volume from your Raspberry

it is nice to be able to set the volume from a mediaplayer or tts but if your raspberry is set to zero or maximum then still it can be annoying.

if you configure your sound outside HA (like i do with appdaemon) then it is even more annoying.

so i created an app to set the volume from the raspberry itself.

first i made a input_slider:

  rpivolume:
    name: Volume from Raspberry
    initial: 70
    min: 0
    max: 100
    step: 5

and then the app:


class sound(appapi.AppDaemon):

  def initialize(self):
    self.listen_state(self.setrpivolume,"input_slider.rpivolume")

  def setrpivolume(self, entity, attribute, old, new, kwargs):
    volume = new
    self.log("volume: " + volume[:-2])
    cmd = ['amixer','cset','numid=1',volume[:-2] + '%']
    with tempfile.TemporaryFile() as f:
      subprocess.call(cmd, stdout=f, stderr=f)
      f.seek(0)
      output = f.read()

and all you now have to do is put this app in the appdaemon config and you can control your RPI volume.

2 Likes

Rene,

Why do you find yourself changing the volume of the RPi itself? Do you have speakers hooked up and use it as a media player?

Thanks,
SN

i have a speaker hooked up to it.
and in the near future a have a compleet 5.1 surroundset hooked up to it.

I use TTS with appdaemon, the radio plays over the RPI and i have a clock making hourly sound.
the need started really by using TTS.

some announcements are important and need to be set to loud, but some are not that important.
the clock, the radio it all needs its own volume.

i could try to use volume from the different mediaplayer, but that didnt work like i would like to.
i needed to set the RPI volume to max and from the speaker as well and then i could use the mediaplayervolume. for some things. but that gave some annoying extra effects.

thats why i started playing with the RPI volume and that is satisfying.
i can mute all at once, i can set everything a little louder when i like. after i have tuned all the different soundniveaus to another.