The Software

You can use the software that I’ve written. It enables you to control your power strip via Telegram and/or MQTT. But you don’t have to. Feel free to write your own software. For instance you don’t need my software if you’re not interested in controlling your power strip remotely. If you do want to write your own software you can stop here. Otherwise you can read on for the next steps.

This part of the project has taken up most of my time to get it finished. I had managed to control the power strip using Telegram quite quickly. And it has operated flawlessly ever since. Only once it didn’t work, and that’s when Telegram suffered from a major network issue. You can’t blame the software for that of course.
Getting the power strip to listen to MQTT was another story. It’s not that it is so difficult to do, but rather it took me quite some time to find the time to get started properly. We have moved house in between, which ate up most of my spare time. With my hobby room almost ready I thought it was time to finish this project so I could finally present it to the world.

This software allows you to control the power strip as a Telegram bot and/or you can control it using your own MQTT broker.

The program is written in Python, currently my favourite programming language on the Raspberry Pi. And it will be started as a service by systemd to assure that it will always be running. Should it crash it will be started automatically again.
Since the program is written in Python the source code is automatically included. I have used ample comments to explain what the program is doing. So please feel free to see how it works, in case you’re interested or want to change some of its behaviour.

Download And Installation

We’ll start with the latest version of Raspbian you can find. I would recommend downloading my version of Raspbian, which you can find elsewhere on my site.

Then, before you put the SD card into your Raspberry Pi Zero W you write a file called wpa_supplicant.conf to the boot sector of the SD card, i.e. the FAT formatted part of the SD card. The file should contain something like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=NL

network={
    ssid="YourSSID"
    scan_ssid=0
    key_mgmt=WPA-PSK
    psk="YourWPA2Password"
    id_str="YourSSID"
}

It goes without saying that you may want to change the SSID and the PSK to match your Wifi network. You can even enter multiple networks to this file and the Raspberry Pi will pick the one it finds first.
While you’re at it you might want to add an empty file with the name ssh to the same boot partition to enable the ssh server. This step can be omitted when you use my Raspbian image, because it is already enabled.

Now you can remove the SD card from your computer and boot the Raspberry Pi Zero W with it. After a couple of minutes tt should login to your Wifi network automatically. Booting the first time always takes longer because the file system has to be resized first. Then you’ll have to find the IP address of your Raspberry Pi. You might find the Android App called Fing very useful for that.
Once you know the IP address you can login to the Raspberry Pi using the ssh command on a Linux terminal, or you can use Putty when you’re on a Windows computer:

ssh [email protected]

I hope you realize that you’ll have to substitute the IP address above tby the one of your Raspberry Pi. At the prompt type the following commands:

mkdir tempdir
cd tempdir
wget "https://www.sbprojects.net/projects/powerstrip/powerstrip.zip"
unzip powerstrip.zip
./install.sh

This will install some dependencies and it will install the python program to your ~/bin directory and setup a systemd server file, which will not be started yet.

This completes the installation. But we’re not done yet. You have to make some configuration settings to make the it work with your MQTT broker and/or your Telegram account.

Next we'll configure Telegram.