📜 ⬆️ ⬇️

How I added a new device to SmartThings Hub, part 1

In this article I want to tell you about my experience in developing the so-called Device Handler for the smart home SmartThings. The task was to add a universal device based on the Z-Wave protocol - Z-Uno , as well as the processing of child devices connected to it.



Introduction to development took me quite a lot of time, but after enlightening a careful study of most of the documentation, further development did not require much effort. In consequence of this, it was decided to write this article in order to facilitate the work of the Russian-speaking user.

The entire development process takes place in the Groovy SmartThings IDE web application. Testing is more convenient from a mobile device, but it is possible to create device simulators in the same development environment. In the case of testing the graphical shell, it is already necessary to use the SmartThings Classic mobile application ( Android , iOS ).
')
A connected device is a board that allows you to add control to almost any device in Z-Wave. And the connected devices can be a different number (up to 32 pieces). Accordingly, at the software level, all types of connected devices must also be processed and transferred to the application.

The list of processed types:



Document structure


There are two logical blocks:


I will describe in more detail the purpose and content of each block during the cycle of articles.

Metadata


As you can see from the name of the method - it contains meta information.

Consider in order what is included in this block:

Definition ()


In this method, arguments specify three things, respectively: the name of the processor, the namespace, and the name of the author.


  definition(name: "Your device", namespace: "yournamespace", author: "your name") {} 

The following variables can be declared in the method body: attribute, capability, command, fingerprint . Next, we take a closer look at what it is and when it is applied.

Connect and fingerprinting


We connect our device. In our case, SmartThings V2 Hub and Z-Uno will be used.

At the time of adding a new Z-Wave or ZigBee device, the hub will try to recognize which type of device they are trying to connect to it and will start looking for the most relevant handler. He will choose it by “Fingerprints”. If the hub does not find matches in the custom handlers, it will try to use one of the closest standard templates.

“Fingerprints” are set in the handler itself to indicate which types of devices it supports. The official documentation states that they will be different for Z-Wave devices and ZigBee devices; we will consider implementation for Z-Wave.

Z-Wave protocol devices store information about their manufacturer, device type, its capabilities, etc. During the so-called “interview” with the device, ST collects this information in a Z-Wave raw description. An example of such a line:

 zw:Ss type:2101 mfr:0086 prod:0102 model:0064 ver:1.04 zwv:4.05 lib:03 cc:5E,86,72,98,84 ccOut:5A sec:59,85,73,71,80,30,31,70,7A role:06 ff:8C07 ui:8C07 

The value of each key is used to fill in the “Fingerprint”. A detailed description of each item can be found here . We will look at those that will be used in our handler.

In order to find this line with information, you need to go to the 'My Devices' tab and click on the device of interest to us (before this, the device must be added to the network).



mfr is a 16-bit value containing the manufacturer ID (Manufacturer ID). A list of manufacturers and their IDs can be found here .

prod - 16-bit value containing Product Type ID - unique ID of the device type.

model - a 16-bit value containing the Product ID.

inClusters is an 8-bit value that establishes the need for a particular Command Class. For example, if we need to specify that our handler will work with MultiChannel CC, we need to write its code 0x60. A list of available for SmartThings CC can be found here .

These four keys are enough for the hub to understand exactly which device this handler belongs to. An example of how they are used by me:

 fingerprint mfr: "0115", prod: "0110", model: "0001", inClusters: "0x60" fingerprint mfr: "0115", prod: "0111", inClusters: "0x60" 

A device may have more parameters, in which case it may successfully connect with this handler, however, if at least one of them does not match the declared fingerprint, the device will ignore this handler.

Smartthings recommends adding manufacturer information (mfr) and model (prod, model) to fingerprint to rule out cases where the choice of handler is not obvious. For example, when the fingerprints of one of the templates or examples used by default will match yours.

Location in code
 metadata { definition(...) { ... fingerprint mfr: "0115", prod: "0110", model: "0001", inClusters: "0x60" fingerprint mfr: "0115", prod: "0111", inClusters: "0x60" } ... } 


A full cycle of articles is planned, up to release. I hope this information will help you in the development.

Source: https://habr.com/ru/post/427923/


All Articles