offset \ˈȯf-ˌset\ noun

a force or influence that makes an opposing force ineffective or less effective

Home Assistant Icecast Radio Alarm and Syncthing

Usually when you listen to a radio online, chances are that the stream is coming from the Icecast server. Icecast is an open source project and I've set it up to run on our Raspberry PI in a Docker container.

To generate the music for the Icecast, I use Liquidsoap (also in a separate Docker container like Icecast) and it takes files from a certain folder on the external drive (passing it in the container as a volume via host folder).

The inspiration partially came from Silent Protest talk and then their repo containing Docker images.

Some music is not available on Spotify so I resort to this method as well. Just like the Spotify alarm was set up, the automation for this is done in the Home Assistant in a similar way, but much simpler. You need to call media_player.play_media service and give it the target of the speakers with the source being that music stream from Icecast. It's bound to the local network as well because I am not comfortable exposing the service to the world.

Now here's the kicker. That same folder that is the music source for the Icecast stream is synced among other PCs in the household using Syncthing (also in a separate Docker container). This means we can update the folder with new files and Liquidsoap's configuration periodically scans the changes in the folder and updates the streaming playlist. This is the reload parameter from the Liquidsoap cookbook. I am really happy with how it's all brought together.

Syncthing pierces the local network. It also creates a mesh from the connected instances. I use it to back-up my database on the external server and replicate the file among other synced devices. It involves some terminal commands and an edit of the crontab, as well as having a .pgpass file ready to execute the pg_dump command without a prompt. Remember to have that file owned by the user executing the commands and that the permissions are 600.

# have this in the crontab, for instance as a daily job
# this dumps Postgres database to a certain file with
# a timestamp as a part of the filename, Windows compatible
pg_dump -U {db-user} {db-name} -f /folder/for/syncthing/Sync/{project-name}_`date +\%Y-\%m-\%d_\%H-\%M-\%S`.sql
# to restore, use: $ psql -U {db-user} {db-name} < {dump-filename-from-above}.sql

# to remove backups, also a daily cron job
# this lists all the files in the folder, then
# filters out first 13 entries and
# removes them from the system
ls -t /folder/for/syncthing/Sync/*.sql | sed -e '1,13d' | xargs -d '\n' rm

Because I have an external drive locally and a big enough one on the network, I can sync between devices, cheaply backing-up photos and videos. When I take photos with the GoPro, I move them from the device to the cell phone app and then to the phone system. It ends up in the same folder ready for syncing, courtesy of Syncthing for Android. For now it only backs up the photos of the local parks and scenic spots. It can be sunny here. It's summer after all. We'll make use of this functionality even more once the pandemic passes.

Aside from the alarm radio in the Home Assistant, I also added a Syncthing card in it, using REST integration to say what the usage of it is. That works well, too, and it expands my Home Assistant dashboard with a new functionality. I shamelessly copied the instructions from the community forums.