Simple mqtt command executor to play sounds
Go to file
2024-05-12 11:49:59 +03:00
.gitignore First commit 2024-05-12 11:49:59 +03:00
go.mod First commit 2024-05-12 11:49:59 +03:00
go.sum First commit 2024-05-12 11:49:59 +03:00
main.go First commit 2024-05-12 11:49:59 +03:00
README.md First commit 2024-05-12 11:49:59 +03:00
structs.go First commit 2024-05-12 11:49:59 +03:00

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