The Finished Product
The project is available at GitHub in my hs100-status-bar repository.
I have a very noise window unit air conditioner that I turn off during conference calls. This is a hassle if I want to screenshare for only a few moments. I’ve written a small menu bar app that lets me turn it on and off with a click. I wrote a command line client first, but I since I start my conference calls with a mouse, it was easier to use the menu bar app.
TP-LINK HS100 Wi-Fi Smart Plug
The HS100 is a wifi enabled smart plug that works with a phone app and Amazon Echo. It allows you turn on an off an appliance at 120 volts and up to 15 amps. This is plenty for a small window air conditioning unit.
The HS100 doesn’t have a open API for the device. However, George Georgovassilis has done a wonderful job of documenting the commands available to the device. This has opened up the devices to scripting from a variety of languages, and I’ve based my project on the work from Josh Kleinpeter.
I purchased mine at Amazon. If you’re interested in the project, here’s an affiliate link for you to purchase the HS100 at Amazon.
Menu Bar Apps with Rumps
Rumps exposes Objective-C classes as Python classes and greatly simplifies the process of creating a statusbar application. It makes it very straight forward to create a little app that lists the available devices on the network and gives a toggle to turn them on and off.
Rumps is no longer under active development. However, it’s stable, easy to use, and has a small footprint. It’s got everything we need for this little task.
In keeping with the theme of hacking this out - the project is a single file. It’s simple, really simple. j05h has been a valuable contributor with great enthusiasm, and he wrote the original API interface on which this is based.
When you initial setup an HS100 device via the phone app, you give the device a name. This name is then available via the API. We use this name in the Rumps app. The devices also expose their current state of on/off, and we use that to set the base state of the Rumps toggle switch.
We have a very simple API Class that exposes methods for
meter. I’m using the less expensive HS100, and so the
meter isn’t available. However, if you had the HS110 with the energy meter, this would be a great thing to wrap into this app. A pull request would be very welcome!
Rumps allows us to establish a callback for a toggle menu item, and we’ll simply call our
off method when we click on the item.
Building the App
It also copies the icon into the application folder so that it is available to Rumps.
This is a quick little app that has made a big difference in my office. It’s quick and easy to use, and I’ve had a great time writing some Python again. If you try it out, please let me know by dropping me a note at @there4dev.