Pulseaudio with HomeAssistant and Docker

I wanted to have direct 3.5mm pulse audio from Home Assistant container via the host with 3,5mm jack.
I added the following code in the docker-compose:
homeassistant:
    build: /home/docker-compose/homeassistant-custom
    restart: always
    volumes:
      - /dev:/dev
      - /tmp/.X11-unix:/tmp/.X11-unix
      - ~/.config/pulse/cookie:/root/.config/pulse/cookie
      - /run/user/1000/pulse:/run/user/1000/pulse
      - /var/run:/var/run
      - /run/dbus/:/run/dbus/:rw
      - /dev/shm:/dev/shm
    environment:
      - PULSE_SERVER=/run/user/1000/pulse/native
      - PULSE_COOKIE=/root/.config/pulse/cookie
    devices:
      - /dev/snd:/dev/snd
This code is added on top of your normal docker-compose lines.  Furthermore i created the home-assistant-custom dir and add the following in dockerfile
FROM homeassistant/home-assistant:latest
RUN apt-get update && \
    apt-get install -y vlc-nox apt-utils alsa-utils nano pulseaudio && \
    usermod -a -G audio root && \
    usermod -a -G pulse-access root
Now you can get TTS pulse audio from HA, just add a media_player:
media_player:
- platform: vlc
  name: speaker_1
  arguments: '--alsa-audio-device=hw:0,0'
And use it in a script or automation.


(https://www.martinvdm.nl/2018/08/25/pulseaudio-with-homeassistant-and-docker/)

Post a Comment