Sunday, July 3, 2022

MQTT

Some of the device I have integrated into my smart home use MQTT to communicate to Home Assistant. Since MQTT is a widely used protocol, utilities exist for most existing systems.  While I still don't understand completely the underlying protocol of MQTT, it seemed like the best route to setup a custom sensor to get feedback from a script on my Linux system for ripping backups of discs. 

I simply had to mosquitto_pub entries to the the existing shell script that automates the process in order to know the status of process.  Since I only really care to know when I need to get up to swap a fresh disc into the system I simply report 1 when the tray is open and 0 when the ripping is in progress.


On the Home Assistant side it was simple to add a binary sensor to subscribe to the topic and messages I specified in the shell script. This allowed me add an automation to flash my WLED bias lighting on my desk with a specific color scheme for a minute to let me know it has completed.








Additionally I decided to try something new by using this to add tracking data for this process in Home Assistant. To track the number of discs ripped I added  a counter helper to store the data.  The automation that I created for the notification light was adjusted to call the counter increment function to track the number of discs I have ripped. I will be manually setting the current count to reflect discs that were ripped before this was integrated. 









While I normally like to link back to the appropriate project when talking about projects, I have chosen not to do so here due to legal implications of specifying the content of the discs being ripped. I will simply say the software doing the ripping is widely considered the go to solution and is free but not open source. The script for automating the ripping is separate but also easily findable. 

Update:
After clearing the backlog of discs I had sitting around I realized that I could also make use of this MQTT data to intelligently save power when I am not actively ripping discs. I have configured the automated script to run as a service on startup (which required a small re-write of the ripping automation script to avoid using paths based on executing user) and configured the BIOS to power on when power is restored. With those settings and by adding a smart plug I was able to create an automation so that if the tray is open for 1 hour the power is cut. Then when I want to resume ripping discs I just have to turn the smart plug back on with either a voice command, through Home Assistant, or by directly hitting the physical button. 

No comments:

Post a Comment

Server Monitoring

I have a headless Linux server that I have previously written about for ripping media disks.  While I have had MQTT integrated into the bash...