Controlling teleruptors using Apple Homekit

22 October 2023
Homekit ecosystem

Let's say you want to start controlling and automating (part of) your teleruptor-equipped domestic electrical installation using Apple Homekit.

Before we dive into the technical details, let's first explain how a teleruptor-based system actually works and how it compares to a classic electrical system. 

Adding smarts to a classic electrical system

In a "classic" electrical installation, the light switches are tightly-coupled (hard-wired) to the lights they control. This means there are wires going from your fusebox to your switches and from your switches to your lights. If you want to enable home automation for this kind of installation, you generally have 2 options:

  • Smart Wi-Fi switches to be built into your walls (a popular one being the Shelly 1L)
  • Smart lightbulbs like the ones offered by Philips Hue

 

Shelly 1L in-wall Wi-Fi switch

These are OK as a retrofit solution, but they have some important disadvantages:

  • Scale: in the case of smart Wi-Fi switches, you need a separate Wi-Fi switch for every series of lights. In case of smart lightbulbs: you need to replace all your classic bulbs with smart bulbs
  • Cost: the automation cost increases linearly when you add switches or bulbs. Next to that, if you are into the Apple ecosystem: Homekit-compatible smart gear tends to be more expensive compared to solutions designed to be compatible with Google Home or Amazon Alexa.
  • Reliability: both solutions rely on wireless communication (Wi-Fi or other radio protocols like Zigbee), which are prone to dropped connections, bad wireless signal, etc.
  • Complexity: some of these solutions require to install some sort of hub which bridges the wireless signals to ethernet. Each brand tends to have their own hub (e.g. the Hue Bridge). Luckily, Matter promises to streamline this landscape in the future. If you plan to buy into such a solution, look out for Matter-compatible gear.
  • Usability: each brand ecosystem comes with its own app, meaning you need multiple apps on your phone to operate all your smart equipment. This makes things cumbersome to use and prevents proper automations across solutions from different brands.

Bottom line: retrofit solutions are fine if you are stuck with a classic electrical installation, but they are far from ideal. If your wiring is still to be done, you should look into a more modern wiring scheme.

The big boys in town

If you wired your house like 10 years ago, the domotica and home automation market was still very immature and expensive. Solutions like KNX, Niko Home Control or Loxone (see image below) have a wide range of capabilities, but are very expensive and lock you to a specific vendor (parts, maintenance, etc.). Moreover, you need a technical background to configure these solutions, set up automations, configure scenes, etc. In the end, you also don't want to throw this complexity over your family members in any case: if the software fails, you should still be able to operate all basic appliances by simple push buttons!

A full Loxone domotica installation

Future-proof wiring

What you are looking for is a decent wiring system which allows you to add home automation in the future once more simple and easy-to-use technology becomes available.

The key aspect here is that you never hardwire switches to electrical equipment. NEVER. This goes for lights, switched outlets, electric shades, shutters, your garage door engine, your door bell, etc. It might cost you a bit more on the wires, but this setup gives you all the flexibility you need in the future.

Enter teleruptors

So how do you switch your lights when using a centralized wiring system? Somewhere, you need to hook up your light switches to your lights. A teleruptor does just that: it sits between the push-button wires and the light wires. Note that in this kind of system, your light switches are stateless, meaning they are essentially push-buttons (e.g. the Niko 170-70001, which can control 1 series of lights). When you operate a push-button, a low-voltage (often 24V) pulse is sent to the teleruptor. The teleruptor reacts to this pulse by flipping its state to allow electricity to flow or stop flowing to the associated lightbulb. A widely used solution is the Eltako S12-200 teleruptor, which is a basic bipolar teleruptor (see image below).

Wired teleruptors

These teleruptors are installed in or near your central fusebox. This is exactly where you want to be, since you have 1 single place where you can throw in a software-based controller to trigger these teleruptors. So how do we get started? Remember, our goal here is to control certain light circuits using the Apple Homekit procotol.

In general, there are 2 solutions here:

  1. Swap (some of) your teleruptors with off-the-shelf smart relays (e.g. the Shelly Pro 1 or the Loxone system mentioned above)
  2. Build your own smart relay and put these parallel to your existing push buttons! 😁

