Switch power outlets on and off with home automation tools

If This Then That

A serious disadvantage of the device is obviously that it defines its own proprietary communication protocol. Unfortunately, this is the norm among home automation products. As a result, they only work with the individual manufacturer's not particularly original apps, and the open source community has either reverse-engineered the protocols used, had to dive into the details of a another quirky API, or been left out in the cold entirely.

However, fortunately, the trendy Internet company IFTTT [5] has set out to provide a convenient abstraction layer around this protocol confusion. Using the "If This Then That" paradigm, it lets you create logical connections between events. Integrating these events using an API would require a lot of brainpower and developer hours in the real world. Instead, the service generates rules from conditions (This), which in turn trigger actions (That). With just a few mouse clicks, you can permanently establish these rules.

The This clause defines an input channel, such as "At this time" or "When it rains" or "When this YouTube video goes viral." That refers to initiated actions such as "Send me an email" or "Post this tweet" or "Turn on this device." The example in Figure 5 illustrates how IFTTT sends email if it's going to rain tomorrow.

Figure 5: The IFTTT service triggers actions when predefined events occur.

IFTTT has all sorts of ready-made channels that trigger an event: Weather Channel events like sunrise, rain, or sunshine are triggered as those natural phenomena occur at the user's location; various security components also trigger an alarm if a sensor in the house reports a break-in. Falling or rising stock prices can also trigger events.

People wanting to use a channel on access-controlled servers like GitHub or Gmail don't need to store a password on IFTTT.com; instead, you are guided properly through the OAuth web flow of these applications. The applications then prompt you to confirm that IFTTT.com may now perform selected actions under your user ID on the specific service. As usual with OAuth, you can withdraw permission at any time. The password never leaves the original service, and IFTTT.com works with tokens of limited validity.

Because programmers are often recruited from the open source scene to code the nitty gritty of the interface between IFTTT and a service (which the end user subsequently just has to select), the channels are consistently very good and implemented with the latest security guidelines in mind.

The arsenal of output actions triggered by events includes email and text messages, push notifications, on/off switches like WeMo, and more. The possible combinations of inputs and outputs, called "recipes," therefore appear to be almost unlimited, and the contributing developers imagination assumes astounding levels.

Setting Rules with a Mouse Click

Communication between the smartphone app and the Belkin server can only be achieved by use of an SDK, but the WeMo app already has built-in integration with IFTTT.com. If you want to switch the WeMo on and off using IFTTT, simply subscribe to the WeMo Switch channel and provide a PIN to IFTTT.com, which the WeMo app generates on request in the Settings menu (Figures 6 and 7 ).

Figure 6: The WeMo app generates a PIN …
Figure 7: … which IFTTT accepts and can use to control the WeMo Switch remotely.

Now, IFTTT has the keys to the kingdom of remotely controlling the WeMo switch. In conjunction with a triggering input channel, it can now switch on local electrical devices when predefined events occur, as well as with uncommon events, such as rising share prices, or the arrival of tweets.

Alarm for GitHub Issue

If you have a project on GitHub, you can now simply create a new IFTTT recipe to switch on a light or siren each time a new GitHub issue is created in your project. To do so, you need to subscribe to the GitHub channel and the WeMo Switch channel and then link the New Issue section of the GitHub channel as an input to the WeMo Switch channel as an output action (Figure 8).

Figure 8: Each new GitHub issue switches on the WeMo Switch.

The IFTTT server needs to continuously check many such recipes, so once the input is initiated, it might take a while for the output to be activated. In my tests, the delay between creating a GitHub issue and the switching action was about two minutes. Nevertheless, it is fascinating to see how easy this kind of link can be made and how many possibilities for home automation are opened this way.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Programming Snapshot – Power Outages

    A power failure can cause the IQ of a smart home to plummet suddenly. An emergency power supply and a script on the SmartThings platform can prevent a total outage and inform the owner. The polyglot Perlmeister embarks on a foray into the territory of the Groovy scripting language in this issue.

  • Programming Snapshot – Driving Data

    A connector plugged into the diagnostic port of Mike Schilli's cars sends current information such as speed, acceleration, and fuel economy via the mobile phone network to a cloud service. An app and a programmable API read out the data and provide stunning visualizations.

  • Universal Plug and Play

    Universal Plug and Play provides an easy framework for seamless integration of network devices. Learn how to build your own UPnP solution using the open source BRisa framework.

  • FOSSPicks

    Graham checks out Sigil, Dragonfly Reverb, LabPlot 2.8, Node-RED, batufo, rg3d, and much more.

  • Tasmota

    Flashing IoT devices with new firmware lets you wield control and keep them out of the cloud.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters