MQTT Program Runner

This is the evolution of the script from my other post “Open Applications On Your Computer With Alexa And HA“.

The code and documentation can be found on Github.

Why The Update

I figured that there are probably a lot of people that face the same problem as I did but don’t have the tools or the will to solve it, so I decided to make the script into a proper program and make it easy to use.

After a few months of using the script, I realized a few of things:
First, when I want to add a new command to the script, it has to be added to the python script itself since all the details are hard-coded.
Second, as a result of the first point, anyone else who wants to use the script has to know python and has to have the right version of python and all the packages installed.
Third, after an alteration to the script was made, the program has to be restarted for the changes to take effect.
Fourth, the console window that the script opens is great for debugging, but is not needed and might be confusing for anyone else using the script.

What’s New

YAML

In order to make the configuration of the program easy for non-programmers, I moved the commands definitions to a separate file.

I chose the YAML format specifically since this is aimed for people who work with Home Assistant and are already familiar with the syntax.
It is also not hard to understand if you haven’t seen it before.

Configuration

All the configuration that has to be made to make the program work with your setup is done in the YAML file. This eliminates the need to edit the python file or know python at all.

Moving the config to another file also makes it possible to make changes to the configuration without restarting the program. This is done by adding an option to reload the YAML file and replace the stored commands with the new ones.

Customization

I added the option to customize the icons and toasts to be displayed when a command is triggered.

The message that will trigger a specific command can be customized and no longer has to be the command name nor unique.
This means that it is possible set the same message for multiple commands and by that trigger multiple commands with the same message.
I’m also working on the ability to define multiple messages for a single command, this will allow the option to trigger a command as part of a group (by setting the same message for multiple commands) but also to be triggered separately with it’s own unique message.

Toasts

To add to the user experience and have some feedback from the program when executing a command, I added Toasts that appear when a command is triggered and if the loading of the YAML file fails.

.pyw

In order to not open a console window with the program, all that is needed is to change the file extension from .py to .pyw.

Doing this instead of hiding the window programmatically gives the option to re-enable the window without editing the code or having to pass special arguments or flags to the program. This becomes very useful for debugging.

One caveat of this is that there is no simple way to close the program or know that it is actually running. You’ll have to use the Task Manager or the Command Prompt.
This is taken care of in the next points.

Tray Icon

In order to have an indication of the program running and have a way to interact with it, I added a tray icon with a menu.

The menu offers an option to exit the program, reload the YAML file and disable toasts for command triggers.

.exe

As I mentioned before, I want this program to be accessible to people who don’t care about python or want to install anything extra.
For this, I converted the python project to an executable. This makes the program portable and doesn’t require anything to be installed.

The executable still uses the YAML file for configuration and is based on the .pyw version of the file so it also runs without a console window.

Compatibility

Since I currently only need this for Windows 10 computers, I only added and tested features for Windows 10. I haven’t tested the program with Linux or earlier versions of Windows.

Support for some Linux distributions will probably be added in the future.

If you successfully ran this program on a different operating system, please share your experience so I can fix problems or update this section.

Contribution

This project is released to Github as an open-source project so that further research and development can be done by not only me, but also by other people who use the program and have different needs than me.

If you know how or have ideas, you’re welcome to contact me via the information on this site or contribute code via Github.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s