Announcement System using Raspberry Pi

Hi Everyone,

I wanted to share a Python script I wrote to queue and make announcements via HTTP GET requests. Currently, I have a Raspberry Pi (not running OH) connected up to a relay board and a USB sound-card (which is hooked up to an AMP and some speakers through the relay for zoning).

Basically, this lets me make announcements via a HTTP GET from OpenHab to different zones in my house (right now inside and outside). I use this for the burglar alarm, dryer done notifications, doorbells, door opening chimes, etc…

To use it, once the Pi is setup, you just make a call to the web server running in the Python script and it will queue and play messages to the zones setup with the relay.

Here’s the github link: https://github.com/kq9914/RPI-Announce

This code was very hastily written and is not secure (don’t face it towards the Internet!), but it does work quite well for my purposes. I’m hoping someone else will be able to get some use of it too.

I am starting on Openhab on Raspberry Pi 3.
This looks very usefull. In fact I was looking for it already and did not see anything simple. So I am interested to give it a go.
Can you explain what a USB audio adapter on the Pi is and what you recommend to buy?
Also RPi3 has an audio jack, can it be used instead?

Thanks for sharing.

Thanks for sharing.
I’ve been running such an announcement system on my openHAB Pi, too. Doorbell, rain warning and lots of funny or useful little things.

As a long time openHAB user, I would recommend to implement all the action inside OH rules
Let me point you at some openHAB ‘ingredients’, before you put too much work into expanding your script:

First, there’s a couple of builtin audio functions to play MP3 and WAV files directly from OH rules. You can combine this with HTTP actions.
Second, check out the googletts and marytts addons in openHAB, they provide text-to-speech capabilities.
Third, there are bindings for the most popular AVRs. You can use this to switch zones, or there’s also the generic HTTP binding.

Some notes on hardware:
Yes, you can use the audio jack, too. While the Pi’s audio chip isn’t great (I wouldn’t use this to play music), it’s absolutely sufficient for announcements. I’ve simply attached an old PC loudspeaker. Just make sure you use an active one (one with an external power supply) because the maximum volume the Pi can provide all by itself isn’t all that great.
Second, if your amplifier or AVR is in ‘cable range’ to your Pi (mine isn’t) and has HDMI inputs, connect it to the Pi’s. That way you don’t need a USB sound card. Use raspi-config to select audio output.

Thanks for the input – It’s definitely a good idea to use what OpenHAB has available built-in whenever possible!

I’ve been using this distributed announcement model for a 3+ of years now, starting with Vera, just with a different Python implementation. I finally re-wrote it to support queuing which helps a lot when multiple announcements are being made at the same time (ex: burglar and fire alarm going off (hopefully not something that happens too often!)).

I initially tried to implement this feature set in OpenHAB, but was not successful for a few reasons:
a) (This could be due to lack of familiarity with the Java-based rule language, but…) It was difficult to implement this functionality in the rule code itself so that asynchronous calls would not overlap when announcements were being made. That being said, it was incredibly easy to just make an HTTP get request from inside a rule when something happened
b) I run my OpenHAB on Windows Server on a small dedicated PC, so I did not have directly access to GPIO pins to control the relays
c) I wanted to have my OpenHAB server in a different physical location from my PA amplifier for these speakers

I used to have a need for TTS, but got annoyed with the relatively bad quality of the output, so I hired a voice actress on Fiverr to make all of announcements, so I don’t really need TTS anymore. ($5 USD for 150 words). This also significantly increased the WAF (wife approval factor).

When I say amp, I’m talking a dedicated amp for dedicated announcement speakers, not one hooked up to my home theater. I wanted a dedicated system so that the announcements would happen regardless of anything else. I also have a Sonos system, but was not satisfied with the way the announcements worked through it. The relays allow for quick and dirty zoning of the dedicated in-ceiling speakers throughout the house and also completely removes any “buzzing” or “humming” that may occur when no sound is being played since the speakers are totally disconnected from the amp.

