Pi audio component

cool! i am not using hass.io, just have to detirmine how to use it in HA

1 Like

Hello Pantomax, very new to this Hassio system but im begining to like it, but as a noob I’m having problems with testing json service call in developer module. Basically I would like to trigger a sound when temperature of sensor reaches a certain level but being a noob and an old git can’t get this to work. Is it possible to use the call service and test json format. If it’s possible could you give us an example please?

Hey @OldGitHub,
actually I don’t really know how to answer to your question, I’m not even a coder, so my knowledge level is very low. Maybe… something like:

{
     "addon" : "de3cd379_audio_player", 
     "input" : "http://192.168.1.100:8123/local/sound_when_temperature_of_sensor_reaches_a_certain_level.mp3"
}

:sweat_smile:

Hello again @Pantomax…you sir are a legend, brilliant, I made the error of missing “input”, which was why I kept getting errors in the log…Doh! this is great, after pulling out what hair I had left, I can now wire the house up with sensors and speakers, the only down-fall is I’m probably gonna get an ear bashing from TheOldGirl when a trigger sounds an alert. This home automation stuff is brill…thanks again for your quick reply :sweat_smile:

1 Like

Glad that I could help. :blush:
Happy automating over there, let your home sound like the USS Enterprise computer :wink:

@Pantomax ciao, volevo chiedereti di aggiungerti al mio gruppo facebook per creare una comunitĂ  di supporto italiana di HA, visto il poco materiale reperibile nella nostra lingua, ciao e grazie

Ciao @Domo, in realtà non ho nessun profilo Facebook, magari piÚ avanti me ne faccio uno. Se ti può interessare sto scrivendo un piccolo tutorial su Linkedin:

magari a qualcuno può servire :wink:
Max

1 Like

perfetto, grazie, se non dispiace condivido sul gruppo.
Inoltre ti volevo chiedere maggiori informazioni riguardo l’audio dal jack, ho seguito le tue istruzioni e dal log risulta che la musica e in esecuzione ma dalla cassa non esce alcun suono,
questo e il log che ricevo: riesci ad aiutarmi a capire come mai non funziona?grazie
Immagine

Certo, condividi pure. Prova con l’indirizzo di Radio Rai ( http://icestreaming.rai.it/1.mp3 ) che sono sicuro sia compatibile con il player utilizzato. Sei sicuro che il jack funzioni? Hai mai sentito altri suoni uscire da lì? Se nemmeno quello funziona ne riparliamo :wink:

Funzionaaa, il problema era che prima di provare la tua guida,avevo fatto delle prove e avevo collegato l HDMI di raspberry alla TV, cosi ho letto un antro post dove un utente aveva il mio stesso problema e staccando HDMI e riavviando il PI e partito l’audio dal jack alla cassa. funziona sia con mopidy che con audio_player, pero vedo che non funziona il TTS, conosci qualche soluzione?

(Per quanto riguarda il tts lo scrivo in inglese, magari può far comodo anche ad altri.)
So, if you guys want to use the TTS on this player, I made a little workaround. I hope it will work correctly also on your system.

First of all you need to make a directory called tts inside the /config/www/ directory and set this dir as the google tts cache, like this:

tts:
  - platform: google
    cache: true
    cache_dir: /config/www/tts

Now, you have to set these three elements:

  1. a fake media player
media_player:
  - platform: universal
    name: hassio
  1. a command used to clean the directory after every usage
shell_command:
  remove_old_mp3_files: rm /config/www/tts/*.mp3
  1. a sensor used to sense when Google TTS writes the TTS mp3 in my directory
sensor:
- platform: command_line
  name: "last tts"
  command: "ls /config/www/tts/ -1t | head -1"
  scan_interval: 5

I will call this script to generate the mp3 file:

script:
  hassio_talk:
    alias: Hassio talk script
    sequence:
      - alias: Hassio Talk 
        service: tts.google_say
        entity_id: media_player.hassio
        data_template: 
          message: >
            '{{ message }}'
          language: en
          cache: True

and this automation will play the file as soon as the mp3 file will be transferred on the hassio (don’t forget to replace the IP address of your RPi):

automation:
  - alias: "Read TTS"
    trigger:
    - platform: state
      entity_id: sensor.last_tts
    action:
    - service: hassio.addon_stdin
      data_template:
        addon: de3cd379_audio_player
        input: "http://192.168.1.100:8123/local/tts/{{ states('sensor.last_tts') }}"
    - delay: '00:00:05'
    - service: tts.clear_cache

so, if you want to call the script, just use this service:

  - service: script.hassio_talk
    data:
      message: "Hello world!"

for example when the hassio starts:

  - alias: "TTS message at start"
    trigger:
      - platform: homeassistant
        event: start
    action:
      - service: shell_command.remove_old_mp3_files
      - service: script.hassio_talk
        data:
          message: "Server on line"
1 Like

If you are not using hass.io, just install VLC media player component. It can play local MP3 and TTS.

Before that, you need to run this…

sudo apt-get install vlc-nox
1 Like

Hey there @masterkenobi, thank you for the hint.
Do you have any idea on how to set the volume level on Hassio?

why does this happen if I try to install VLC?

@Pantomax volevo chiederti se hai idea di come poter installare un microfono per usare i comandi vocali sul RPi con Hass.io, sul web non ho trovato risposte.

Because you are on Hass.io, there is no access the the underlying OS.

Is there a way to choose between the audio jack or have the raspi transmit the signal via Bluetooth, allowing cable free connection to my Bluetooth speaker.

Hello,

I had a question, if you wouldn’t mind answering

I tried to install the addon locally but I’m getting this error.

starting version 3.2.4
/usr/bin/entry.sh: /run.sh: /bin/bash^M: bad interpreter: No such file or directory
/usr/bin/entry.sh: line 9: /run.sh: No error information

do you know what is causing it?

ARG BUILD_FROM

FROM $BUILD_FROM



# Add env

ENV LANG C.UTF-8



# Setup base, install sox package

RUN apk add --no-cache jq sox



# Copy data

COPY run.sh /

RUN chmod a+x /run.sh



CMD [ "/run.sh" ] 

{

  "name": "Audio Player",

  "version": "1.55",

  "slug": "audio_player",

  "description": "Play audio files",

  "startup": "before",

  "boot": "auto",

  "stdin": true,

  "audio": true,

  "hassio_api": true,

  "options": {},

  "schema": {},

  "host_network": true

}

#!/bin/bash

set -e



echo "starting!"



# Read from STDIN aliases to play  file

while read -r input; do

    # removing JSON stuff

    input="$(echo "$input" | jq --raw-output '.')"

    echo "[Info] Read alias: $input"



    if ! msg="$(play $input)"; then

    	echo "[Error] Playing failed -> $msg"

    fi

done

I’m still trying to learn all this stuff.

Thanks very much!

After i test this in the developer tools > services in the log i get this message, any idea why?

[Info] Read alias: http://192.168.1.13:8123/local/alarm.mp3
ALSA lib conf.c:1876:(snd_config_load1) toplevel:1:2:Unexpected char
ALSA lib conf.c:5017:(snd_config_expand) Parse arguments error: Invalid argument
ALSA lib pcm.c:2501:(snd_pcm_open_noupdate) Unknown PCM hw:{0,0}
[Error] Playing failed ->

Great Addon-on, thank you.
Is there a way to set the volume?