Integrating my Smart Home into the Tangle
Home Assistant is an awesome open-source home automation platform, with a strong focus on privacy, offering integrations for more than 1000 smart home components. The project puts local control first, and empowers you to run it on your local server.
IOTA is an open-source distributed ledger, built to power the future of the Internet of Things with feeless microtransactions and data integrity for machines. You can also run it on your own server — and 1000s of people, possibly far more, — including this author — , do so.
Integrating those two technologies would immediately enable many more possible applications. Without thinking for too long, the following examples came to my mind:
Reacting to events in the Tangle
Your smart home solution is supposed to run on a small device, like a Raspberry Pi, in your home. But there will come a time you want to be able to trigger actions from outside that home.
An example for this could be some mailman, who wants to unlock your front door to deliver mail. Or an AirBnB host, who temporarely grants a guest access to his home. Or just a friend, who you otherwise would give a physical key.
For this, you could expose your Home Assistant server to the internet, but this comes with its own risks. Combining Home Assistant with IOTA elegantly solves this, eliminating all security concerns.
Your mailman, guest, or friend would have to publish this “open door” action on the Tangle, digitally signed so you could afterwards undeniably prove the open door was a direct result of this message. The message also has to be encrypted, so no one else can find out when guests come to your apartment — or when it is unoccupied.
Audit trails in the Tangle
As initially stated, IOTA is great for ensuring data integrity. This is where the following use case comes from: Audit trails.
Certain changes of the state can be published to the Tangle, to prove afterwards that the data is pure and unaltered.
These state changes could be simple, like movement detectors, that triggered an alert; or more complex scenarios like temperature sensors which regularely publish their values to ensure the cooling chain of a food supplier is unbroken.
The raw data can either by encrypted, so only the owner of the corresponding private key can understand it (and, if needed, reveal it to third parties like lawyers or courts), or it can deliberately be open and for the whole world to see.
Proof of Concept and Technical Details
After a few days of coding I had a simple prototype that I can now share with you, it’s available under https://demo.tingeltangle.de (check out the sources below!).
ZMQ <-> Websocket bridge
To react on messages in the Tangle, first of all there has to be a possibility to listen for new messages. This is already where it started getting complicated, current approaches tend to poll the IOTA nodes at regular intervals. I wanted near-realtime notifications with no strain on the nodes, so I came up with another solution.
The IOTA Reference Implementation already provides such a transaction stream, namely via the ZeroMQ-protocol. This is usually not exposed by public nodes, so I built a wrapper around that. iota-websocket-proxy is (as the name suggests) a websocket proxy, which allows subscriptions on a per-address basis, and can be exposed to the internet. You can check out my demo server as an example.
MAM listener
This component integrates messages received through IOTAs Masked Authenticated Messaging (MAM) module into the Home Assistant platform.
The video explains the installation and setup steps in more depth, and also gives another demonstration of it.
The automations component of Home Assistant offers a wide range of possible configurations, so the MAM listener can be used in various different scenarios. The basic idea is, that somebody will trigger an action by attaching a bundle to the Tangle. When Home Assistant notices such an action, the event iota_mam.action_triggered will get triggered. This event has a unique identifier (like open_door). It can also contain some additional data (like which door exactly should be opened). Further details and configuration examples can be found in the repository on GitHub.
MAM publisher
This component is for the “Audit Trail” and “Data Marketplace” usecase. It is based on the notify component of Home Assistant, and can therefore be used to post any message into the MAM stream on the Tangle.
You can use it for data that can be publicly readable, private or restricted. Private messages can be decrypted by anyone who knows the message root (the address is just the hash of the root), restricted messages also need an additional side key (encryption key) as well.
Source code
Check out the source code at
* https://github.com/lukas-hetzenecker/iota-websocket-proxy
* https://github.com/lukas-hetzenecker/iota-dooropener
* https://github.com/lukas-hetzenecker/home-assistant-iota
About the author
I am a masters student of computer science at the Technical University of Vienna. I’ve been fascinated by Blockchain, smart contracts, and alternative ledger technologies since some time now.
P.S.: By the time this post gets published, the MAM configuration will already be changed, so don’t try to open my door ;-)