-
Notifications
You must be signed in to change notification settings - Fork 397
Smart Home remote control with MQTT
This module will integrate Phoniebox into a Smart Home environment and make it remotely controllable. It can be read out and controlled through MQTT which is widely supported in Smart Home environments. Several clients can connect to a MQTT server and exchange messages there just like in a chat room. Every MQTT client will publish messages and will also listen for messages. To make your Smart Home tool of choice talk to Phoniebox and vice versa both need to connect to a MQTT server that mostly comes with the Smart Home environment (e.g. openHAB comes with Mosquitto). Phoniebox will automatically publish current status information periodically and in parallel listen for command messages from any MQTT client. Please refer to your Smart Home tool's documentation on how to setup MQTT for it. It will need to be able to listen for messages and also send messages to Phoniebox' "chat room" (=topic in MQTT terms).
- let your Smart Home control Phoniebox based on time schedules
- disable wifi in the evening when Phoniebox is used as a sleeping device
- shutdown at night when it's finally bedtime
- lower the volume in the mornings (to keep you asleep)
- control Phoniebox via Voice Assistants like Snips (which also uses MQTT!), Google Home, Amazon Echo,...
- let Phoniebox play an informational note to your kids that the weather outside is great and they should consider going outside (if your Smart Home has weather-based sensors)
- run statistics on when and how your kid uses Phoniebox
- arrange terms with your kid how long the Phoniebox can be used (e.g. max. 2h per day)
- monitor if your kid complies with those terms or enforce them if need be
Phoniebox' MQTT client connects to the MQTT server that is defined in the SETTINGS
section of the script itself. It is able to connect by authenticating...
- with username and password
- with server and client certificates
Please check your MQTT server configuration regarding which authentication method it is configured to use. Once connected to the MQTT server it will publish messages to the mqttBaseTopic
that is defined in SETTINGS
(defaults to phoniebox
, we will use this default topic from now on on this page). Other MQTT clients that are e.g. part of a smart home solution can listen and respond to this base topic and its sub-topics.
Phoniebox' MQTT client will do the following things:
- at startup send state and version info about Phoniebox to
-
phoniebox/version
(e.g. 1.2-rc1) -
phoniebox/edition
(e.g. classic) -
phoniebox/state
(online) -
phoniebox/disk_total
(disk size in Gigabytes) -
phoniebox/disk_avail
(available disk size in Gigabytes)
-
- at shutdown send state info to
-
phoniebox/state
(offline)
-
- periodically send all attributes to
phoniebox/attribute/$attributeName
(this interval can be defined throughrefreshIntervalPlaying
andrefreshIntervalIdle
in theSETTINGS
section) - listen for attribute requests on
phoniebox/get/$attribute
- listen for commands on
phoniebox/cmd/$command
(if a command needs a parameter it has to be provided via payload)
MQTT clients can (additionally to the periodic updates) request an attribute of Phoniebox. Sending an empty payload to phoniebox/get/volume
will trigger Phoniebox' MQTT client to fetch the current volume from MPD and send the result to phoniebox/attribute/volume
.
- volume
- mute
- repeat
- random
- state
- file
- artist
- albumartist
- title
- album
- track
- elapsed
- duration
- trackdate
- last_card
- maxvolume
- volstep
- idletime
- rfid (status of rfid service [true/false])
- gpio (status of gpio service [true/false])
- remaining_stopafter [minutes left until "stop" is triggered]
- remaining_shutdownafter [minutes left until shutdown]
- remaining_idle [minutes left for the idle shutdown timer]
Sending empty payload to phoniebox/get/help
will be responded by a list of all possible attributes to phoniebox/available_attributes
MQTT clients can send commands to Phoniebox. Sending an empty payload to phoniebox/cmd/volumeup
will trigger Phoniebox' MQTT client to execute that command. If the command needs a parameter it has to be provided in the payload (e.g. for setmaxvolume
a payload with the maximum volume is required).
- volumeup
- volumedown
- mute
- playerplay
- playerpause
- playernext
- playerprev
- playerstop
- playerrewind
- playershuffle
- playerreplay
- scan
- shutdown
- shutdownsilent
- reboot
- disablewifi
- setvolume [0-100]
- setvolstep [0-100]
- setmaxvolume [0-100]
- setidletime [in minutes]
- playerseek [e.g. +20 for 20sec ahead or -12 for 12sec back]
- shutdownafter [in minutes; 0 = remove timer]
- playerstopafter [in minutes]
- playerrepeat [off / single / playlist]
- rfid [start / stop]
- gpio [start / stop]
- swipecard [card ID]
- playfolder [folder name (not path)]
- playfolderrecursive [folder name (not path)]
Sending empty payload to phoniebox/cmd/help
will be responded by a list of all possible commands to phoniebox/available_commands
and phoniebox/available_commands_with_params
All relevant files can be found in the folder:
components/smart-home-automation/MQTT-protocol/
See also here for details: https://github.com/MiczFlor/RPi-Jukebox-RFID/tree/master/components/smart-home-automation/MQTT-protocol#installation
- The daemon is run by executing the script
daemon_mqtt_client.py
which will run in an endless loop. - There's a sample service file (
phoniebox-mqtt-client.service-default.sample
) that can be used to register the daemon to be run at bootup. - It is currently not integrated into the one-line-install script so please run the following commands to do it manually.
First step: copy files to destination locations:
# First copy the daemon script and service config file to the correct directory:
sudo cp /home/pi/RPi-Jukebox-RFID/components/smart-home-automation/MQTT-protocol/daemon_mqtt_client.py /home/pi/RPi-Jukebox-RFID/scripts/
sudo cp /home/pi/RPi-Jukebox-RFID/components/smart-home-automation/MQTT-protocol/phoniebox-mqtt-client.service-default.sample /etc/systemd/system/phoniebox-mqtt-client.service
Now edit the file /home/pi/RPi-Jukebox-RFID/scripts/daemon_mqtt_client.py
to match your requirements.
Now continue and activate the service.
# Now systemd has to be notified that there's a new service file:
sudo systemctl daemon-reload
# Now enable the service file, to start it on reboot:
sudo systemctl enable phoniebox-mqtt-client
# And now you can reboot to have your daemon running or start it manually:
sudo systemctl start phoniebox-mqtt-client
# To see if the reader process is running use the following command:
sudo systemctl status phoniebox-mqtt-client
If you like Phoniebox, consider: buy me a coffee or PayPal
- Code: https://github.com/MiczFlor/RPi-Jukebox-RFID
- Phoniebox home page: English | Deutsch
Phoniebox is a contactless jukebox for the Raspberry Pi, playing audio files, playlists, podcasts, web streams and spotify triggered by RFID cards. All plug and play via USB, no soldering iron needed. Update: if you must, it now also features a howto for adding GPIO buttons controls.
Visit Phoniebox.de
π₯ Version 3
- β Releases
- π΅ Install Jukebox Version 3
- π Report a bug
- π Propose a feature
- βοΈ Feature Status
- π Documentation
- π©βπ» Development
- βοΈ Contributing
- π¦ Code
πΆ Version 2
- β Releases
- π΅ Install Jukebox Version 2
- π Report a bug
- βοΈ Features
- π Documentation
- βοΈ Contributing
- π¦ Code
Version 2 Pages
-
Setup / Upgrades
- Synchronising Phonieboxes in a local network
- Smart Home remote control with MQTT
- Hardware Pinout Overview
- Systemwide Equalizer
- Phoniebox with read-only Filesystem
- HiFiBerry Soundcard Details
- WM8960 Hi-Fi HAT
- PAM8403 Amplifier Power Off
- TPA3118 Amplifier Power Off and EMI improvement
- External Non USB Audio DAC ES9023, PCM5102, etc.
- On-board LEDs with fibre optics
- Setting GPIOs at boot time
- Stop on removal with USB RFID Reader
- Firmware update improves audio out
- Architecture