Skip to content

tomcarlson/mqtt_audio_player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT Audio Player

This project is an MQTT-based audio player daemon that listens for MQTT messages and plays different audio files when specific conditions are met. It can be used to integrate audio notifications into your home automation or IoT projects.

Features

  • Listens to multiple MQTT topics.
  • Plays different audio files for each MQTT topic when a specific condition is met.
  • Supports JSON payload for MQTT messages.

Prerequisites

Before running the MQTT Audio Player, you need to have the following prerequisites installed:

  • Python 3.x
  • Paho-MQTT library
  • Pygame library

You can install the required Python libraries using pip:

pip install paho-mqtt pygame

Usage

  1. Clone the repository to your local machine:
git clone https://github.com/tomcarlson/mqtt-audio-player.git
cd mqtt-audio-player
  1. Configure the MQTT broker settings and audio directory by modifying the script as needed. You can set the following variables in the script:

    • MQTT_BROKER_HOST: The IP address or hostname of your MQTT broker.
    • MQTT_BROKER_PORT: The port of your MQTT broker.
    • AUDIO_DIRECTORY: The directory where your audio files are located.
    • TOPIC_AUDIO_MAPPING: A dictionary mapping MQTT topics to their associated audio files.
  2. Run the MQTT Audio Player script:

python mqtt_audio_player.py

The script will connect to the MQTT broker, listen for messages on the specified topics, and play the corresponding audio files when conditions are met.

Example Configuration

Here's an example configuration in the script:

# MQTT broker settings
MQTT_BROKER_HOST = "192.168.1.200"
MQTT_BROKER_PORT = 1883

# Define the audio directory
AUDIO_DIRECTORY = ""

# Define MQTT topics without /occupancy and their associated audio files
TOPIC_AUDIO_MAPPING = {
    "zigbee2mqtt/HouseLeft Motion": "Left.mp3",
    "zigbee2mqtt/HouseRight Motion": "Right.mp3",
    "zigbee2mqtt/HouseFront Motion": "Front.mp3",
}

In this example, three MQTT topics are defined, and the associated audio files are specified.

Linux Service

To learn how to set this up to run as a service on Linux - see the SERVICE file for details.

Acknowledgments

About

Play audio files if event is detected on mqtt

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages