Skip to content

Instantly share code, notes, and snippets.

@EverythingSmartHome
Last active February 18, 2024 11:51
Show Gist options
  • Save EverythingSmartHome/990f2436608fd347cd20cf0009b5cef4 to your computer and use it in GitHub Desktop.
Save EverythingSmartHome/990f2436608fd347cd20cf0009b5cef4 to your computer and use it in GitHub Desktop.
Zigbee Network Migration
#Check new adapter is found
lsusb
#Check which port new adapter is on
ls -lah /dev/tty*
# Enter Home Assistant container
docker exec -it homeassistant /bin/bash
#Install open-coordinator-backup
pip install zigpy-znp 'git+https://github.com/puddly/bellows@puddly/open-coordinator-backup'
#Start backup process (replace with your device address)
bellows -d socket://YOUR_IP_OR_ADDRESS backup > /config/zigbee-backup.json
#Restore backup to new adatper (replace with your adapter)
python -m zigpy_znp.tools.network_restore /dev/ttyUSB0 -i /config/zigbee-backup.json
#Change to storage directory
cd /config/.storage
#Backup config file
cp core.config_entries core.config_entries.backup
#Edit config file
vi core.config_entries
#Find ZHA using the forward slash key and search for zha. Edit path and radio type as applicable. Press escape and type :x and hit enter to save.
@hbkhalil
Copy link

hbkhalil commented Jan 9, 2022

Hi there,
I am getting this error
`Traceback (most recent call last):
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/bin/bellows", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/bellows/cli/util.py", line 39, in inner
loop.run_until_complete(f(*args, **kwargs))
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/local/lib/python3.9/site-packages/bellows/cli/backup.py", line 83, in backup
ezsp = await util.setup(ctx.obj["device"], ctx.obj["baudrate"], _print_cb)
File "/usr/local/lib/python3.9/site-packages/bellows/cli/util.py", line 118, in setup
await s.reset()
File "/usr/local/lib/python3.9/site-packages/bellows/ezsp/init.py", line 94, in reset
await self._gw.reset()
File "/usr/local/lib/python3.9/site-packages/bellows/uart.py", line 223, in reset
return await asyncio.wait_for(self._reset_future, timeout=RESET_TIMEOUT)
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
^CException ignored in: <module 'threading' from '/usr/local/lib/python3.9/threading.py'>
Traceback (most recent call last):
File "/usr/local/lib/python3.9/threading.py", line 1435, in _shutdown
atexit_call()
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 31, in _python_exit
t.join()
File "/usr/local/lib/python3.9/threading.py", line 1053, in join
self._wait_for_tstate_lock()
File "/usr/local/lib/python3.9/threading.py", line 1069, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
`
I am unsure of what is happenning.
Thank you very much for your help.

@puddly
Copy link

puddly commented Jan 9, 2022

What adapters are you trying to migrate between and what exact commands are you running?

@hbkhalil
Copy link

hbkhalil commented Jan 9, 2022 via email

@puddly
Copy link

puddly commented Jan 9, 2022

Right, but what exact commands are you running?

Your traceback includes references to bellows, which handles communication with EZSP/Silicon Labs radios. Neither of the two commands to migrate between your two sticks should be using the ezsp radio type. They should all be znp.

@hbkhalil
Copy link

hbkhalil commented Jan 9, 2022 via email

@shahms
Copy link

shahms commented Jan 9, 2022

I was able to successfully migrate from a HUSBZB-1 stick to CC2652P-based adapter using a hybrid of the steps described here and in zigpy/zigpy-cli#2

I did so using a second computer to perform the backup/restore to avoid too much invasive surgery on my HA install. Specifically, I:

  1. Disabled the ZHA integration
  2. Removed the HUSBZB-1 stick and put it into a second computer.
  3. Performed the backup from zigpy/zigpy-cli#2
  4. Put the new controller stick in the computer
  5. Performed the restore steps from zigpy/zigpy-cli#2
  6. Attached the new stick to my HA Raspberry Pi
  7. Edited core.config_entries to change the device path and (importantly!) the baud rate. The HUSBZB-1 used 57600 while the new stick requires 115200
  8. Restart HA
  9. Re-enable the ZHA integration
  10. Edit core.device_registry and core.entity_registry to re-enable the disabled devices and entities (as others have noted)
  11. Restart HA

There were a number of false-starts after 7. I originally didn't edit the baud rate which lead to timeouts trying to re-enable the integration. After fixing that and restarting again, all of the devices/entities were disabled (as others have noted). After manually re-enabling them and restarting again everything seems to be working! I'm not sure if one of those missteps are what lead to the devices/entities being disabled or what.

As to my rationale: while I have fairly few ZigBee devices, one of them is a notoriously finicky ceiling fan which is having occasional drop outs and which I'm hoping the new adapter will help with. It's also incredibly obnoxious to re-pair, so being able to avoid that is worth almost any amount of other work.

@sprynm
Copy link

sprynm commented Jan 9, 2022

ugg, stuck at "-bash: docker: command not found"

EverythingSmartHome commented on Dec 9, 2021
@tof92130 Firstly the command you typed isn't correct (typo), but secondly you must type "login" first on the command line if you are doing it from the terminal. You can also disable protected mode on the SSH add-on instead and do it that way.

Unsure what context "login" has here but all my credentials fail (root, admin,...).

SSH addon doesn't appear to have an option to "disable protection mode"

tof92130 commented on Dec 10, 2021
Ok, I was not using the good add-on, it needs to use ssh & Web Terminal to access docker command

I have the "Terminal & SSH" addon (only one I could find in a search). From here: https://github.com/home-assistant/addons/tree/master/ssh

Is there a different one on a different repo I should use?

Installation Type | Home Assistant OS
Development | false
Supervisor | true
Supervisor Version | supervisor-2021.12.2
Docker | true
Docker Version | 20.10.9
User | root
Virtual Environment | false
Python Version | 3.9.7
Operating System Family | Linux
Operating System Version | 5.10.63-v8

@puddly
Copy link

puddly commented Jan 9, 2022

SSH addon doesn't appear to have an option to "disable protection mode"

There are two SSH addons and you're probably using the not-so-useful one. Take a look at https://github.com/zigpy/zigpy-znp/blob/dev/TOOLS.md#in-home-assistant-os.

@satyajitmishra93
Copy link

I am specifically stuck at the part where it creates the backup.
I entered the following command;
bellows -d /dev/ttyUSB0 backup > /config/zigbee-backup.json
Then I get an error called; asyncio.exceptions.CancelledError
Can someone please tell me what I am doing wrong?

@Hoekeren
Copy link

Hoekeren commented Feb 7, 2022

Same problem here https://gist.github.com/EverythingSmartHome/990f2436608fd347cd20cf0009b5cef4?permalink_comment_id=4023749#gistcomment-4023749

bellows -d socket:/dev/ttyACM0 backup > /config/zigbee-backup.json

this is the stick i try to backup "/dev/serial/by-id/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B00193B17CD-if00"

@anoril1979
Copy link

anoril1979 commented Feb 21, 2022

Hi!
Many thanks for the video and explanation; I'm trying to migrate from a Sonoff basic to the Sonoff 3.0 Plus, as depicted in the video, and was afraid to lost all my data in the change.

Actually, I got an issue with the export. Note that I'm not using Docker but HA Core on a Synology NAS. ZigPy and Bellows were kind-of hard to install correctly but seem to work. (pip install ... on project https://github.com/zigpy/bellows 0.29.0)
Now, I backup my Sonoff ZBBridge using the bellows command and I got a json file as expected. But it looks inconsistent and fails the check against json validation: jsonschema.exceptions.ValidationError: 'metadata' is a required property
How this can happen? Does Bellows can export in a wrong format (I read the json file and see that there is a lot of missing "required" keys, like "devices", "coordinator_ieee", "channel"...

I then used python3 -m zigpy_znp.tools.network_backup --output /volume1/BackUp/zigbee-backup2.json socket://192.168.1.41:8888 to give it a try but I ended with a TimeoutError...

@balcanuc
Copy link

The solution described here is not working anymore. Please consider following instructions from zigpy/zigpy-cli#2 instead

There was an intentional change that break functionality.

@anoril1979
Copy link

anoril1979 commented Feb 21, 2022

Thanks for the update.
I tried following steps depicted by @shahms but I did not manage to run zigpy.

For instance, if I go pip install zigpy-cli, it issues a ERROR: No matching distribution found for zigpy-cli error.
I downloaded zigpy-cli archive, dezipped, changed the files with the ones from the PR, then requested an install. Python told me I must have PySQLite3 and provided the command (pip install pysqlite3-binary)...
Which fails with ERROR: No matching distribution found for pysqlite3-binary... I tried with pip install pysqlite3 which worked but then zigpy -vv radio ezsp socket://192.168.1.41:8888 backup /volume1/BackUp/zigbee-backup2.json still issues an error about sqlite3 version...

I'm cursed!

@anoril1979
Copy link

I installed Python on Windows platform with all the components. SQLite3 is OK, ZigPy is ok, etc. but running zigpy command returns a missing zigpy-cli module, while this exact one is listed as installed by pip list command.
I'll wait for this to be ironed before to migrate my zigtbee gateway :P

@10165joe
Copy link

Hi, I get the following error when trying to install bellows branch
This branch is obsolete! Please test zigpy/zigpy-cli#2 instead
however if i try this, i get...
fatal: repository 'zigpy/zigpy-cli#2' not found

any help would be greatly appreciated.. thanks :-)

@Aham330
Copy link

Aham330 commented Apr 13, 2022

Hi @10165joe i believe I used this video to
update my Sonoff 3.0 dongle
Plus.

https://youtu.be/iCE5Z43EKpk

Then used the zha_toolkit through HACS to update my Zigbee network. Rewrote and renamed some devices (needed to be done anyway) also
Looked at the automations and changed some of those. All in all about 2 hours. Having about 30 devices.

Overall very happy because the Sonoff seems much more stable than the cc2531 that I had.

@10165joe
Copy link

Hi @10165joe i believe I used this video to update my Sonoff 3.0 dongle Plus.

https://youtu.be/iCE5Z43EKpk

Then used the zha_toolkit through HACS to update my Zigbee network. Rewrote and renamed some devices (needed to be done anyway) also Looked at the automations and changed some of those. All in all about 2 hours. Having about 30 devices.

Overall very happy because the Sonoff seems much more stable than the cc2531 that I had.

Perfect! thanks

@plankto
Copy link

plankto commented Jun 26, 2022

I just went through this and got stuck with the obsolete branch, switching out the following commands worked for me.

#Install open-coordinator-backup
pip install 'zigpy>=0.47.0' 'zigpy-znp>=0.8.0' 'zigpy-deconz>=0.17.0' git+https://github.com/puddly/zigpy-cli.git@puddly/zigpy-radio-api git+https://github.com/puddly/bellows.git@puddly/zigpy-radio-api

#Start backup process (replace with your device address)
zigpy -vv radio ezsp socket://YOUR_IP_OR_ADDRESS backup /config/zigbee-backup.json

#Restore backup to new adatper (replace with your adapter)
zigpy -vv radio znp /dev/ttyUSB0 restore /config/zigbee-backup.json

@ernst77
Copy link

ernst77 commented Jul 19, 2022

I just went through this and got stuck with the obsolete branch, switching out the following commands worked for me.

#Install open-coordinator-backup pip install 'zigpy>=0.47.0' 'zigpy-znp>=0.8.0' 'zigpy-deconz>=0.17.0' git+https://github.com/puddly/zigpy-cli.git@puddly/zigpy-radio-api git+https://github.com/puddly/bellows.git@puddly/zigpy-radio-api

#Start backup process (replace with your device address) zigpy -vv radio ezsp socket://YOUR_IP_OR_ADDRESS backup /config/zigbee-backup.json

#Restore backup to new adatper (replace with your adapter) zigpy -vv radio znp /dev/ttyUSB0 restore /config/zigbee-backup.json

this does not work either...

@sorenjacobi
Copy link

sorenjacobi commented Oct 9, 2022

This worked for me:

pip install 'zigpy>=0.47.0' 'zigpy-znp>=0.8.0' 'zigpy-deconz>=0.17.0' git+https://github.com/puddly/zigpy-cli.git@puddly/zigpy-radio-api

python -m zigpy_znp.tools.network_backup /dev/ttyUSB0 -o /config/zigbee-backup.json

Read more here: https://github.com/zigpy/zigpy-znp/blob/dev/TOOLS.md#backup-and-restore

@puddly
Copy link

puddly commented Oct 9, 2022

Please use ZHA's migration interface, there's no need to use the command line tools. If you still want to do it over the command line, use zigpy-cli: https://github.com/zigpy/zigpy-cli#network-backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment