How to unify the Thread networks from SmartThings and Home Assistant?

Unfortunately, even as a member of the OpenThread consortium, Samsung has been quite restrictive in how it allows the use of its Thread network. As of now, there is no graphical interface or simple official method to take advantage of the Thread network from SmartThings hubs on other platforms. Users are forced to perform the initial pairing exclusively through the SmartThings app, limiting interoperability.

However, with some persistence, it’s possible to work around this limitation. By digging into specific SmartThings pages, it’s possible to retrieve certain credentials, such as the network password and PAN ID of the hub. With these details, a Python script can be used to import the credentials into Home Assistant, enabling the use of Samsung’s Thread network outside the SmartThings ecosystem.

If you use the Home Assistant app on iOS, there’s an even more integrated alternative: you can automatically export the Thread network credentials from SmartThings to the iCloud Keychain. This makes it possible to add devices to the SmartThings Thread network using Apple Home’s pairing process, significantly expanding cross-platform integration possibilities.Vamos ao passo a passo:

GET SMARTTHINGS CREDENTIALS

  1. Open Smartthings setup page and select your hub.
  2. On settings page, scroll down the screen until you find the Thread network information for the hub, which should include the Network Key (similar to some Wi-Fi password), ChannelPAN ID, and Extended PAN ID (similar to your Wi-Fi network name).
Informações da rede Thread criada pelo hub SmartThings. (Imagem: PontoByte/Vitor Gomes).

How PAN ID code provided by Samsung is in decimal format, we need to convert it to hexadecimal. To do this, you can use online tools available directly through Google.

CONVERT CREDENTIALS TO TLV

On a computer with Python installed, create a file named tlv.py and paste the script below to generate the TLV code. You may need to install the python_otbr_api library using the commands pip install python_otbr_api or python3 -m pip install python_otbr_api.

Remember to replace the information such as the Thread channel, Channel, PAN ID, Extended PAN ID, and Network Key with the values you obtained from the Samsung SmartThings page.

import python_otbr_api
from python_otbr_api import PENDING_DATASET_DELAY_TIMER, tlv_parser
from python_otbr_api.pskc import compute_pskc
from python_otbr_api.tlv_parser import MeshcopTLVType, MeshcopTLVItem

CHANNEL = <Canal do Thread>
PANID = "<Seu PAN ID em Hexadecimal>"
EXTPANID = "<PAN ID estendido>"
NETWORK_KEY = "<Network Key do SmartThings>"
TIMESTAMP = b'\x00\x00\x00\x00\x00\x03\x00\x00'

channel = MeshcopTLVItem(tag=0, data=CHANNEL.to_bytes(length=3, byteorder='big'))
pan_id= MeshcopTLVItem(tag=1, data=bytes.fromhex(PANID))
ext_pan_id = MeshcopTLVItem(tag=2, data=bytes.fromhex(EXTPANID))
network_key = MeshcopTLVItem(tag=5, data=bytes.fromhex(NETWORK_KEY))
timestamp = MeshcopTLVItem(tag=14, data=TIMESTAMP)

tlv_new = {0: channel, 1: pan_id, 2:ext_pan_id, 4: network_key, 14: timestamp}
tlv  = tlv_parser.encode_tlv(tlv_new)
print(tlv)

Script from Home Assistant Forum.

Now, using your computer’s terminal, run the script with the commands python3 tlv.py or pip tlv.py to generate your TLV.

Exemplo do valor TLV obtido utilizando o script acima. (Imagem: PontoByte/Vitor Gomes).

ADD TLV TO HOME ASSISTANT

With the TLV code in hand, access your Home Assistant and go to Settings > Devices & Services.

  • If you already have a Thread network configured, you’ll find an integration called Thread.
  • Within the Thread integration, tap on Configure, then click the three dots in the upper right corner.
  • On the page, select the option Add TLV dataset and paste the TLV code generated by the Python script.
Opção para adicionar o código TLV obtido na etapa anterior, por meio do script python. (Imagem: PontoByte/Vitor Gomes).

UNIFY THREAD NETWORKS!

If the TLV code is accepted, you will see a small key next to your SmartThings network and the Make Preferred Network option available. Tap on it to make the SmartThings network the preferred one for Home Assistant.

Rede Samsung SmartThings JÁ definida como a preferida, enquanto a rede ha-thread, oriunda do Home Assistant, se tornou uma secundária. (Imagem: PontoByte/Vitor Gomes).

Finally, tap on the three dots corresponding to your Thread dongle in Home Assistant and select Add to Preferred Network.

Opção de adicionar dongle Thread do Home Assistant à rede SmartThings. (Imagem: PontoByte/Vitor Gomes).

Once this is done, your Home Assistant Thread dongle will join the SmartThings network, helping to expand coverage and potentially acting as a second Thread Border Router if the SmartThings Thread hub stops working.

Dongle Thread do Home Assistant (um Sonoff dongle-e) unificado com a rede Thread do SmartThings, auxiliando a expandir o sinal e atuar como failover. (Imagem: PontoByte/Vitor Gomes).

WHAT ABOUT APPLE HOME

Unfortunately, it is not yet possible to force HomePods and Apple TVs to connect to the Samsung Thread network or an existing Thread network from Home Assistant. The default behavior is to always create a new network, and this is expected to change with the adoption of the new Thread 1.4 protocol, which will prioritize connecting to existing networks.

However, according to reports, once network credentials are saved in the Apple Keychain, HomePods may eventually connect to an existing network to expand the current network, rather than creating a new one. This change happens automatically and randomly, following unknown criteria.

With the SmartThings keys saved in Home Assistant, it’s extremely easy to export them to the Apple Keychain on iOS. Just follow these steps:

  1. Open the Home Assistant app and go to the Thread settings, where the available networks are listed.
  2. Select a device to be the credential router by tapping the three dots next to the SmartThings hub or the Thread dongle connected to Home Assistant.
  3. Tap the option Send Credentials to Phone, and you’re done!
Adicionando credenciais da rede Thread do SmartThings ao Apple Keychain. (Imagem: PontoByte/Vitor Gomes).

If everything went well, the SmartThings Thread network credentials are now saved on iOS and can be used even for adding Thread devices using the ST- network instead of the default Apple Home network.

You can check the saved Thread networks in the Apple Keychain using the Home Assistant app. To do this, go to Settingsand look for the Mobile App option. On this screen, scroll down to Debugging, and finally, tap on Thread.

Todas as credenciais da rede Thread salvas no Apple Keychain. (Imagem: PontoByte/Vitor Gomes).
Share