# Doorbell sound via amplipi and speakers

**URL:** <https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126>\
**Category:** General AmpliPi Questions\
**Created:** [August 15, 2022, 3:13pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126 "2022-08-15T15:13:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpo](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/mpo/32/21_2.png) [@mpo](https://amplipi.discourse.group/u/mpo)\
**Post date:** [August 15, 2022, 3:13pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/1 "2022-08-15T15:13:09Z")

</div>

anyone who can share some experience with attempting to have some dedicated doorbell-sound.mp3 be played via amplipi?

my home domotica can trigger the required code that talks amplipi-rest-api to get the following effect

- capture current config
- mute all
- play mp3 on all speakers
- go back to previous config and happily play along

any advise, suggestions or tips welcome

NOTE: I have the mp3 up on a local http server and configured as an internet radio on the amplipi - would be nice though if I could “hide” it from the other inputs (that or have some hierarchy in the input selection)

---

<div class="post-metadata">

**Author:** ![linknum23](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/linknum23/32/6_2.png) [@linknum23](https://amplipi.discourse.group/u/linknum23)\
**Post date:** [August 16, 2022, 12:32am UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/2 "2022-08-16T00:32:04Z")

</div>

Have you tried looking into the `announce` endpoint? It does all of this in one API call, the zones to play the sounds on can be specified but by default it plays on all zones, the sound file is expected to be given as a url.

---

<div class="post-metadata">

**Author:** ![mpo](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/mpo/32/21_2.png) [@mpo](https://amplipi.discourse.group/u/mpo)\
**Post date:** [August 16, 2022, 6:35pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/3 "2022-08-16T18:35:12Z")

</div>

> Have you tried looking into the `announce` endpoint?

Wow. Sounds like a perfect match !

Had just started reading up on the API + using the pyamplipi lib - but this answer allows me to skip ahead quite a bit 🙂

---

<div class="post-metadata">

**Author:** ![mpo](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/mpo/32/21_2.png) [@mpo](https://amplipi.discourse.group/u/mpo)\
**Post date:** [August 16, 2022, 7:51pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/4 "2022-08-16T19:51:53Z")

</div>

In case anyone else looks here for something like an answer:

just add your own API\_URI and SOUND\_URI to a .env and use:

```bash
#! /usr/bin/env bash
source .env

ANNOUNCE="${API_URI}/announce"
CT_JSON="Content-Type: application/json"
CONTENT_JSON=$(printf '{"media": "%s"}' ${SOUND_URI})

printf "Using announce\n at %s\n to post data %s\n\n" "${ANNOUNCE}" "${CONTENT_JSON}"

curl -s --url ${ANNOUNCE} -X POST -v -H "${CT_JSON}" -d "${CONTENT_JSON}" -o /dev/null >> /dev/null 2>&1

echo "done"

```

Or using the pyamplipi lib (current version):

```python
#! /usr/bin/env python3
"""
Playing a sound over the amplipi-announce
"""
import asyncio
import os
from collections.abc import Iterable
from pyamplipi.amplipi import AmpliPi
from pyamplipi.models import Announcement, Status
from dotenv import load_dotenv

async def play_sound(sndsrv, sound_uri):
    sound: Announcement = Announcement(media=sound_uri, vol_f=0.6, source_id=3)
    await sndsrv.announce(sound)

async def runit(): 
    load_dotenv()
    api_uri = os.getenv("API_URI")
    sound_uri = os.getenv("SOUND_URI")
    print(f"Using announce\n at {api_uri}\n to play sound at {sound_uri}\n\n")

    sndsrv = AmpliPi(api_uri, timeout=30)
    await play_sound(sndsrv, sound_uri)
    await sndsrv.close()
    print("done")

def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(runit())

if __name__ == ' __main__':
    main()

```

---

<div class="post-metadata">

**Author:** ![linknum23](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/linknum23/32/6_2.png) [@linknum23](https://amplipi.discourse.group/u/linknum23)\
**Post date:** [August 17, 2022, 2:37pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/5 "2022-08-17T14:37:14Z")

</div>

Nice example. Thanks for posting that!

Care to explain a little more about your doorbell setup? I wasn’t expecting to see python.

---

<div class="post-metadata">

**Author:** ![mpo](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/mpo/32/21_2.png) [@mpo](https://amplipi.discourse.group/u/mpo)\
**Post date:** [August 18, 2022, 9:05pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/6 "2022-08-18T21:05:19Z")

</div>

> Care to explain a little more about your doorbell setup? I wasn’t expecting to see python.

Sure.

Here in Belgium [Niko](https://www.niko.eu) is a well known and appreciated brand for home-electricity wall mount power-plugs, switches, … since many generations. Their contemporary offering includes a good and affordable ‘home-automation’ solution called [niko home control](https://www.niko.eu/nl-be/producten/niko-home-control)

It is proprietary, but with some open api support and gateways to other brands and products. Most importantly they allow triggering “virtual devices” which generate events that can be trapped through the [nhc2-coco](https://pypi.org/project/nhc2-coco/) python library → with [open code at github](https://github.com/filipvh/nhc2-coco)

The aim is to develop a simple local running service (I have small server running docker) that just listens to these events to trigger some neat effects involving the amplipi:

- for starters this very thing → have the doorbell push trigger the `/announce` of some `dingdong.mp3`
- in some zones (the rooms with built-in speakers) I’ve foreseen these [6-function-controlpads](https://www.niko.eu/nl-be/producten/schakelmateriaal-en-stopcontacten/schakelaars-en-stopcontacten/zesvoudige-potentiaalvrije-24v-drukknop-met-leds-no-productmodel-niko-9e5189f2-1271-52e7-9f90-159934ee823c) that should be driving some useful effects like volume up/down, next/prev source, room-preset, mute/play, …
- finally I have an “all shut” switch in the house that not only should close the doors, shut the lights but also mute-all zones
- to avoid boredom after the above I am open to wild suggestions: joking, but all should be possible (e.g. bird-song-announcements when the sun rises, family-birthday announcements, personalized text-to-speech-train-commute-delay-messages, and reversely → have the lights flicker - or romantically dimmed ? when certain spotify-tracks are played … 🤷)

So yeah, you might expect some more questions from me while I get through this little project 🙂

Thx already for the fast responses, will do my best to document my progress, share alike, and pass the occasional suggestion, bug-report or PR via github…

---

<div class="post-metadata">

**Author:** ![linknum23](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/linknum23/32/6_2.png) [@linknum23](https://amplipi.discourse.group/u/linknum23)\
**Post date:** [August 19, 2022, 2:26pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/7 "2022-08-19T14:26:21Z")

</div>

Sounds like a fun project. Keep these questions coming.

---

<div class="post-metadata">

**Author:** ![rwarner](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/rwarner/32/84_2.png) [@rwarner](https://amplipi.discourse.group/u/rwarner)\
**Post date:** [March 10, 2023, 9:04pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/8 "2023-03-10T21:04:45Z")

</div>

Similiar to @mpo 's thread here.

Is there a local location on the AmpliPi I can reference an mp3 from using the announce API?

I uploaded an MP3 to  
/home/pi/ampli-dev/web/static/audio/youve-got-mail.mp3

but then I go to use the `announce` endpoint and try both:

- /home/pi/ampli-dev/web/static/audio/youve-got-mail.mp3
- static/audio/youve-got-mail.mp3

but neither work. The example URL does work from nasa, but I’m not looking to host a mp3 file elsewhere.

---

<div class="post-metadata">

**Author:** ![linknum23](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/linknum23/32/6_2.png) [@linknum23](https://amplipi.discourse.group/u/linknum23)\
**Post date:** [March 11, 2023, 12:37am UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/9 "2023-03-11T00:37:42Z")

</div>

Hmm that is weird. I just tested on my test setup with the following media file (included in amplipi for testing)

I browsed to the built in api tester via [http://amplipi.localdoc#post-/api/announce](http://amplipi.localdoc#post-/api/announce)

Then I filled in the **announce** example with the JSON below and clicked **Try**

```auto
{
  "source_id": 0,
  "media": "/home/pi/amplipi-dev/web/static/audio/optical_in2.mp3"
}

```

This example specifies using source\_id 0 to make the announcement (the default is source\_id 3).

Does that work for you?

---

<div class="post-metadata">

**Author:** ![rwarner](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/rwarner/32/84_2.png) [@rwarner](https://amplipi.discourse.group/u/rwarner)\
**Post date:** [March 11, 2023, 6:17pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/10 "2023-03-11T18:17:00Z")

</div>

I went ahead and tried it again today and it seems like it’s working without the need for the source\_id. I could have sworn I was doing everything the same but it is working now with both paths:

- `/home/pi/amplipi-dev/web/static/audio/youve-got-mail.mp3`
- `web/static/audio/youve-got-mail.mp3`

No idea what was going on yesterday.

---

<div class="post-metadata">

**Author:** ![linknum23](https://yyz2.discourse-cdn.com/free1/user_avatar/amplipi.discourse.group/linknum23/32/6_2.png) [@linknum23](https://amplipi.discourse.group/u/linknum23)\
**Post date:** [March 13, 2023, 4:12pm UTC](https://amplipi.discourse.group/t/doorbell-sound-via-amplipi-and-speakers/126/11 "2023-03-13T16:12:23Z")

</div>

Hmm weird. Let us know if you figure out what was going on. Good to know it is working now.
