Author Topic: Vera Home Made Raspberry pi Speakers  (Read 1736 times)

Offline ghost

  • Newbie
  • *
  • Posts: 12
  • Karma: +4/-0
Vera Home Made Raspberry pi Speakers
« on: November 27, 2017, 04:21:56 pm »
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: https://www.raspberrypi-spy.co.uk/2013/06/raspberry-pi-command-line-audio/). 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");   
?>

9. create a folder in the same location called audio. This is where you put your audio files that you want the PI to play
10. Put an audio file into the audio folder
11. 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

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

Offline kartcon

  • Full Member
  • ***
  • Posts: 147
  • Karma: +7/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #1 on: January 06, 2018, 10:11:39 pm »
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

Offline TheCivvie

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #2 on: January 07, 2018, 05:02:45 am »
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


Offline kartcon

  • Full Member
  • ***
  • Posts: 147
  • Karma: +7/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #3 on: January 07, 2018, 09:08:56 am »
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:
http://forum.micasaverde.com/index.php/topic,50540.msg335250.html#msg335250

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.
« Last Edit: January 07, 2018, 09:20:18 am by kartcon »

Offline actran70

  • Newbie
  • *
  • Posts: 18
  • Karma: +3/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #4 on: January 07, 2018, 11:44:38 am »
@ghost Thanks for sharing.   Good stuff.

Offline TheCivvie

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #5 on: January 07, 2018, 06:39:15 pm »
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:
http://forum.micasaverde.com/index.php/topic,50540.msg335250.html#msg335250

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.
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


Offline therealdb

  • Full Member
  • ***
  • Posts: 136
  • Karma: +1/-0
  • Automate all the things!
Re: Vera Home Made Raspberry pi Speakers
« Reply #6 on: January 08, 2018, 02:50:05 am »
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# :)
Vera Edge, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (1), Nest (3), Raspberry PI running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station

Offline RitterIwan

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #7 on: January 08, 2018, 08:34:18 am »
@therealdb

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

Offline therealdb

  • Full Member
  • ***
  • Posts: 136
  • Karma: +1/-0
  • Automate all the things!
Re: Vera Home Made Raspberry pi Speakers
« Reply #8 on: January 09, 2018, 04:23:40 pm »
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.
Vera Edge, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (1), Nest (3), Raspberry PI running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station

Offline ghost

  • Newbie
  • *
  • Posts: 12
  • Karma: +4/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #9 on: February 02, 2018, 05:43:16 am »
@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
« Last Edit: February 02, 2018, 05:59:19 am by ghost »

Offline mversion

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #10 on: July 14, 2018, 09:12:57 am »
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:

sudo chmod -R 777 /dev/snd

Offline RV

  • Full Member
  • ***
  • Posts: 108
  • Karma: +0/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #11 on: July 31, 2018, 09:55:29 pm »
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

Offline ghost

  • Newbie
  • *
  • Posts: 12
  • Karma: +4/-0
Re: Vera Home Made Raspberry pi Speakers
« Reply #12 on: August 01, 2018, 05:49:50 am »
did you try the steps given here:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/4
or
https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

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

Offline hellovn

  • Sr. Member
  • ****
  • Posts: 267
  • Karma: +19/-46
Re: Vera Home Made Raspberry pi Speakers
« Reply #13 on: August 01, 2018, 08:33:55 am »
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.

Offline therealdb

  • Full Member
  • ***
  • Posts: 136
  • Karma: +1/-0
  • Automate all the things!
Re: Vera Home Made Raspberry pi Speakers
« Reply #14 on: August 01, 2018, 09:43:56 am »
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.
Vera Edge, Fibaro FGRM 222 (12), Fibaro FGS 223 (20), Fibaro FGS 222 (5), Fibaro Universal Binary Sensor (2), Fibaro Plug (3), NeoCoolCam Door Sensor (3), NeoCoolCam PIR (1), Nest (3), Raspberry PI running my own integrations, Harmony Hub, OpenSprinkler, Personal Weather Station