kardia-as / zigpy-zboss

GNU General Public License v3.0
36 stars 4 forks source link

How to get started with zigpy-zboss and Home Assistant? #20

Closed ajlennon closed 1 year ago

ajlennon commented 1 year ago

Hi there!

I have a number of Nordic DKs and dongles here (e.g. nRF52840 Dongle) and would love to connect these up to HA.

I've programmed up the dongle with the right firmware and I have tried to add the integration into HA. The serial port is detected but I can't see how to get zigpy-zboss in here to support zboss?

Any advice would be much appreciated !!!

Thanks,

Alex

Hedda commented 1 year ago

You need to manually patch directly in the Home Assistant core, modify the source by patching the ZHA component (”zha” under components) inside it to include zigpy-zboss as well as add ”zboss” to the ZHA manifest (manifest.json) as a new radio type, in the same way that the zha component there already includes for example zigpy-znp and ”znp” radio type in ZHA manifest -> https://github.com/home-assistant/core/tree/dev/homeassistant/components/zha -> https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/manifest.json

Alternatively, I believe you can copy the ZHA component and use that as a custom component itself to override the built-in core integration or maybe perhaps even rename it? -> https://developers.home-assistant.io/docs/creating_component_index/ (a tip, if you try to do that, is to know that the manifest.json file has support for a version key which you could set to a higher version than one that comes with the core and thus it will not overwrite it on updates.

ajlennon commented 1 year ago

Thanks @Hedda !

Hedda commented 1 year ago

FYI, there is also related discussion in zigpy-zboss issue https://github.com/kardia-as/zigpy-zboss/issues/2 as well as more general discussion in zigpy issue https://github.com/zigpy/zigpy/issues/394

ebarczynski commented 11 months ago

Hi @ajlennon, have you succeeded with ZHA configuration to work with zigpy-zboss? I would like to start using nrf52840 dongle as Zigbee NCP and feel a bit lost about the required steps to get there.

Hedda commented 11 months ago

FYI, there is also related discussion in zigpy-zboss issue #2 as well as more general discussion in zigpy issue zigpy/zigpy#394

For reference, also see non-developer forum discssion -> https://community.home-assistant.io/t/nordic-semi-nrf52840-chips-with-zboss-zigbee-stack-now-usable-as-zigbee-coordinator-for-the-zha-integration-via-new-radio-library-for-zigpy/570196

ajlennon commented 11 months ago

Well to be honest I stopped. I wasn't really keen on Zigbee and was much more interested in OpenThread so we're now working on OpenThread on 802.15.4 !

jodynichols commented 10 months ago

You need to manually patch directly in the Home Assistant core, modify the source by patching the ZHA component (”zha” under components) inside it to include zigpy-zboss as well as add ”zboss” to the ZHA manifest (manifest.json) as a new radio type, in the same way that the zha component there already includes for example zigpy-znp and ”znp” radio type in ZHA manifest -> https://github.com/home-assistant/core/tree/dev/homeassistant/components/zha -> https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/manifest.json

Alternatively, I believe you can copy the ZHA component and use that as a custom component itself to override the built-in core integration or maybe perhaps even rename it? -> https://developers.home-assistant.io/docs/creating_component_index/ (a tip, if you try to do that, is to know that the manifest.json file has support for a version key which you could set to a higher version than one that comes with the core and thus it will not overwrite it on updates.

I started digging into this tonight and have flashed the device and started creating custom component (using container so this appeared easier) but man... I'm stuck. Do I need to copy the zboss folder into my custom ZHA and then edit all files where radio is mentioned and add call to zboss?

puddly commented 10 months ago

You should be able to copy the ZHA integration, add a version key to its manifest.json to make it a custom component, and apply the following patch:

diff --git a/homeassistant/components/zha/core/const.py b/homeassistant/components/zha/core/const.py
index c286d0112e9..f3bb6f9c2e7 100644
--- a/homeassistant/components/zha/core/const.py
+++ b/homeassistant/components/zha/core/const.py
@@ -10,6 +10,7 @@ import zigpy.application
 import zigpy.types as t
 import zigpy_deconz.zigbee.application
 import zigpy_xbee.zigbee.application
+import zigpy_zboss.zigbee.application
 import zigpy_zigate.zigbee.application
 import zigpy_znp.zigbee.application