For both of these solutions, keep in mind that your will need some sort of software-based "bridge" to make your relay(s) communicate with Apple Homekit. More on that later.

For this tutorial, we are only going to go into solution 2.

Hardware

Like mentioned above, the idea is to insert a smart relay in parallel to our existing push buttons. This means that the smart relay is on the same level as the push buttons and is pushing a 24V signal to the teleruptor, resulting in the latter to switch the light on or off. So our smart relay is only dealing with low-voltage electric flow, not with 230V.

As a foundation for our smart relay, I highly recommend to use a Raspberry Pi. It has a number of general purpose input/output (GPIO) pins, which we can use to drive a separate relay board. The Raspberry Pi 5 will be released soon, which is the one you want to get to get the latest chipset and features. For the relay board itself, there are various options available. I would suggest to go for a "HAT" solution (Hardware Attached on Top), since you don't need any intermediate breadboards or such. It mounts directly on the GPIO pins of the Pi. With this Raspberry Pi 8-Channel Relay Expansion Board, you will be able to drive 8 teleruptors / light circuits.

 

Wiring

Warning: do not mess with electronics if you don't know what you are doing. Always cut off the power from your circuits if you want to change things. Consult a professional in case of any doubt.

Let's wire things up:

Wiring scheme

As you can see in the diagram above, we hook up our relay board parallel with our wall push button (yellow dotted lines). Adjust the wiring according to your type of push button, type of relay board and teleruptor type.

How does this circuit works? There are now 2 ways to trigger our teleruptor:

  1. When the push button is pushed and released
  2. When the respective relay on our relay board is opened and closed again

In both of these cases, a 24V signal is passed to the teleruptor which in turn changes its state and turns the light on or off.

These type of teleruptors are build to be triggered by a human manually pushing a button. This action takes around 200ms. So what we need to do now is ensuring the respective relay on our relay board closes the circuit for around 200ms and then opens up again. To do this, we will write a small script on our Raspberry Pi.

Software

OK, back to our end-goal for second: making sure we can use Homekit to trigger our teleruptors. A key software ingredient to make this possible is the wonderful Homebridge package.

Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It supports Plugins, which are community-contributed modules that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of "smart home" devices.

To get started with Homebridge, install Raspberry Pi OS on your Raspberry Pi or go for the off-the-shelf Homebridge image for Raspberry Pi.

Next, we need a special Homebridge plugin to trigger our relay board. We will rely on the omnivalent Script2 plugin for this. This fantastic plugin allows you to execute any script when you operate a Homekit accessory and write the state of this accessory to disk. This is beautifully simple and it even allows for the correct accessory states to be recovered after a power failure! You can add this plugin using the Homebridge UI.

Now we are ready to start playing with the GPIO pins and make our relay board do what we want. Check out the official documentation if you want to learn the details of the GPIO header.

In essence, we will use a custom Python script for this. This script gets called by the Script2 plugin and does mainly 2 things:

  1. Trigger a certain relay on the relay board, depending on which pin you pass as a parameter to the script
  2. Set or remove the flags which indicate the teleruptor state (files on disk)

To use this script, place it in a separate directory in your home directory. Make sure this file is executable using the chmod command. Also create an empty "flags" directory. Make sure this directory is writable (also using the chmod command).

$ mv hb_script2_gpio.py /home/@user@/homebridge_script2/
$ mkdir /home/@user@/homebridge_script2/flags
$ chmod +x /home/@user@/homebridge_script2/hb_script2_gpio.py
$ chmod -R 700 /home/@user@/homebridge_script2/flags

Finally, install the rpi.gpio package to be able to communicate with the GPIO pins from within the Python script:

$ sudo apt-get install rpi.gpio

Now you should be able to do the first test of your setup! Run the following command with the correct pin number (check out the GPIO documentation and the documentation for your relay board to find out which pin to trigger, corresponding to the relay hooked up to your teleruptor)

