Vera Home Made Raspberry pi Speakers

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:

  1. Get a raspberry pi (any old one will do)
  2. Install Raspbian on the raspberry pi (there are lots of tutorials out there for this, some NOOB SD cards come with this already)
  3. 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
  4. Download Filezilla, we will use this to FTP (transfer) files to the raspberry pi
  5. Go to your router and give the raspberry pi a static ip address (check your router settings)
  6. 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
  7. 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
  8. Create a file called sound.php and paste the following code into it:
<?php $filename = $_GET['file']; $volume = $_GET['volume']; exec("sudo mpg321 -g ".$volume." /var/www/html/audio/".$filename.".mp3"); ?>
  1. create a folder in the same location called audio. This is where you put your audio files that you want the PI to play
  2. Put an audio file into the audio folder
  3. 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

  1. Give your PI a static ip address from your router
  2. 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

ghost,

I’m totally surprised that no one else has commented on all the effort you took to make a very complete tutorial. I thank you!!

I am new to RPi, but looking forward to experimenting. One question; does the Pi have enough power to produce sufficient sound? Are your speakers powered or does all the power come from the Pi? I have seen several audio out cables that have jacks on the ‘out’ side that could be plugged into a set of powered computer speakers and it seems that may be the way I end up going but I was curious of your feedback for both sound quality and quantity (loudness) in the tutorial as shown.
Also, What happens if the sound clip is greater than the 5 second timeout? Does the clip terminate early or does the connection close at the end of playing the clip? Is there any harm in increasing the timeout to a larger value, say 10 seconds, or will that produce a more noticeable latency in the rest of Vera’s work?

Any other suggestions to use a Pi with Vera to expand its abilities? Looking forward to playing with the Pi.

kartcon

Wow this is ideal. I have a siren but was looking at a chime for when the front door opened when mode in home. This is the solution. I have a Rasperberry Pi that is in need of a project added to it

Sent from my Vivo XL2 using Tapatalk

Civvie,