@@ -262,6 +263,8 @@ class RadioType(enum.Enum):
         zigpy_xbee.zigbee.application.ControllerApplication,
     )

+    zboss = ("ZBOSS", zigpy_zboss.zigbee.application.ControllerApplication)
+
     @classmethod
     def list(cls) -> list[str]:
         """Return a list of descriptions."""

From there, the radio type will show up and you can set up ZHA to point to the serial port.

willpuckett commented 9 months ago

I flashed a Xiao nRF52840 earlier this evening. It shows up over usb serial as expected.

When I create the custom component as noted above, I get:

Error
Config flow could not be loaded: {"message":"Invalid handler specified"}

Removing the version key from manifest.json reverts back to the non-custom component.

A little googling indicated that a mismatch between the component folder name and the domain key of manifest.json can generate the above error. I checked and they're the same. I also removed the integration and recopied it from a current version off GitHub.

I think this is a super cool project and am excited to try it out! Thanks for the inspiring work to all involved and any assistance you may have to offer in advance.

willpuckett commented 9 months ago

Still trying... I did a pip install zigpy-zboss inside the container. That seemed to help. Now I'm getting the below error:

2023-10-23 19:12:00.048 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing platform homeassistant.components.zha.config_flow
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/loader.py", line 838, in get_platform
cache[full_name] = self._import_platform(platform_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 855, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 23, in <module>
from . import repairs, websocket_api
File "/usr/src/homeassistant/homeassistant/components/zha/repairs.py", line 21, in <module>
from .core.const import DOMAIN
File "/usr/src/homeassistant/homeassistant/components/zha/core/__init__.py", line 3, in <module>
from .device import ZHADevice
File "/usr/src/homeassistant/homeassistant/components/zha/core/device.py", line 35, in <module>
from . import const
File "/usr/src/homeassistant/homeassistant/components/zha/core/const.py", line 14, in <module>
import zigpy_zboss.zigbee.application
File "/usr/local/lib/python3.11/site-packages/zigpy_zboss/zigbee/application.py", line 14, in <module>
import zigpy_zboss.types as t_zboss
File "/usr/local/lib/python3.11/site-packages/zigpy_zboss/types/__init__.py", line 2, in <module>
from .basic import * # noqa: F401, F403
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zigpy_zboss/types/basic.py", line 353, in <module>
class enum_flag_uint8(enum_flag_factory(uint8_t)):
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/zigpy_zboss/types/basic.py", line 303, in enum_flag_factory
class _NewEnum(int_type, enum.Flag):
File "/usr/local/lib/python3.11/site-packages/zigpy_zboss/types/basic.py", line 307, in _NewEnum
enum.IntFlag._create_pseudo_member_.__func__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/enum.py", line 784, in __getattr__
raise AttributeError(name) from None
AttributeError: _create_pseudo_member_
2023-10-23 19:12:00.066 ERROR (MainThread) [homeassistant.config_entries] Error occurred loading flow for integration zha: Exception importing homeassistant.components.zha.config_flow
puddly commented 9 months ago

zigpy-zboss does not appear to be compatible with Python 3.11.

@DamKast Since this repository is based on zigpy-znp, take a look at this PR I made to zigpy-znp that removes unnecessary type duplication within radio libraries: https://github.com/zigpy/zigpy-znp/pull/225

JohnConnett commented 2 months ago

I have set up a development environment for Developing with Visual Studio Code + devcontainer and added zigpy-zboss support roughly as described by @puddly above.

The missing part of the puzzle is how to pass through /dev/ttyACM0 to the devcontainer. That would be useful information as part of the "How to get started".

Hedda commented 2 months ago

The missing part of the puzzle is how to pass through /dev/ttyACM0 to the devcontainer. That would be useful information as part of the "How to get started".

I do not have much experience with Docker or other PaaS/CaaS systems for handling containers, I use virtual machines instead.

I know that if you are using Docker then you to install and use something like Docker Compose for adding configuration to forward your device from the host machine to the Docker container instance, see:

https://www.home-assistant.io/integrations/zha#cant-connect-to-usb-device-and-using-docker

also check that the the USB or serial device is not being claimed other services on the host, see example.

https://www.home-assistant.io/integrations/zha#zha-start-up-issue-with-home-assistant-or-home-assistant-container

PS: Probably does not help but FYI, there are additional tips regarding installation and configuration in these zigpy documents: