Intercept of Things - part 4: Device Twins

In this article, we'll tell you more about Device Twins. What are they? And why is it important to understand the capabilities of Device Twins. 

Something we have touched on several times but not really got into depth with is “Device Twins”. This might not be the most elaborate article in this series but it is very important to understand the capabilities of the Device Twins. Because Essentially, without them you’re just read data from a device while you could do so much more!

Microsoft describes the Device Twins as follows:

Device twins are JSON documents that store device state information including metadata, configurations, and conditions. Azure IoT-Hub maintains a device twin for each device that you connect to IoT-Hub.”

That sounds very basic and very advanced at the same time!

You could see device twins as a way to “operate” your device from Microsoft Azure IoT-Hub.

What can a device twin do?

Device Twins can be used to store data about the device in the cloud. We call this metadata. Let say you added the metadata to the device with the location of the device (apartment A, building 5), you want your device to report that back so you know which apartment in which building is responsible for the data generated.

But it’s not just that. You can also use Device Twins to report specific states, capabilities or conditions. For instance “Temperature sensor is turned on” or “Airconditioning is turned off”.

Now that maybe sounds nice.. But your next question will be: Can I change the value of those properties? Yes you can. We can actually control part of the state on the device.

Using IotHub and Device Twins we can send the device a message stating “please change the property”. Essentially we can send a message (simplified for readability):

“Airconditioning: On”

“Temperature: 15c”

The use case

Now that’s pretty powerful. That means that we can not only provision and manage devices from an infrastructure perspective. But we can also manage the properties on the devices and actually “control” them. Think of the use cases! We probably already have similar technologies but let’s think of building management for example. We are now gathering telemetry with IoT Device from the building and storing them in Azure.

We can use analytics, machine learning, data from external resources (think weather) and maybe build a model that outputs when and why we need to change the temperature of the heating in the building or when to turn on the air conditioner. We can now actually do that because we can use Device Twin to set those properties without having to build complicated interfaces to interact with our devices. We’re literally talking about “Smart Buildings” here.

But it’s not just using the device twin of a single device. We can query across devices or set a specific property for multiple devices. Maybe we want to turn the lights off an hour after sunrise. From Azure we can pull the data from an API that tells us the time for sunrise for a specific day in a specific region. We can then build logic in Azure to use the Device Twins technology to turn off the lights an hour after sunrise by just changing the property.


Device Twins may come across as a very small feature but it’s actually what’s powering the use case for many IoT scenarios. Where we traditionally monitored devices and gathered telemetry, we are now controlling devices and providing the logic (from the cloud) for industrial plants, buildings or even your smart home. Yes, the devices are connected to the cloud and you can send messages back and forth but, the Device Twins are glue that put everything together.  We could even argue that this could replace a big part of the traditional messaging of devices to the cloud. Why would we need to send hundreds of thousands of messages with “temperature X, Y Z” if we can just query the property and build some alerting when it drops down or rises above a specific value? The use case really depends on your requirements but it’s good to know what’s out there.

And with that, we’re at the end of our IoT Edge article.  In our next post we’ll go further down the rabbit hole and look at using Device Twins to manage devices, which is easier than it sounds but also an amazing technology!


This article is part of a series

Part 1: Intercept of Things - part 1: Introduction

Part 2: Intercept of Things - part 2: Planning your IoT Solution

Part 3: Intercept of Things - part 3: IoT Edge

Written by

Wesley Haakman

Wesley Haakman

Lead of DevOps at Intercept | Microsoft Azure MVP | CISSP | Spreker

Possibly interesting as well: