Simple mqtt command executor to play sounds
.gitignore | ||
go.mod | ||
go.sum | ||
main.go | ||
README.md | ||
structs.go |
MQTT sounder
Simple mqtt command executor to play sounds.
Config example:
mqtt:
address: "tcp://example.com:1883"
username: "mqtt"
password: "${MQTT_PASSWORD}"
client_id: "mqtt_sounder"
command_topic: "notify/sounder/command"
state_topic: "notify/sounder/state"
player:
default_program: ffplay
default_args:
- "-autoexit"
- "-nodisp"
- "-loglevel"
- "quiet"
sounds:
test:
args: ["sounds/test.mp3"] # args appended to default_args
doorbell:
args: ["sounds/doorbell.wav"]
# default:
# program: bash # default_program replaced to program
# args: # default_args replaced to args because program specified
# - "-c"
# - "echo sound not found"
# default:
# args:
# - "sounds/{payload}.mp3" # {payload} replaced to command payload, use only in trusted environment
Password is provided via MQTT_PASSWORD environment variable.
Usage:
mqtt-sounder config.yaml
Systemd unit example:
[Unit]
Description=Play sound via mqtt commands
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Type=simple
User=mqtt_sounder
Environment=MQTT_PASSWORD=xxxxxxxxxxxxx
WorkingDirectory=/opt/mqtt-sounder/
ExecStart=/opt/mqtt-sounder/mqtt-sounder config.yaml
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target