I made a home speaker using raspberry pi to get feedback from vera. I wanted to share how i did this with the community, maybe it would help someone or someone in the comunity with beter skills than I have can make something better
I needed an audio feedback from vera for when i enable night mode, disable the alarm … If I walk into the house when the alarm is active, i wanted a way of getting feedback that the alarm is active. Now when I set vera to night mode, i get an voice saying ‘Night mode activated’, i also get a voice warning ‘Kitchen door vibrating’ is my kitchen door vibration sensor is tripped
What I did was install a webserver on a raspberry pi, give it a static ip address and connect a USB powered speaker to it. When ever vera wants to play an audio, I call the pi via the ip address and give it the name of the audio file to play out and also tell it what volume to play it at. All audio that is played out has to be stored on the pi first
This is how I did it:
- Get a raspberry pi (any old one will do)
- Install Raspbian on the raspberry pi (there are lots of tutorials out there for this, some NOOB SD cards come with this already)
- Install a PHP Lamp server on the raspberry pi (https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress), you don’t need the mysql database
- Download Filezilla, we will use this to FTP (transfer) files to the raspberry pi
- Go to your router and give the raspberry pi a static ip address (check your router settings)
- We are going to play our MP3 Using MPG321 so lets install MPG321 (more info here: Raspberry Pi Command Line Audio - Raspberry Pi Spy). It can be installed by running: sudo apt-get -y install mpg321
- Now we have raspberry pi set up as a web server that can play audio files. Lets add the php file that does the playing of the audio file
- Create a file called sound.php and paste the following code into it:
- create a folder in the same location called audio. This is where you put your audio files that you want the PI to play
- Put an audio file into the audio folder
- Get the IP address of the raspberry PI and call it from a different browser as follows:
http://192.168.0.2/sound.php?file=alarm_disabled&volume=100
The 192.168.0.2 is the ipaddress of the raspberry PI. alarm_disabled is the name of the adio file that i want to playout. The name must match the mp3 file (minus the .mp3 part) Volume = 100 means play it out at the highest volume. Try it out
- Give your PI a static ip address from your router
- Your PI is ready to use
You can get audio for what ever text from http://www.fromtexttospeech.com. Save the mp3 file and use it in your PI. I use filezilla to copy the mp3 file to the PI
In your vera scene, paste this in the Also, ‘execute the following Luup code:’, change the ip address and file name as required
local http = require(“socket.http”)
– 5 Second timeout
http.TIMEOUT = 5
result, status = http.request(“http://192.168.0.2/sound.php?file=dinning_door_vibrating&volume=95”)
The process looks long but it is quite simple to do. It can be set up with just a few commands. I welcome any improvements. Maybe some one can make an app for this for the vera community