Home Assistant

Raspberry Pi Volume Central

Unlike using the media_player.volume_set this method will adjust the main output of the raspberry pi regardless of the platform that is outputting the audio. Therefore you could use this as a volume limiter to your media player running on your Raspberry Pi through Home Assistant.

You can add Raspberry Pi Volume Central in two ways. By adding some components (Automation, Shell Command, Group, Script, Input Slider) or simply by adding a package using the packages feature in Home Assistant.

1. Using The Packages Feature (Fast & Easy)

  1. Simply download the raspberry_pi_volume_central.yaml file and move it to the sane directory where you have the configuration.yaml file.
  2. Add the faloing to your configuration.yaml under homeassistant:
packages: 
    raspberry_pi_volume_central: !include raspberry_pi_volume_central.yaml

3. restart home assistant find out how in the documentation or restart your raspberry pi sudo reboot

All Done

2. Add The Components (Advanced)

Home Assistant is going toward having a yaml file for every component (see Splitting up the configuration). I have structured my configuration.yaml so it takes advantage of !include to decorate the clutter in the configuration file. click here to see how I did it. (coming soon)

Automation File

- action:
   - service_template: shell_command.pi_volume_{{ trigger.to_state.state | int }}
   alias: Pi Volume
   condition: []
   id: 'pi_volume'
   trigger:
   - entity_id: input_slider.pi_volume
     platform: state

Input Slider File

pi_volume:
  icon: mdi:volume-high
  name: Volume 
  initial: 70
  min: 0
  max: 100
  step: 10

Shell Command File

pi_volume_0: amixer cset numid=1 -- -10238
pi_volume_10: amixer cset numid=1 -- -5675
pi_volume_20: amixer cset numid=1 -- -3820
pi_volume_30: amixer cset numid=1 -- -2740
pi_volume_40: amixer cset numid=1 -- -1976
pi_volume_50: amixer cset numid=1 -- -1383
pi_volume_60: amixer cset numid=1 -- -942
pi_volume_70: amixer cset numid=1 -- -525
pi_volume_80: amixer cset numid=1 -- -195
pi_volume_90: amixer cset numid=1 -- 118
pi_volume_100: amixer cset numid=1 -- 400

Group File

pi_volume:
  icon: mdi:timer
  entities:
  - input_slider.pi_volume
  - script.mute_pi_script
  name: Raspberry Pi Volume
  view: false

Script File

mute_pi_script:
  alias: Mute Pi
  sequence:
  - data:
      entity_id: input_slider.pi_volume
      value: 0
    service: input_slider.select_value

restart home assistant find out how in the documentation or restart your raspberry pi sudo reboot

All Done