zigpy / zigpy-zigate

A library which communicates with ZiGate radios for zigpy
GNU General Public License v3.0
32 stars 18 forks source link

[REQUEST] Zeroconf / mDNS network detection of ZiGate Pack WiFi adapter and configuration flow for ZHA integration #36

Open Hedda opened 4 years ago

Hedda commented 4 years ago

Not sure if any of you own the newer ZiGate-Ethernet (wired gateway with PiZiGate) or the older ZiGate + WiFi Pack (wireless bridge for ZiGate module) but please consider discussing and brainstorming mDNS concepts for zigpy probe method + initialization routine that can be used in a config flow by the ZHA integration component for initial Zigbee setup in Home Assistant.

https://www.home-assistant.io/integrations/zha/#discovery-via-usb-or-zeroconf

Zeroconf network discovery can be used by not only for the ZiGate Pack WiFi adapter but also for similar none-ZiGate network-attached Zigbee-adapters that will probably come in the near future, (like any other ESP8266/ESP8285 and ESP32 based gateways with a zigpy compatible Zigbee radio which will surely get a hacked firmware with similar features, and probably sooner rather than later as it is inexpensive and looks to have a great Zigbee radio.

Please also see the Zeroconf discovery for ZHA integration discussion here in the Home Assistant community forum:

https://community.home-assistant.io/t/zha-automatic-discovery-of-zigbee-coordinator-bridges-gateways-ethernet-wifi-network-devices-that-support-zeroconf-or-ssdp/293300

Anyway, this is a follow-up issue to mDNS question raised in https://github.com/home-assistant/core/pull/35161 where Adminiuga implemented a configuration flow for ZHA integration component to make the probing type of to local connect adapters and initial initialization routine much more user-friendly for new installations in the ZHA integration component for Home Assistant.

Now it would be awesome if the ZHA integration component for Home Assistant from an end-user perspective supported just as an easy detection and configuration of network networked-attached Zigbee coordinator adapters, like the "ZiGate Pack WiFi adapter".

Therefore I suggest using some kind of Zero-configuration networking (zeroconf) method, like for example mDNS, (as mDNS is already in use in Home Assistant Core), to make the ZHA integration component for Home Assistant automatically detect, connect, and configure compatible networked-attached Zigbee coordinator adapters like the "ZiGate Pack WiFi adapter" as that is otherwise already supported by the zigpy-zigate radio library for zigpy.

As I understand it, all ZiGate hardware look to be modular in design and the "ZiGate Pack WiFi adapter" was first concieved as really just an optional ESP8266/ESP8285 or ESP32 based "dumb" UART-to-TCP/IP (for Serial-port to WiFi-bridge function) for the standard "ZiGate TTL adapter" that allows users to connect to it remotely using TCP/IP over your home LAN (Local Area Network) instead of plugging it directly to your computer via the optional USB adapter.

Specifically, please see the picture of "ZiGate Pack WiFi adapter" https://zigate.fr/produit/zigate-pack-wifi-v1-3/ compared to the picture of "ZiGate TTL USB adapter" https://zigate.fr/produit/zigate-ttl/

Thus "ZiGate Pack WiFi adapter" allows ZHA users to have a networked Zigbee adapter setup like this:

ZHA <–> zigpy/zigpy-zigate <–> TCP/IP over LAN <–> ZiGate-WiFi <–> UART <–> ZiGate Radio

Suggesting this now as I just learned from @doudz there that the new v2.0 version of the ZiGate Pack WiFi adapter firmware contains "ESP-LINK from Jeelab" software which among other things adds mDNS and UART WiFi Bridge support over TCP. As I understand, version v1.x of the firmware for the ZiGate Pack WiFi adapter basically only contained a simple UART/serial-port server forwarding service ( serial server software that just acts as a dumb Zigbee to WiFi bridge for the zigpy-zigate library), while the new version v2.x also has more advanced features (which does not need to used) it still also contain a simple UART/serial-port server forwarding service, but now mDNS also makes it easier to discover the adapter on your local network.

ESP-LINK from Jeelab

Here is the list of features of this new v2.xx firmware for the ZiGate Pack WiFi adapter:

PS: @doudz Do you maybe happen to have any connections or contact with the manufacturers of ZiGate and could possibly get them to sponsor each of you guys (yourself plus @Adminiuga and @dmulcahey ) with both the ZiGate Pack WiFi adapter as well as the standard ZiGate TTL USB adapter for ZHA, zigpy and zigpy-zigate development purposes for free under the premises of no promises and no-strings-attached so that there is no pressure for you to produce as this is still just a hobby project?

Hedda commented 4 years ago

FYI, posted copy of the request in https://github.com/fairecasoimeme/ZiGate-WiFi/issues/3 on ZiGate-WiFi repo redirecting here

doudz commented 4 years ago

For information, I implemented it in zigate lib https://github.com/doudz/zigate/blob/master/zigate/transport.py#L385

Adminiuga commented 4 years ago

zeroconf discovery is outside zigpy scope. Could be implemented by radio, but ATM probably should be the best to be implemented in ZHA integration.

Hedda commented 4 years ago

Do you think some type Zeroconf like mDNS automatic network discovery of networked Zigbee WiFi-bridge adapters like the ZiGate WiFi bridge with 2.0 firmware belongs in the config flow for ZHA integration in Home Assistant?

Again, the idea is a simplified initial configuration flow that is even easier to use for first-time users. Similar to the https://github.com/home-assistant/core/pull/35161 concept but make the initial discovery + setup of networked Zigbee radio adapters in ZHA more user-friendly experience via automatic detection on the network.

Adminiuga commented 4 years ago

to make initial discovery + setup of networked Zigbee radio adapters in ZHA easier

Exactly. And I think we've discussed this already, but Zigpy is just a library for handling ZCL/ZDO requests. It does not manage the radio. it is unaware of multiple radio lib existing.

Actual radio management, configuration, detection is done by the respective radio lib.

Hedda commented 4 years ago

Home Assistant 0.110 & later should allow zeroconf instance sharing between different integrations:

See -> https://github.com/home-assistant/core/pull/35484 ("shared zeroconf instance")

This new approach allows the zeroconf instance to be shared between Home Assistant integrations.

mercenaruss commented 3 years ago

Hi, we are working on firmware for ZigStar LAN Coordinator ,we included zeroconf in the firmware. But unfortunately till now I didn't understand how to submit a PR and what information should be provided.

https://github.com/xyzroe/ZigStarGW-FW

MDNS.addService("zig_star_gw", "tcp", ConfigSettings.socketPort); MDNS.addServiceTxt("zig_star_gw", "tcp", "version", "1.0"); MDNS.addServiceTxt("zig_star_gw", "tcp", "radio_type", "znp"); MDNS.addServiceTxt("zig_star_gw", "tcp", "baud_rate", String(ConfigSettings.serialSpeed)); MDNS.addServiceTxt("zig_star_gw", "tcp", "data_flow_control", "software");

photo_2021-09-29_22-01-47

Hedda commented 3 years ago

Hi, we are working on firmware for ZigStar LAN Coordinator ,we included zeroconf in the firmware. But unfortunately till now I didn't understand how to submit a PR and what information should be provided.

https://github.com/xyzroe/ZigStarGW-FW

MDNS.addService("zig_star_gw", "tcp", ConfigSettings.socketPort); MDNS.addServiceTxt("zig_star_gw", "tcp", "version", "1.0"); MDNS.addServiceTxt("zig_star_gw", "tcp", "radio_type", "znp"); MDNS.addServiceTxt("zig_star_gw", "tcp", "baud_rate", String(ConfigSettings.serialSpeed)); MDNS.addServiceTxt("zig_star_gw", "tcp", "data_flow_control", "software");

photo_2021-09-29_22-01-47

FYI, there is more information and discussion on what is needed to be changed in Home Assistant core in their forums here:

https://community.home-assistant.io/t/zha-automatic-network-discovery-of-zigbee-coordinator-bridges-gateways-ethernet-wifi-network-adapters-that-support-zeroconf-or-ssdp/293300/

As I understand, if your Zeroconf and DNS TXT Records if correct then think you should only need to extend code in these two files:

https://github.com/home-assistant/core/blob/dev/homeassistant/generated/zeroconf.py

https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/manifest.json

The DNS server in your network router of course needs to support/enable mDNS (multicast DNS) so .local names can be used.

Hedda commented 3 years ago

FYI, there is more information and discussion on what is needed to be changed in Home Assistant core in their forums here:

https://community.home-assistant.io/t/zha-automatic-network-discovery-of-zigbee-coordinator-bridges-gateways-ethernet-wifi-network-adapters-that-support-zeroconf-or-ssdp/293300/

As I understand, if your Zeroconf and DNS TXT Records if correct then think you should only need to extend code in these two files:

https://github.com/home-assistant/core/blob/dev/homeassistant/generated/zeroconf.py

https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/manifest.json

The DNS server in your network router of course needs to support/enable mDNS (multicast DNS) so .local names can be used.

@doudz I think for the ZiGate gateway you would also need to add RadioType.zigate.name as radio_type device option as well(?):

https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/config_flow.py