zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

[ANNOUNCEMENT] Zigbee-herdsman: the next zigbee-shepherd

Open Koenkk opened this issue 7 years ago โ€ข 49 comments

As some of you have already noticed, lately I've been putting lots of efforts in refactoring zigbee-shepherd. Zigbee-shepherd is the Javascript Zigbee library were zigbee2mqtt is based up-on.

My biggest reason to do this is that, in my opinion, zigbee-shepherd was not maintainable and extensible. This made it very hard to fix bugs and add new features, which made it hard to take zigbee2mqtt to the next level.

I ended up in completely rewriting zigbee-shepherd from scratch. Because of that I also gave it a different name, zigbee-herdsman. Just to give an idea of the effort that I've put into it, this job took me 100+ hours spread over 2 months.

Zigbee-herdsman will land into the zigbee2mqtt (dev branch) and zigbee-shepherd-converters after zigbee2mqtt 1.6. After this zigbee-shepherd-converters will be renamed to zigbee-herdsman-converters, as zigbee-shepherd-converters and zigbee-herdsman are not compatible.

What will I as a user notice from it?

  • Improved stability and predictability
  • Improved Xiaomi devices pairing (should be similar to the official Xiaomi gateway now, even for Mija devices, bye bye Cannot get node descriptor for... error ๐Ÿ˜บ)
  • Improved logging, especially during pairing devices (earlier shows when a device has been connected and we can now show if a device has been paired successfully)
  • Improved error handling (e.g. unplugging the stick will stop zigbee2mqtt now)
  • (future) Possibility to support other adapters than TI Z-stack adapters
  • (future) Keep track of device bindings

What will I as a developer notice from it?

  • Written in Typescript; makes it easier to detect errors earlier in the development process -> less bugs
  • 100% test coverage; makes it easier to detect errors earlier in the development process -> less bugs
  • Reduced amount of dependencies (and especially not maintained dependencies)
  • Simplified Zigbee API -> adding devices to zigbee-shepherd-converters will be easier
  • Automatic iAS zone enrolment -> no need to do it in zigbee-shepherd-converters anymore -> easier to add support for iAS devices
  • Push down code from zigbee2mqtt into zigbee-herdsman (= less zigbee2mqtt code size and other programs based on zigbee-herdsman are able to benefit from it).
  • Drastically reduced and simplified zigbee-shepherd codebase:
    • From 17231 to 11273 lines (= 35%), but as a big part of the code are long definition files (example), it would be fair to count without these files, resulting in: From 7675 to 3739 lines (=52% code reduction)

Koenkk avatar Aug 23 '19 19:08 Koenkk

Nice! Looking forward to trying 1.6.

james-fry avatar Aug 23 '19 21:08 james-fry

Nice! Looking forward to trying 1.6.

Just to be clear, it will NOT be included in 1.6, but will be included in the dev branch after the 1.6 release. (we first need some time to test before it can be released).

Koenkk avatar Aug 23 '19 21:08 Koenkk

Great job! Thank you a million times for all the hard work and thank you to everybody involved in this great project.

way2many avatar Aug 24 '19 20:08 way2many

That sounds amazing!! Thank you so much for such a great project and work!

santirguez avatar Aug 26 '19 06:08 santirguez

What will be the optimal hardware (CC2530, ...) for the new version?

runningman84 avatar Aug 26 '19 07:08 runningman84

Koen, Thanks for your great work. I still have a love-hate relationship with zigbee. I've quite a large network, about 37 devices, still growing. Stability is increasing because of your hard work. Less devices are getting lost. My network is expanding, 3 floors and a garden. Which never could have happened without zigbee2mqtt! Thanks thanks thanks!

bochelork avatar Aug 26 '19 07:08 bochelork

Improved Xiaomi devices pairing (should be similar to the official Xiaomi gateway now, even for Mija devices, bye bye Cannot get node descriptor for... error :smiley_cat:

Can't wait to test this... I have more than 50 Devices, lots of them Xiaomi/Aqara. :+1: Herd is still growing and pairing Xiaomi has become a pain in the #$ยง!!

Maybe, a hint to Donation is useful. Come on Guys: Just think about the difference sending for any given device (f.e. hue vs tradfri)...

dirstel avatar Aug 26 '19 08:08 dirstel

Maybe, a hint to Donation is useful. Come on Guys: Just think about the difference sending for any given device (f.e. hue vs tradfri)...

That was on my list. Thanks for reminding.

bochelork avatar Aug 26 '19 08:08 bochelork

Hi Everyone,

I am also working on Zigbee JavaScript file. Could I share it with you?

Nashet Ali Microsoft Certified Professional, Coimbatore-Tamil Nadu

On Sat, 24 Aug 2019, 00:32 Koen Kanters, [email protected] wrote:

As some of you have already noticed, lately I've been putting lots of efforts in refactoring zigbee-shepherd. Zigbee-shepherd is the Javascript Zigbee library were zigbee2mqtt is based up-on.

My biggest reason to do this is that, in my opinion, zigbee-shepherd was not maintainable and extensible. This made it very hard to fix bugs and add new features, which made it hard to take zigbee2mqtt to the next level.

I ended up in completely rewriting zigbee-shepherd from scratch. Because of that I also gave it a different name, zigbee-herdsman https://github.com/Koenkk/zigbee-herdsman. Just to give an idea of the effort that I've put into it, this job took me 100+ hours spread over 2 months.

Zigbee-herdsman will land into the zigbee2mqtt (dev branch) and zigbee-shepherd-converters after zigbee2mqtt 1.6. After this zigbee-shepherd-converters will be renamed to zigbee-herdsman-converters, as zigbee-shepherd-converters and zigbee-herdsman are not compatible.

What will I as a user notice from it?

  • Improved stability and predictability
  • Improved Xiaomi devices pairing (should be similar to the official Xiaomi gateway now, even for Mija devices, bye bye Cannot get node descriptor for... error ๐Ÿ˜บ)
  • Improved logging, especially during pairing devices (earlier shows when a device has been connected and we can now show if a device has been paired successfully)
  • Improved error handling (e.g. unplugging the stick will stop zigbee2mqtt now)
  • (future) Possibility to support other adapters than TI Z-stack adapters
  • (future) Keep track of device bindings

What will I as a developer notice from it?

  • Written in Typescript; makes it easier to detect errors earlier in the development process -> less bugs
  • 100% test coverage; makes it easier to detect errors earlier in the development process -> less bugs
  • Reduced amount of dependencies (and especially not maintained dependencies)
  • Simplified Zigbee API -> adding devices to zigbee-shepherd-converters will be easier
  • Automatic iAS zone enrolment -> no need to do it in zigbee-shepherd-converters anymore -> easier to add support for iAS devices
  • Push down code from zigbee2mqtt into zigbee-herdsman (= less zigbee2mqtt code size and other programs based on zigbee-herdsman are able to benefit from it).
  • Drastically reduced and simplified zigbee-shepherd codebase:

โ€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Koenkk/zigbee2mqtt/issues/1888?email_source=notifications&email_token=AIPEKXOVO6PO34SRNCAAZA3QGAX2TA5CNFSM4IPCPAGKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HHDPC6Q, or mute the thread https://github.com/notifications/unsubscribe-auth/AIPEKXNKNJ26URKR6W73PM3QGAX2TANCNFSM4IPCPAGA .

nashetali837 avatar Aug 26 '19 10:08 nashetali837

zigbee-herdsman has now landed in the dev branch, let the testing begin :)

Koenkk avatar Sep 09 '19 17:09 Koenkk

Hi,

Is there any breaking change? I udated dev branch and now cannot start: Sep 09 20:21:41 SmartHome systemd[1]: Started zigbee2mqtt. Sep 09 20:21:42 SmartHome npm[7178]: > [email protected] start /opt/zigbee2mqtt Sep 09 20:21:42 SmartHome npm[7178]: > node index.js Sep 09 20:21:43 SmartHome npm[7178]: zigbee2mqtt:info 9/9/2019, 8:21:43 PM Logging to directory: '/opt/zigbee2mqtt/data/log/2019-09-09.20-21-42' Sep 09 20:21:43 SmartHome npm[7178]: zigbee2mqtt:info 9/9/2019, 8:21:43 PM Starting zigbee2mqtt version 1.6.0 (commit #d83085e) Sep 09 20:21:43 SmartHome npm[7178]: zigbee2mqtt:info 9/9/2019, 8:21:43 PM Starting zigbee-herdsman... Sep 09 20:21:44 SmartHome npm[7178]: zigbee2mqtt:error 9/9/2019, 8:21:44 PM Error while starting zigbee-herdsman Sep 09 20:21:44 SmartHome npm[7178]: zigbee2mqtt:error 9/9/2019, 8:21:44 PM Error: Backup is only supported for Z-Stack 3 Sep 09 20:21:44 SmartHome npm[7178]: at Object. (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/dist/adapter/z-stack/adapter/backup.js:78:19) Sep 09 20:21:44 SmartHome npm[7178]: at Generator.next () Sep 09 20:21:44 SmartHome npm[7178]: at fulfilled (/opt/zigbee2mqtt/node_modules/zigbee-herdsman/dist/adapter/z-stack/adapter/backup.js:4:58) Sep 09 20:21:44 SmartHome npm[7178]: zigbee2mqtt:error 9/9/2019, 8:21:44 PM Failed to start zigbee Sep 09 20:21:44 SmartHome npm[7178]: zigbee2mqtt:error 9/9/2019, 8:21:44 PM Exiting... Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! code ELIFECYCLE Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! errno 1 Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! [email protected] start: node index.js Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! Exit status 1 Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! Failed at the [email protected] start script. Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! A complete log of this run can be found in: Sep 09 20:21:44 SmartHome npm[7178]: npm ERR! /home/pi/.npm/_logs/2019-09-09T18_21_44_648Z-debug.log Sep 09 20:21:44 SmartHome systemd[1]: zigbee2mqtt.service: Main process exited, code=exited, status=1/FAILURE Sep 09 20:21:44 SmartHome systemd[1]: zigbee2mqtt.service: Failed with result 'exit-code'. Sep 09 20:21:44 SmartHome systemd[1]: zigbee2mqtt.service: Service RestartSec=100ms expired, scheduling restart. Sep 09 20:21:44 SmartHome systemd[1]: zigbee2mqtt.service: Scheduled restart job, restart counter is at 2.

santirguez avatar Sep 09 '19 18:09 santirguez

Can you provide the log when running with DEBUG=* npm start? (please post it on pastebin)

Koenkk avatar Sep 09 '19 18:09 Koenkk

I have some issues with device locking. I'm not sure if it's my setup or not. I have to physically disconnect my USB device and reconnect it before I can restart zigbee2mqtt.

https://pastebin.com/xpPsiJit

BabyDino avatar Sep 09 '19 18:09 BabyDino

And it looks like I've just pastebinned my network key...

BabyDino avatar Sep 09 '19 18:09 BabyDino

@BabyDino can you check which processes have the device open? (lsof /dev/ttyUSB2)

Koenkk avatar Sep 09 '19 19:09 Koenkk

Can you provide the log when running with DEBUG=* npm start? (please post it on pastebin)

Sure, here it is: https://pastebin.com/CUF7MBMZ

santirguez avatar Sep 09 '19 19:09 santirguez

@Koenkk Next time it happens I will post the data.

Another issue with an unhandled promise rejection: https://pastebin.com/S6bj9VY5

BabyDino avatar Sep 09 '19 19:09 BabyDino

@santirguez issue should be fixed in the latest dev branch (make sure to do a rm -rf node_modules && npm install after updating).

@BabyDino I see that you are also at least suffering from the same issue as @santirguez, (Error: Backup is only supported for Z-Stack 3). Should be fixed in latest dev, can you check if it also fixed the other issue. Regarding the resource busy, it probably happens because zigbee2mqtt fails to start (because of the issue) and therefore keeping the port locked. So that should fix itself automatically when we can get zigbee2mqtt to start :)

Koenkk avatar Sep 09 '19 19:09 Koenkk

9/9/2019, 7:38:57 PM - debug: Loaded state from file /app/data/state.json
9/9/2019, 7:38:57 PM - debug: Saving state to file /app/data/state.json
9/9/2019, 7:38:57 PM - info: Starting zigbee2mqtt version 1.6.0 (commit #d83085e)
9/9/2019, 7:38:57 PM - info: Starting zigbee-herdsman...
9/9/2019, 7:38:57 PM - debug: Using zigbee-herdsman with settings: '{"network":{"panID":6754,"extenedPanID":[221,221,221,221,221,221,221,221],"channelList":[11],"networkKey":"HIDDEN"},"databasePath":"/app/data/database.db","backupPath":"/app/data/coordinator_backup.json","serialPort":{"baudRate":115200,"rtscts":true,"path":"/dev/ttyACM0"}}'
9/9/2019, 7:38:59 PM - error: Error while starting zigbee-herdsman

Cannot get more from debug log. Running latest docker container on RPi 3.

way2many avatar Sep 09 '19 19:09 way2many

@way2many probably same issue as @santirguez, please update to the latest dev (you should see commit #411f1fa). If you are on docker, wait until https://travis-ci.org/Koenkk/zigbee2mqtt/builds/582844293?utm_source=github_status&utm_medium=notification has been finished. (max 30 minutes from now).

EDIT: docker image is ready now.

Koenkk avatar Sep 09 '19 19:09 Koenkk