Volume slider for integrated 3.5mm speaker

Hi,

On my raspberry i have connected a 3.5mm speaker and setup as media player.

I can set the volume on the pi with:
amixer set PCM – 100%
or
amixer set PCM – 50%
or what ever level.

Have some one ever made an volume slider with this code above?

Thanks

Hello.

That should be straightforward with an input_number configured as slider and then with an automation based on the input slider value to be set as a value to a shell command (similar to what you have here).

Can you please share what kind of speaker you have and your configuration? I’m interested in such a setup and with configuration I might be able to help you with it…

Thanks in advance.

Hi,

My media_player is:
- platform: vlc
name: speaker_1
arguments: ‘–alsa-audio-device=hw:0,0’

Indead with an input_select and a shell_command it should be possible.

Thanks

Thanks, pretty straightforward.

And the device itself, can you share? Link/picture, if possible.

The device itself is just a regular 3.5mm speaker connected to the Pi. It has no intelligence, bare metal speaker.

1 Like

Made the folllowing:

internal_speaker_volume:
name: Interne Speaker Volume
initial: 100
min: 0
max: 100
step: 10
icon: mdi:volume-high

Automation:

  • alias: “Internal Speaker - Set Volume”
    trigger:
    platform: state
    entity_id: input_number.internal_speaker_volume
    action:
    • service: shell_command.run_sudo
      data:
      cmd: “amixer set PCM – ‘{{ states.input_number.internal_speaker_volume.state | int}}’%”

Getting error:
Unable to find service shell_command/run_sudo

Got it working:

shell_command:
set_internal_speaker_volume: “amixer set PCM – ‘{{ states.input_number.internal_speaker_volume.state | int}}’%”

input_number:
internal_speaker_volume:
name: Interne Speaker Volume
initial: 100
min: 0
max: 100
step: 10
icon: mdi:volume-high

automation:

  • alias: “Internal Speaker - Set Volume”
    initial_state: on
    trigger:
    platform: state
    entity_id: input_number.internal_speaker_volume
    action:
    service: shell_command.set_internal_speaker_volume

I have this in my HA. I will post it this evening.

Awesome :sunglasses: will try this week.

I have put this in package. It will not show up. you need to put the group.pi_volume shows in this package in the tab view you want.
pi_volume

#Raspberry Pi Volume Control

##################################################
## Extra volume control for Raspberry Pi 3
##################################################

shell_command:
     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

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

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

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

group:
     pi_volume:
       icon: mdi:timer
       entities:
       - input_number.pi_volume
       - script.mute_pi_script
       name: Raspberry Pi Volume
       view: false
1 Like

I think my scripting is a lot easier, See my post above

1 Like

So would this work for my tv using my Harmony Hub?

can shellcommand: work in hassio?

Yes it can.

has anybody got this working in Hassio, both examples above return errors

i moved commands around to get a check config “good” but it still hasn’t worked.

I use it with hassbian and raspbian connect to 3.5mm jack to the speaker. I have no experience with hassio, so I’m not sure if this would works with hassio.

thanks Sunonline

ill eventually figure all of this stuff out.

including the Alexa tts and Janet Tts

I tried using the code mentioned above withouth success; is anyone using HassIO ?

I know there are several answers already but this works oob for me, I’m using the package method, so this is te content of the file raspberry_pi_volume_central.yaml
I have issues copying pasting the code from above as the symbols screwed everything up. Code tags should be used for posting :+1:

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

shell_command:
  set_internal_speaker_volume: amixer set PCM - '{{ states.input_number.pi_volume.state | int}}'% -M

automation:
  - alias: Pi Volume
    id: 'pi_volume'
    trigger:
      - entity_id: input_number.pi_volume
        platform: state
    action:
      - service: shell_command.set_internal_speaker_volume

Trying to execute the shell command mentioned here returns FileNotFoundError: [Errno 2] No such file or directory: ‘amixer’, not sure why, any help is appreciated.