Running Python MQTT Client as a Linux Service

A project log for MQTT Porchlight is an Intranet of Thing

Controlling a Wemo light switch with MQTT and Raspberry Pi

Mike SzczysMike Szczys 12/09/2019 at 20:540 Comments

Home Automation is only useful if it's automatic. So with a proof of concept Python script I needed to turn it into a service. This is pretty easy with systemd. All you need is a "yourservicename.service" file in the /etc/systemd/system folder that calls your script.

Important parts on this are to name the correct user and file location in your service:

ExecStart=/usr/bin/python3 /home/pi/wemoswitch-to-mqtt/


Start it with systemctl (protip, you'll want to use systemctl status yourservicename.service to see if it had errors or is running correctly):

systemctl enable mqtt_porchlight.service
systemctl start mqtt_porchlight.service