So yes, there are definitely easier ways to do this directly in OpenHAB if you don’t have some of the requirements I do. As you said, if you can make it work for your use-case, I would highly recommend doing it directly in OpenHAB, too.

As for the USB audio adapter, I found the sound quality to be significantly better when using the USB adapter than the built-in 3.5mm jack, but there’s no reason why you couldn’t just use what was already there.

Ok, although I’m pretty satisfied with the Pi sound jack (btw: Pi vs. Pi2 makes a significant difference here), with your hardware setup and if I still wanted better sound, I would go for a USB sound card, too. Even more so now that you have it in operation.
I, too, use (self) spoken announcements stored as MP3s. But GoogleTTS is really good, and of course it gives you the advantage of playing dynamic announcements. Using OH rules, you can use both and even combine them.

Well, in order to move your system into OH,
a) can be accomplished by using two things:

  1. use Thread::sleep() after playSound() to wait for a defined number of milliseconds. Works fine provided you know how long the recorded sound files are taking to play, but you can find out using an audio tool and store the values in an array inside the rule.
  2. for threading safety, use a virtual item (one that is not mapped to any physics), then implement a play routine (rule) that triggers upon change of that item. You can apply locking inside that rule and you use item.sendCommand() to play an announcement. Examples for this are in the OH wiki.

b) huh? You have a Pi working but run OH on Windoze ?
There actually is a openHAB GPIO binding available, too. So if you moved your OH setup to the Pi (save energy, save the earth :-)), you could control your zoning from within OH, i.e. the aforementioned rule could trigger the right relay before playing the sound.

Hi, James! I am really intrigued by your setup. But I am neither a hardware nor an audio guy and could need some advice on the detailed setup. I have a Pi2 running OpenHAB, so that’s covered.

  1. If I would want to connect a dedicated amplifier via built-in audio jack or HDMI, do you have any suggestions which equipment to use (reference, supplier etc)?

  2. What kind of dedicated loudspeakers do you use (reference, supplier, picture etc.)? Which cable did you use?

  3. When you talk about a relay board, which relays with which specifications? How did you wire everything up? A schematic would help me a lot to understand.

  4. Finally, if I got it right, your amplifier is connected to only one loudspeaker at a time depending on the relay which is switched? Or can you do announcement or play music everywhere at once? If not, how could this be accomplished? I guess it would make a big difference for the amplifier whether one, two or ten loudspeakers were connected to its output and that the volume would vary, right?

I am really interested in an announcement system (to play music or dedicated announcements) for when I build a new house.

Many thanks for your help.

I’m currently using a cheap Pyle amplifier I ordered from Amazon (30 watts). No particular reason I chose it besides it was small and seemed like it had good reviews.

I’m using Honeywell/Ademco 746 alarm speakers for the system. I used generic 18 gauge speaker wire to connect the amp to the speakers through the relay.

For the relay, I used a generic SainSmart 4 channel relay board. This was readily available from Amazon and works at 5v. I’m attaching a diagram to this post.

It’s connected to groups of speakers, but also can be connected to all of them. I misspoke earlier saying they were all on the same stereo channel – When I went back and looked, I have each zone on a different stereo channel. The code allows for a specific zone to be turned on as well as both zones to be turned on. Yes, this would mean that there are different resistances on the line depending on how many zones are active. I’m not an audio guy either, but it doesn’t seem to impact the loudness/quality much, but using the different stereo channels may have something to do with that, as well as the channels being balanced.


I’m using a Raspberry Pi 1, so yeah, the onboard sound was pretty bad. From what you’re saying, I have no doubt it has improved in the more modern generations.

Thank you for the advice on accomplishing this in OH! I think I’m going to stick with the “announcement appliance” model though. It might not be right for everyone, but it works well for me and my particular application. I personally like the idea of using OH strictly as a bus/brains for automation and have other abstracted parts for specific functions.

Eh, what can I say, I have a ton of Windows running in my home on a virtualization cluster, so for server applications, like OH, I already have the infrastructure setup to patch/secure/access control Windows. It is running on a super-lower power (granted, not as low power as the Pi) Gigabyte Brix :slight_smile: