How to configure preferred Thread network

Hi!

Could You tell me how exactly, step by step, do this? I mean merge HA thread network with Google Nest network.
My HA thread network is based on sonoff zigbee 3.0 dongle flashed with custom firmware from this site: https://smarthomescene.com/guides/how-to-enable-thread-and-matter-support-on-sonoff-zbdongle-e/
This thread network works because i was able to add and use EVE power socket with it.
I have Google Nest 2 and would like to use it to improve network coverage.
My preferred thread network is default home assistant created automatically after installing silicon labs multiprotocol addon. I managed to change channel of the thread network and ZHA to 18 usde by Nest network, but have no option/don’t know how to change preferred network and then “merge” with Nest.

I’m quite new to HA so please be understanding :slight_smile:

Greetings!

I don’t have an Android device to test this but according to Thread - Home Assistant all you need to do is add a Matter device via the Android app.

Home Assistant will sync the Thread credentials with Google when starting to commission a Matter device via the Home Assistant Companion app. For other vendors, if the vendor allows you to see the operational dataset in TLV format, you can import it to Home Assistant from the Thread panel.

I tried just using HomeAssistant via an Android emulator on my PC, but it seems that you actaully need to add a device.

On the Apple side however, I was able to get the credentials using this script and the Nanoleaf app.

Only wier dthing now is that my Apple network name WAS MyHomeXX, but now after adding the SkyConnect to it, Eve is showing the network name as home-assistant (which is what was the name of the network that the SkyConnect stick used to have.; while in the HomeAssistant configuration… it has no name… I even removed the home-assistant network afterwards since it didn’t seem to be being used.

Not a huge issue, but anyone know how I can change the name for the network? The OTBR UI seems to be removed in the multiprotocol add-on.

In addition to this… it seems like if I reboot one of my Apple devices, they are no longer in the Thread network… and never come back! :open_mouth:

Update:
Well, I managed to get the SkyConnect back onto its own network, but my Apple Thread network is completely busted! The network will come back if I restart an AppleTV or HomePod… temporarily. After about 3 or 4 minutes, the network disappears again…

R.I.P. Thread network….

1 Like

@Veldkornet : Agree with your last sentence. If I understand correctly, you want to integrate EVE devices into HA. Not sure if you know: EVE has announced that EVE Thermostats can be migrated to Matter starting November 15. I have migrated my EVE Window and EVE Energy to Matter, they work fine with HA. So I‘ll be patient for a few more weeks :slight_smile:

Yes, I eventually reset my SkyConnect and just completely disconnected it.
After about a day and a bit, my Apple devices slowly came back to life.
I have two Eve Energies which I connected via Matter and that works fine.

I just thought I’d try combine my Apple / Google and HomeAssistant thread networks for better coverage.
Seems it’s a bit sensitive though :joy:

I’ll just stick with Apple being my main thread network and get everything into HA via Matter as support comes along.

:+1:
Now all we need is the Matter Integration to leave it‘s Beta status.

FYI, I couldn’t leave it alone… :smiley:

I noticed that the script I was using was missing the network name and PKSC. So I’ve added those to the script, and now things are looking better. Will leave things a couple of days to settle and see if it stays fine now… I also set the network name to a name of my choosing instead of the MyHomeXX, it seems to be okay with it so far… I checked in the Eve and Nanoleaf apps, and all the devices seem to have adopted the new name.

Here the updated Python script if anyone wants it (FYI, I got all the needed information from the Nanoleaf app, if you add a Nanoleaf device it exposes all that information).

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

# Apple
CHANNEL = <Channel Number>
PANID = "<YourPanID>"
EXTPANID = "<YourExtPanID>"
NETWORK_KEY = "<Your Network Key>"
NETWORK_NAME = "<Your Network Name>"
PSKC = "<YourPSKC>"
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_name = MeshcopTLVItem(tag=3, data=str.encode(NETWORK_NAME))
pre_shared_key = MeshcopTLVItem(tag=4, data=bytes.fromhex(PSKC))
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, 3: network_name, 4: pre_shared_key, 5: network_key, 14: timestamp}
tlv  = tlv_parser.encode_tlv(tlv_new)
print(tlv)
5 Likes

Hey I can’t help but notice that this is (similar) to the way I made my sonoff zigbee dongle running multiprotocol to merge the thread network with it. I now have my apple border routers and my nanoleaf shapes and EVERY thread homekit device merged with skyconnect, have for a while now. All I did myself was open the nanoleaf app (it helps I have a shapes panel as border router as well) and go to thread network, copy the network key and then I opened the otbr ui went to join and selected one of the corresponding thread devices and used the network key.

Although my thread network is joined together successfully and my god its been working SO WELL for a couple months now with not one single issue, its shocking as my past attempts ended me up with an apple tv that WAS on the same network as HA but for some reason my two homepod minis would diverge and form their own “myhomeblahblah” homekit thread network separate from the appletv/ha and it was constant drop outs wiht a small set of devices.

