Soundify: my wifi door chime / siren / loudspeaker with REST API

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Post Reply
fez
Posts: 147
Joined: 20 Jul 2015 23:03

Soundify: my wifi door chime / siren / loudspeaker with REST API

Post by fez »

I needed (wanted) a networked door chime to use in my z-wave gateway.
I considered ordering an Aeotec Doorbell, but this is not available in Europe. I looked for other alternatives within the given price range, but I found nothing, so I decided to build my own, which eventually proved to be even cheaper.
Required hardware:
- Raspberry Pi Zero (W): 10€
- Adafruit I2S 3W Class D Amplifier Breakout - MAX98357A, 6€
- a speaker (I've opted for Visaton FR 7, after a failed experiment with a cheaper option), 5€
- a power supply, I just reused a phone charger (consider one capable of 1.2A or more)
- a plastic box, 3€, but I started with a cardboard shoe box

Start by setting up the Raspberry with a Jessie Lite image:
https://www.raspberrypi.org/downloads/raspbian

Once you have written the image to the SD card, but still on the PC side, prepare it for headless operation:
- create a "wpa_supplicant.conf" file (to connect later to your wifi network) in the boot folder with the content:

Code: Select all

network={
    ssid="testing"
    psk="testingPassword"
}
- create an empty file named "ssh" to have SSH enabled for headless operation

Follow the guide from Adafruit to set up the I2S amplifier:
https://learn.adafruit.com/adafruit-max ... d-mono-amp
... until the "Simple MP3 speaker test", the rest you won't be needing
... or you may use a different amp. I found the above to be inexpensive and practical choice.

Add your user to the "audio" group:

Code: Select all

sudo usermod -a -G audio YourUserName 
Install curl:

Code: Select all

apt-get install curl
Download my scripts and mp3 samples to ease the coding:

Code: Select all

curl -L -o soundify.zip 'https://drive.google.com/uc?export=download&id=0B-cIbx13ShdkN2hiOEt3bjRDSHM'
unzip soundify.zip
chmod +x -R soundify
Try playing an mp3 file/sound:

Code: Select all

~/soundify/sound.py -i ~/soundify/tones/start-sound.mp3 -v 0.1
... the -v parameter sets the volume (accepted 0.01 to 0.99)

Now get rid of the I2S popping/cracking sound by following this guide:
https://www.lightbluetouchpaper.org/201 ... spberry-pi

Try playing the sound again, twice. Popping should be gone in the second run.

Code: Select all

~/soundify/sound.py -i ~/soundify/tones/start-sound.mp3 -v 0.1
Now get the Flask python module (Jeremy M.'s guide):
sudo apt-get install python-pip
pip install flask[/code]

Start the server by calling the script:

Code: Select all

~/soundify/shout.py
... the the raspberry should be waiting for commands

Set up a HTTP device to test the web api ( I use my zway gateway for this):

Code: Select all

http://your-raspi-IP:5000/shout/api/v1.0/doorbell1.mp3/49
... use GET, no user, no password

Configure the Raspberry to run the service at boot time:

Code: Select all

sudo nano /etc/rc.local
Add the below line before the "exit 0" :

Code: Select all

# start pulse audio
pulseaudio -D
# play a sound to activate pulse. A (first) popping sound will be followed by the start-sound.
~/soundify/sound.py -i ~/soundify/tones/start-sound.mp3 -v 0.1
# start the REST API server
~/soundify/shout.py & 
You can play any mp3 file placed in the "~/soundify/tones" folder over the web api:
- use GET
-

Code: Select all

http://your-raspi-IP:5000/shout/api/v1.0/your-mp3-filename/your-volume
Replace your-raspi-IP, your-mp3-filename, your-volume with real values.
Allowed volumes: 1-99

Authentication is not implemented. Follow Miguel Grinberg's guide to secure the service.

20170802_005402~01~01.jpg
20170802_005402~01~01.jpg (99.93 KiB) Viewed 6072 times

This project is based on the great guides offered by:
- Raspberry Pi Foundation
- Adafruit
- Steven J. Murdoch
- Dan Bader
- Jeremy Morgan
- Miguel Grinberg
- and others
Last edited by fez on 10 Jan 2018 11:43, edited 2 times in total.
enbemokel
Posts: 482
Joined: 08 Aug 2016 17:36

Re: Wifi door chime / siren / loudspeaker with REST API

Post by enbemokel »

Thanks for sharing, I´m looking also for a doorbell, Doorbird e.g.. but it´s very expensive.
Your solution may be also a solution for other places.
Post Reply