Device Twin is a digital representation of a device or sensor on the IoT hub. It is used when you want to configure your devices from a backend service and synchronize the state information between the device and the hub. For example, if you want to set an operational temperature for the air conditioner or color for the smart light, you can send the configuration to your device.
In simpler terms, device twin is a JSON document associated with every device. This document is stored in the IoT hub and contains information like the desired properties, reported properties and the tags.
- Desired property: This property is set through the IoTConnect platform and is used to send state information to the device.
- Reported property: This property is set by the device is used to receive state information from the device by the IoTConnect Platform.
- Tag: This is set by the IoTConnect platform in case the device is Gateway supported. However, this information is never sent to the device.
A twin definition is shared by all the devices of a template, this safeguards your IoT application against the variability that offers occurs in an IoT device ecosystem. However, the twin property must be executed on every device, so that you can start the interaction.
Use case
Let us take an example of a temperature maintenance system in a commercial building. There are multiple smart air-conditioners present in the complex and the operators want to configure the state information to 25 Celsius.
Start with creating an IoT template for smart air-conditioners. To know more about template creation, click here. Once you have created the template and added the attributes, setup the twin property. As you want to configure the temperature, set property name and key accordingly. Now set the data type to Number and default value to 25 Celsius. Save this twin property.
The next step is to add the devices and select the twin property specified in the template. By default, the desired value will be taken as 25 Celsius as specified in the template. In case, you want to change the desired value for this device, simply enter the new value and execute the twin property.
When you connect the actual device via SDK, the IoTConnect will receive the reported value for this device.
If you want to know more about adding twin property, read our user guide.