$ /home/@user@/homebridge_script2/hb_script2_gpio.py @pin@ on
$ /home/@user@/homebridge_script2/hb_script2_gpio.py @pin@ off

When running these commands, you should hear a click sound from the corresponding relay on your relay board. Furthermore, you should see a flag appearing/disappearing in your flags directory.

To finish things off, we should add our teleruptor as an accessory to our Script2 plugin config. You can omit the state, on_value and unique_serial parameters:

"accessories": [
  {
    "accessory": "Script2",
    "name": "Light 1",
    "on": "/home/@user@/homebridge_script2/hb_script2_gpio.py @pin@ on",
    "off": "/home/@user@/homebridge_script2/hb_script2_gpio.py @pin@ off",
    "fileState": "/home/@user@/homebridge_script2/flags/pin_@pin@.flag"
  }
]

Finally, add your Homebridge system to the Apple Home app.

You should now see your accessories pop up, as defined in your Script2 plugin configuration. Tap the icon in the Home app and your connected light should turn on!

Important note: when you push the button, the state of the light will obviously not be updated in the Home app. The idea is to have the push button still available in case of problems with your Pi. However, you should not use it when working with the Home app. This setup is ideal for lights which are mainly triggered by Homekit automations.   

The new iMac 24-inch

20 April 2021
New iMacs in multiple colors

Today, Apple introduced the new iMac 24-inch. Based around the new M1 chip debuted last year, this surely will be a blazingly fast machine. A few initial observations:

  • The new colors definitely look cool (unfortunately, a black option is missing)
  • Only USB-C / Thunderbolt ports, no USB-A or card reader
  • The power supply is now a separate brick, which was probably required given the thin design (only 11.5 mm!). The brick itself is not color-matched with the iMac body.
  • The power brick includes an ethernet port, which is quite smart I think
  • New Magic Keyboard, Magic Mouse and Magic Trackpad are color-matched with the iMac body.
  • The front of the new iMac has nearly white bezels. At first sight, this looks extremely weird to me. Practically all other Apple devices have black bezels... Not sure why they went with such light bezels for the iMac.
  • The typical iMac "chin" is still there, but the Apple logo has been removed. This too is rather strange... Looks like those iMacs they use in TV shows, were they tape over the logo.
  • No word on a bigger screen size comparable to the current iMac 27-inch (which is still for sale). Maybe that version might get a more dark design with black bezels, who knows...

It's a bit ugly indeed, so I fooled around a bit and did some manipulations to the design :-) The mockups below show how the iMac would look like with black bezels and additional Apple logo on the chin.

Silver iMac mockup with black bezels and front Apple logo
Yellow iMac mockup with black bezels and front Apple logo
Blue iMac mockup with black bezels and front Apple logo, together with MacBooks and Mac Mini

To me, that looks a lot more inline with the rest of the line-up. Furthermore, black bezels tend to be more easy on the eyes as a frame for the content displayed on the screen.

The current Mac line-up

17 June 2020

On the occasion of recent rumblings concerning the iMac getting a potential refresh very soon, I looked into the current Mac line-up as a whole. Turns out, Apple has a pretty decent and clear Mac offering nowadays.

The Mac product strategy anno 1998

Take a look at the video below of Steve Jobs introducing the very first iMac in 1998:

He starts off by discussing the Mac product strategy from that time, using a simple quadrant. Back then, there were two main product categories: desktops and portables. Jobs also identified their target audiences: both consumers and professionals. This resulted in a line-up of 4 Macs.

The Mac line-up anno 2020

If you look at today's Mac offering, the products can be organized in a similar way. Except now Apple offers Macs in three product categories. Mac desktop computers can be divided in two subcategories (see image below): all-in-one desktops and modular desktop systems in which the computer itself is separated from it's peripherals (keyboard, pointing device and display).

Grid showing the current Apple Mac line-up

Cool thing is that, except for the iMacs, all products are in good shape. The list below shows an overview of recent product refreshes:

  • Mac mini: March 2020
  • Mac Pro: December 2019
  • MacBook Air: March 2020
  • MacBook Pro: 13 inch: May 2020 / 16 inch: November 2019