I recently posted another, very simple way to use your door sensors as an annunciator for open events. It uses an Aeon Z-Wave Doorbell to play a sound when the door opens. There is very little overhead (one new device and literally one line of code). See the full post here:
[url=http://forum.micasaverde.com/index.php/topic,50540.msg335250.html#msg335250]http://forum.micasaverde.com/index.php/topic,50540.msg335250.html#msg335250[/url]

My plan is to pursue the Pi as a spoken text device. Yes, you could do it with the doorbell, but once you read my post you will understand how ‘selecting the MP3 to play’ gets a little more complicated as the number of sound files grows. I like ghost’s way simply because you refer to the file by its name, and not its index position on the file structure.

As a side note, the Aeon doorbell is a plug in unit (no batteries) and is quite small. We have ours plugged into the back side of our kitchen island and it is loud enough to be heard through the entire house. I selected a nice, soft electronic bing-bong as the door entry sound and its quite pleasant. No fuss from the wife, and now that my controller is offline for a few days (major meltdown) we both miss the door tones already.

Please let the group know if you expand on what ghost has done. His work is great and I can’t wait to try it.

@ghost Thanks for sharing. Good stuff.

[quote=“kartcon”]Civvie,

I recently posted another, very simple way to use your door sensors as an annunciator for open events. It uses an Aeon Z-Wave Doorbell to play a sound when the door opens. There is very little overhead (one new device and literally one line of code). See the full post here:
[url=http://forum.micasaverde.com/index.php/topic,50540.msg335250.html#msg335250]http://forum.micasaverde.com/index.php/topic,50540.msg335250.html#msg335250[/url]

My plan is to pursue the Pi as a spoken text device. Yes, you could do it with the doorbell, but once you read my post you will understand how ‘selecting the MP3 to play’ gets a little more complicated as the number of sound files grows. I like ghost’s way simply because you refer to the file by its name, and not its index position on the file structure.

As a side note, the Aeon doorbell is a plug in unit (no batteries) and is quite small. We have ours plugged into the back side of our kitchen island and it is loud enough to be heard through the entire house. I selected a nice, soft electronic bing-bong as the door entry sound and its quite pleasant. No fuss from the wife, and now that my controller is offline for a few days (major meltdown) we both miss the door tones already.

Please let the group know if you expand on what ghost has done. His work is great and I can’t wait to try it.[/quote]I looked at this and would try it but being unemployed at the moment, limits what I can do. I. E. Spend money lol

I will keep an eye out for a z-wave doorbell and try it.
I plan to try @ghost solution shortly, I have to find the USB speaker

Sent from my Vivo XL2 using Tapatalk

same here, except I built it using a custom made .NET Core app, and linked it to my two Amazon Alexas via Bluetooth.

I use it to calculate weather statistics, integrate with OpenSprinkler and hosting a telegram bot to issue command when outside, and to generally off-load some tasks from the Vera itself. Plus, I love C# :slight_smile:

@therealdb

I “love” C# as well. Can you please tell more about your solution? Especially the interactions with Alexa.

Alexa can be connected via Bluetooth to external players. Simply pair them, then lunch aplay or omxplayer from command line using asp.net core and you’re done.

I’ll upgrade my new house to Sonos later this year, but voice notifications done like this are pretty cool and cheap.

@kartcon the pi has enough power for the speakers, i tend to use the speaker volume of 50 (except for the dog bark sound which i use 90). The sound is amazing, i have a welcome sound for every time i get guests and on Christmas day, merry Christmas. If the clip is greater than 5 sec, it will still play. I have a good morning scene where after 6am, if my downstairs motion sensor detects movement, it says good morning, todays weather forecast is 5 degrees, with some rain.
I use it as a door bell now and also to log data from vera. in my startup lua, i have this:

function piLog(text)
pi = “http://192.168.0.11
text = string.gsub(text, " ", “+”)
luup.inet.wget(pi … “/log_data.php?data=”…text)
end

now in my scene, i just call piLog(“Reseting Router”), and my pi has a php script that logs this into a text file. Mainly used for debugging.
For the door bell, when I am in the garden shed (gym) if someone presses the door bell, the motion sensor in the gym detects that i’m in the gym and plays the door bell sound in the gym.

Another thing i use the pi for is a last reboot time. on startup, vera calls the pi last reboot.php, this returns the pi’s uptime, and vera can work out if there was a power cut (if uptime is less than 5mins). I get lots of power cuts and when the power comes back on, all my 23 hue lights come on and my 3 garden 50w flood lights on a z-wave switch. so i wanted a way of detecting power cuts and turning off all lights on recovery

In case you are wondering, the answer if yes, i have too much time on my hands. I work from home a lot (using the term ‘work’ loosely). I plan to use the pi as a database for vera, where vera can store data and retrieve data
If anyone is interested in any of my examples, i can write a tutorial on here
i have:

  1. door bell
  2. weather forecast
  3. detect power cut / restore
  4. get my google calendar events and say it out to me in the morning like (bin collection day today).

Please note that all these features can be achieved with a google home device or alexa. i just prefer to do it my self. I will add voice command to it soon using jasperproject and voxcommando

Just to add to this for those discovering this topic.

If you follow the steps and can’t get the URL to produce any sound, you will probably have to run the following command:

[tt]sudo chmod -R 777 /dev/snd[/tt]

not working for me
I can play the sound using
mpg321 /var/www/html/audio/lgo.mp3
I get a web page when I go to the web address
I think php isn’t working for me

did you try the steps given here:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/4
or

You seem to have the web server working but php isn’t installed. If it doesn’t work, do a search on the error. PHP should be straight forward to install. Put your errors here and i can have a look

I am trying to find a way to play a text message to Alexa (I could do that with Google Home and Airfoil) but have not found a solution yet. If someone has an idea, please let me know.

Thanks.

Simplest way, as I posted early in this thread, is to pair Alexa with Bluetooth and play your tunes this way. I’m using it since one year and it’s working very well.

I meant to play any custom text to speech to my Echos. It seems OpenHab already supported this. I have installed openhab2 in my raspberry PI and tried this plugin:

Now, when a door is open, Vera will call a HTTP command and play “Front door is open” to my Echos.

[quote=“ghost, post:13, topic:197796”]did you try the steps given here:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/4
or

You seem to have the web server working but php isn’t installed. If it doesn’t work, do a search on the error. PHP should be straight forward to install. Put your errors here and i can have a look[/quote]
Yes did the first one, skipped the mySQL part and the wordpress part. Is the workpress required?

wordpress and mysql are not required. i’m not sure what the problem is. You need php, maybe try a different php engine

I’ll reimage the SD and try these Raspberry Pi Documentation - Remote access instructions.

I’ve tested php (as described on the rpi page “hello world”) and it’s working

the command line
sudo mpg321 -g 100 /var/www/html/audio/lgo.mp3 plays the file.

I created a test file, soundtest.php, minus the variables but added the date test

<?php exec("sudo mpg321 -g 100 /var/www/html/audio/lgo.mp3") ; echo date('Y-m-d H:i:s'); ?>

to execute it directly. I get the date returned but no sound.

I added ;echo date(‘Y-m-d H:i:s’); and " hello world"; to the original soulnd.php file and I get the date/time and the message but no sound.