Skip to main content

A simple Linux-based doorbell, which plays the mp3 bell ringtone upon receiving an MQTT message.

Project description

Simple MQTT Door Bell

A simple Linux-based doorbell, which plays the mp3 ringtone upon receiving a special MQTT message.

The main idea is to create a system service, which can play an audio file upon receiving the message from the MQTT message broker. This may be useful for configuring sound notifications or alarms in the Home Assistant automations.

This module also supports random ringtones based on a pattern. This means the same message may result in random ringtones being played based on the pattern received in the MQTT message.

Supported platforms

This solution has been tested on Ubuntu 22.04, but most likely will work on other Linux distros, with minor changes.

Prerequisites

  1. Mosquitto MQTT message broker installed and accessible from the deployment machine. You will need to create credentials (user/password) on the MQTT broker server for this solution.

  2. MP3 player utility, which can play mp3 files from the command line, installed on the host machine. I used mpg123 but other options should work as well.

  3. Python verison >= 3.10 + pip.

Installation

First please ensure all pre-requisites are in place. Testing your MP3 player from the command line on the host where you plan to deploy this tool is the first step - you need to ensure that mp3 files are played as expected.

Please note that the following commands will require administrative grants, so please don't forget to start them with sudo if required.

For example, here is the command for the mpg123 utility:

$ mpg123 -qf32768 -adefault:CARD=Speaker /path/to/ringtone.mp3

In this command, the number after the -qf option represents the volume, which can range from -32767 to 32768.

Second, we need to create a user profile, which will run the mqtt-doorbell service:

$ useradd -M doorbell
$ usermod -L doorbell
$ groupadd doorbell
$ usermod -a -G doorbell,audio doorbell 

Install the solution with the following command (must be under sudo!):

$ sudo pip install mqtt-doorbell

Next step is to configure the mqtt-doorbell service

Configuration

First we need to create the configuration file doorbell.conf in the /etc/mqtt-doorbell folder. The file should be as follows:

[broker]
server	 = localhost
port	 = 1883
user	 = mqtt_user 
password = mqtt_password
topic	 = doorbell/ring

[bell]
default_ring  = classic-doorbell
mp3player_cmd = mpg123 -qf32768 -adefault:CARD=Speaker

Please ensure to update the MQTT broker username and password accordingly.

Then, we need to create the mqtt-doorbell.service service configuration file in the /lib/systemd/system folder, as follows:

[Unit]
Description=MQTT Doorbell Service

[Service]
WorkingDirectory=/etc/mqtt-doorbell/
ExecStart=/usr/bin/python3 -m mqtt-doorbell.valet
Type=simple
User=doorbell
Group=doorbell
Restart=always

[Install]
WantedBy=multi-user.target

Next, we need to create a media folder /etc/mqtt-doorbell/media and place there all the mp3 files we want to use as ringtones. You may download the ringtones from here or use your own mp3 files.

Finally we can enable and start the service:

$ systemctl enable mqtt-doorbell.service
$ systemctl start mqtt-doorbell.service

Usage

In order to trigger the ringtone you will need to send the following MQTT message to the doorbell/ring topic:

{"ringtone": "filename_pattern"}

where the filename_pattern should match the name of an MP3 file or files in the media folder. A random ringtone from the search result will be played in case of multiple match.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mqtt_doorbell-0.1.4.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mqtt_doorbell-0.1.4-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file mqtt_doorbell-0.1.4.tar.gz.

File metadata

  • Download URL: mqtt_doorbell-0.1.4.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.12

File hashes

Hashes for mqtt_doorbell-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e47c1a261e183ab047207254799976d0e512e19d8ec8672660d6706098a7ca59
MD5 170d757096d752f365c629156ff09380
BLAKE2b-256 fc93c4874c75c551c65bda042f660f7b7e5ca65d5c341fd79d5879eeab0598dd

See more details on using hashes here.

File details

Details for the file mqtt_doorbell-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: mqtt_doorbell-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.12

File hashes

Hashes for mqtt_doorbell-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 18f4656ae4dc5e5749c2cdd4e306ec94fd3d9a854d23b451229fbc6782231e67
MD5 d514ec42fefb568ba94f24992b66cdb3
BLAKE2b-256 d55b7c937f0a28f5ebbb28e41f77e6b0e2cbb2bcdb7335bcd5d89e1f8723322d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page