The HA team did a great job getting this better integrated. But I have a question, due to runing home asisstant OS for the ease, getting direct access to run these commands is far more time consuming and I don’t exactly like opening up ssh access with the advanced terminal add on simply because of the risk. I have other options if I want to fire up another border router iot gateway but thats mostly for dev stuff and I dont want to muck my stable network up. I just want to change the name of the border router HA uses instead of silicon labs multiprotocol. Could this script be executed from just a docker container with otbr or how did you do this exactly if you dont mind me asking? I know I can get into it with the advanced terminal add on but I really prefer not to open up a security hole as I’m not willing to risk that and its not that I don’t know how to secure it, I definitely DO I justt dont have the time really (and definitely not for another oopsy to be made lol) so many other things I have to do, but I also thought well…I could just try renaming the openthread border router integration (so just devices>openthread border router> services> rename, but would that even work for it or could that make it reset or drop off? After my homekit border routers diverging the last time and all the chaos that ensued and unhappy spouse and home members I try to keep my stable stuff in homekit STABLE because my husband was so mad at me when that happened haha and he really didnt like it when the kitchen lights went unavailable and to be fair i didnt either. Sorry for the long response, I have no friends that can even come close to being interested or could speak the same language and so…do you think doing that would be safe? :slight_smile: I definitely am overthinking it I think, I believe it should work, but why jump ahead and have to deal with that fallout if possible lol anyway, thanks any help is appreciated.

Thanks Veldkornet, but that is way out of my league. If it can‘t be done using the UI then I can not do it, I just do not have that experience. Anyhow, I hope it continues to work for you! :+1:

omg… just bought a few nest hubs , just to figure out thread is bullsh*t the way it is right now :confused:

1 Like

Hi and thank you for the many informations. I also have tried many times to create one thread network and now I think I am really near to a solution. But I have a problem to execute the script. When I start the script in the terminal in HA it always brings this message:

Traceback (most recent call last):
File "/root/threadscript.py", line 1, in <module> import python_otbr_api
ModuleNotFoundError: No module named 'python_otbr_api'

Is there something missing in my system? I have the SkyConnect stick, Thread and OTBR installed.
Can anyone help me with this problem?

1 Like

From wherever you are running the script, you need to have the module installed.

Ie, I run it from the visual studio code add-on, so I just install it there in the console first:

pip install python-otbr-api

1 Like

Thank you! It works now. The thread network from my HomePodMini is now the preferred one! :slight_smile:
I have successfully added a Nanoleaf lightbulb and it is in the HA and the thread network.
I also try to connect a Eve Thermo, but I do not get it. Neither about Thread nor HomeKit integration. In the Eve and HomeApp it works.
Do you have any idea why it will not connect?

Hi, note that EVE has announced that EVE Thermostats can be upgraded to Matter starting Nov 15, which means you can use them in the EVE App, Apple HomeKit and Home Assistant in parallel.
Of course you need to have the Matter Integration installed.
I have upgraded my EVE Door/Window and EVE Energy to Matter and they work fine

Hi there, @Veldkornet thank you very much for your script, the TLV creation worked flawlessly.

But now, I have only the option to switch between my Apple network and my SkyConnect as a preffered Netwok, I cannot merge them. Any thougts/tips on this?

What worked best for me was to just make the Apple MyHomXX network the preferred network and move the stick into that network.

1 Like

Thanks a lot for the script! I bought a Nano leaf product so I could get all the needed credentials, and the script runs fine (I’m using the Advanced Terminal & SSH add-on).

I assume I’m supposed to copy the TLV string into Thread > Add Dataset from TLV?

When doing so I get this error:

expected 77 bytes for STEERING_DATA, got 53

Any idea what I’m doing wrong? Do I need to enable Thread on my SkyConnect for this to work? I am trying to only rely in the Apple network and keep the SkyConnect exclusively for my Zigbee network.

Note: I’m an absolute HA beginner (started yesterday), so may be missing something super obvious!

EDIT: Never mind! I ran it in VS Code instead and I got it working now, though I think I probably just had a typo when copying the output the first time. I did it by hand since I couldn’t figure out how to copy from the terminal… :man_facepalming:

On the Android companion app, go to Devices → +Add Device → Add Matter Device.

I struggled to find this too but eventually found the flow in this video: https://www.youtube.com/watch?v=Fk0n0r0eKcE

hm, I’m not asking how to add matter device, I want set my Google Nest Hub as the border router, see:

Nest Hub is found, but I can’t get it used as preferred router

If I understand correctly, you want to make your NEST_PAN-D73A the “Preferred (Thread) Network”…

As I understand it, HA needs some way to get to the Thread Network’s “Dataset” in order to make it preferred. As far as I know, Google doesn’t provide any open APIs to give HA access to the Nest Hub’s Dataset. However according to a post #12 and #13 above, if you use the HA Android Companion App to add a device (adding as a Matter device) to the Google Nest Thread network, then the Companion App can synch the Dataset (also known as “credentials”) to HA, and after then you should be able to successfully make the Nest Thread network preferred.

oh… ok, now I get it. I was thinking the other way. thanks for the clarification!