Integrating physical devices with IOTA — Philips Hue edition

The 14th part in a series of beginner tutorials on integrating physical devices with the IOTA protocol

Hugo Gregersen
Jan 5 · 7 min read

Introduction

This is the 14th part in a series of beginner tutorials where we explore integrating physical devices with the IOTA protocol. In this tutorial we will be revisiting the use-case from the first tutorial in this series, where we built a simple power circuit that would allow us to purchase services from a physical device using IOTA tokens. In this tutorial, we will take on the same idea and apply it on top of an existing ecosystem of hardware and software, namely the Philips Hue.


The use case

So, why would our hotel owner choose to implement his IOTA payment system on top of an existing ecosystem like the Philips Hue vs building it from scratch as we did in the first tutorial? Well, the simple answer is “plug and play”. Instead of having to deal with a lot of wiring and microcontrollers, he can now simply go to his nearest electronics store, get all the smart devices (lamps, bulbs, plugs, etc.) he needs and have his new payment system up and running in a couple of hours.


What is Philips Hue?

Philips Hue is an ecosystem of color-changing lamps, bulbs, LED stripes, switches, dimmers, motion sensors, smart power plugs etc. that can be controlled wirelessly from an app or the Phillips Hue API. In the center of the ecosystem is the Phillips Hue Bridge. The Hue Bridge functions as a common controller for the entire system. The Hue Bridge can manage up to 50 Hue devices simultaneously in a mesh type wireless network.


Installing Hue

First of all, before we can move on you have to install your Philips Hue system according to the documentation that comes with the system. It’s pretty straight forward and should not take more than a few minutes.


Assigning IOTA addresses to Hue devices

The next thing we need to do is to assign a unique IOTA payment address to each individual Hue device. The simplest way of creating new IOTA addresses (including QR codes) is using the Trinity wallet. Make a note of each address as we will need them in our Python script(s) later on.


Required Software and libraries

A cool feature that comes with the Philips Hue system is that it has its own application programming interface (API), that allows developers like our selves to interface and build new apps on top of the system. And even better, a team of developers calling them self’s studio imaginare have already made a simple Python wrapper around the API called phue that we will be using in our project.


The Code

Now that we have made all the preparations, let’s look at the Python code for this project.


Running the project

To run the project, you first need to save the script in the previous section as a text file on your computer.

  1. Replace the IOTA payment address with the address you created for this particular device id earlier in this tutorial.
  2. Update the device_id variable according to the particular hue device you are targeting (unless the id=1, then no need to change)

Pay the light

To turn on a particular Hue device, simply take your mobile phone with the Trinity wallet, scan the associated QR code for the device and transfer some IOTA’s to its IOTA address. As soon as the transaction is confirmed by the IOTA tangle, the device should turn ON and stay on until the balance is empty, depending on the amount of IOTA’s you transferred. In my example I have set the IOTA/device time ratio to be 1 IOTA for 1 second of service.


Managing multiple Hue devices

If you take a look at the Python script for this tutorial you will notice that the script itself is not prepared for managing multiple Hue devices simultaneously. I guess the appropriate way of dealing with this would be to re-write the code to include some type of device list or array that would allow us to manage multiple devices in parallel. Another alternative is of course (as i did) to simply have multiple instances of Python running at the same time. Each instance running its own script with its own device id/IOTA address.


Contributions

If you would like to make any contributions to this tutorial you will find a Github repository here


Donations

If you like this tutorial and want me to continue making others, feel free to make a small donation to the IOTA address below.

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Hugo Gregersen

Written by

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

More From Medium

More from Coinmonks

Jia Yung Lee
Feb 6 · 5 min read

1.2K

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade