forked from bitlair/ansible
music: Update mpd-volume-to-mqtt script
This commit is contained in:
parent
40093a5936
commit
84e3dc8478
5 changed files with 69 additions and 0 deletions
|
@ -1 +1,2 @@
|
||||||
music_audio_user: audio
|
music_audio_user: audio
|
||||||
|
music_mqtt_mpd_volume: bitlair/music/space/volume
|
||||||
|
|
|
@ -23,3 +23,9 @@
|
||||||
name: soundboard
|
name: soundboard
|
||||||
state: restarted
|
state: restarted
|
||||||
daemon_reload: true
|
daemon_reload: true
|
||||||
|
|
||||||
|
- name: restart mpd-volume-to-mqtt
|
||||||
|
systemd:
|
||||||
|
name: mpd-volume-to-mqtt
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: true
|
||||||
|
|
|
@ -5,3 +5,28 @@
|
||||||
- jackd
|
- jackd
|
||||||
- mpd
|
- mpd
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
- name: Install mpd-volume-to-mqtt script
|
||||||
|
template:
|
||||||
|
src: mpd-volume-to-mqtt.sh
|
||||||
|
dest: /opt/mpd-volume-to-mqtt.sh
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
notify: restart mpd-volume-to-mqtt
|
||||||
|
|
||||||
|
- name: Install mpd-volume-to-mqtt service
|
||||||
|
template:
|
||||||
|
src: mpd-volume-to-mqtt.service
|
||||||
|
dest: /etc/systemd/system/mpd-volume-to-mqtt.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
notify: restart mpd-volume-to-mqtt
|
||||||
|
|
||||||
|
- name: Enable mpd-volume-to-mqtt
|
||||||
|
systemd:
|
||||||
|
name: mpd-volume-to-mqtt
|
||||||
|
state: started
|
||||||
|
enabled: true
|
||||||
|
daemon_reload: true
|
||||||
|
|
16
roles/music/templates/mpd-volume-to-mqtt.service
Normal file
16
roles/music/templates/mpd-volume-to-mqtt.service
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=MPD Volume to MQTT
|
||||||
|
After=network.target
|
||||||
|
Requires=mpd.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=always
|
||||||
|
RestartSec=2s
|
||||||
|
ExecStart=/bin/bash /opt/mpd-volume-to-mqtt.sh
|
||||||
|
DynamicUser=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
21
roles/music/templates/mpd-volume-to-mqtt.sh
Normal file
21
roles/music/templates/mpd-volume-to-mqtt.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
|
||||||
|
trap 'mqtt-simple -h {{ mqtt_internal_host }} -p '{{ music_mqtt_mpd_volume }}' -m "" -r' EXIT
|
||||||
|
|
||||||
|
prev_volume=x
|
||||||
|
|
||||||
|
(echo mixer; mpc idleloop) | while read event; do
|
||||||
|
if [ $event = "mixer" ]; then
|
||||||
|
volume=`mpc volume | sed -nr 's/^volume: ([0-9]+)%$/\1/p'`
|
||||||
|
if [ "$prev_volume" != "$volume" ]; then
|
||||||
|
mqtt-simple -h {{ mqtt_internal_host }} -p '{{ music_mqtt_mpd_volume }} -r' -m "$volume"
|
||||||
|
fi
|
||||||
|
prev_volume=$volume
|
||||||
|
fi
|
||||||
|
done
|
Loading…
Add table
Reference in a new issue