The iMac had its latest refresh in March 2019, while the iMac Pro was never updated since its release in December 2017. New iMacs would really make the current Mac offering complete. I would also welcome a new industrial design (the current design dates back to October 2014). Let's see what Apple will announce next week during WWDC...

Compare this to the situation we were in a couple of years ago:

  • There was no real viable offering for Apple notebooks: underpowered and pricey 12 inch MacBook + a horrible keyboard on all the MacBooks from the previous generation
  • Professionals were begging for a true modular desktop Mac (the "trash can" Mac Pro was unable to fulfill the needs of the most demanding customers

The ultimate Toolgasm

15 May 2020

A Toolgasm is a place in a Tool song or album where the listener achieves maximum listening pleasure. ― Urban Dictionary

Whenever I hear Tool playing, I still think back to the Tool show last summer at Rock Werchter. Specifically the whispering of Maynard ("hey hey hey hey hey hey hey hey...") kicking off the show with Ænema, followed by a supercrisp guitar intro and very impressive lightning effects. The video below shows the start of that show.

That was a quite an impressive gig, probably the most impressive live performance I've ever seen (together with Pearl Jam in 2007 and Neil Young in 2008). Personally, I would classify the start of that show as a Toolgasm ?

I though it would be cool to share my personal Toolgasm top 5:

  1. Stinkfist (4:18)
  2. Right In Two (6:43)
  3. 7empest (14:15)
  4. Descending (7:07)
  5. Culling Voices (6:50)

Those last 3 songs are from the latest Tool album "Fear Inoculum", which is definitely worth a listen.

Caution: the links above will jump you straight to Toolgasm! For the best experience, listen to the songs from start to finish off course ?

Following the WRC on the Web without distractions - Updated

10 November 2019

Since a couple of years, I'm closely following Thierry Neuville in the World Rally Championship. Live timings for every rally are available on the official wrc.com website. Unfortunately, this website is cluttered with ads and other irrelevant content (see screenshot below). This makes the experience of following a rally far from ideal.

Live timings on wrc.com

The cool thing about the Web however, is that the user has the power to decide how a webpage is rendered in the browser. This is made possible by the fact that website front-end code is build according to open standards: the HTML, CSS and Javascript which make up every website can be changed before it is rendered in the browser window. In the context of our wrc.com case, CSS is the most interesting of the 3 technologies, since it can be used to change what is shown on the webpage, just what we need to get rid of those annoying ads. 

To change the CSS, we need a browser plugin called Stylebot. This tool allows us to add extra CSS code to any website and change its look 'n' feel (see screenshot below).

I created a simple set of CSS code which makes the available live timings much more digestible.

header, footer, div a img, p.ad, ul.livecenter-subnav, .logo_wrcplus, .box.cad, .box.w1.f, .driverbar, .epgBox.box.w1.f h3 span, .liveheader, .mCSB_scrollTools, .bigsize, .billboard, .footer-sponsors, .content > div:first-child {
    display: none;
}

.logo_wrc img {
    display: block;
}

nav {
    margin-top: 0;
}

nav .wrapper ul {
    width: 87%;
}

main {
    padding-top: 0;
}

#m_more_2 {
    right: auto;
}

#m_live-timing_2 {
    color: #8dc72d;
}

For the best result, these style rules should be applied to all live timing pages. This can be done by using the following URL pattern:

www.wrc.com/en/wrc/livetiming*

 

Stylebot settings

The screenshot below shows the result after applying the necessary CSS overrides: all unnecessary elements are hidden on the page. This includes sponsors, ads, promoted content, etc. All that is left is the actual live results.

A much better experience!

Live timings on wrc.com - cleaned up
Caution: if the WRC decides to change the HTML output if its website, the CSS overrides above might stop working and need to be updated.

Update

Off course, the WRC has updated its website so all of the above does not apply anymore ? Fortunately, the update is for the better: there is much less clutter now when consulting live results (see screenshot below)! The new design for the website in general is a big step up. ?

The new WRC.com website