Coder Social home page Coder Social logo

esphome-zbbridge's Introduction

ESPHome for Sonoff Zigbee Bridge

ESPHome custom component and configuration for the Sonoff Zigbee Bridge with serial-over-tcp. Allows you to use the ZBBridge with e.g. ZHA or Zigbee2MQTT, in the same way as tasmota-zbbridge.

Requires special firmware for the EFR32MG21 Zigbee chip to work: https://github.com/arendst/Tasmota/tree/development/tools/fw_SonoffZigbeeBridge_ezsp.

Loading the firmware onto the Zigbee chip is technically possible via ESPHome, by flipping GPIOs to put the chip into bootloader mode and uploading over tcp-serial. I will add more information about this later, but for now it's easiest to do this through Tasmota. Once the ZB firmware is flashed, it will stay like that regardless of the ESP firmware, so you can install ESPHome the normal way and it will use the up-to-date ZB firmware without issues.

Please note that, even though the concept of a Wifi-based serial-to-IP bridge sounds great, it is not without issues. A quote from Zigbee2MQTT:

WiFi-based Serial-to-IP bridges are not recommended for Silicon Labs EZSP adapters as the serial protocol does not have enough fault-tolerance to handle packet loss or latency delays that can normally occur over WiFi connections. If cannot use a locally connected USB or UART/GPIO adapter then the recommendation is to use remote adapter that connected via Ethernet (wired) to avoid issues with EZSP caused by WiFi connections.

And some more discussion here: Consider removing the ITEAD Sonoff ZBBridge from ZHA integration list of hardware as EZSP over WiFi-based bridges is often not stable #17170

If anything, you need a very stable Wifi connection, and even then, EZSP, the protocol used by the EFR32MG21 Zigbee chip, just isn't very suited to run over a Wifi connection. YMMV.

How to use

  • Put sonoff_zbbridge.yaml in your ESPHome configuration directory, alongside your other .yaml configuration files.
  • Put the custom_components/ directory with its contents in that same directory, so that you end up with:
my_esphome_configs/
├── custom_components/
│   ├── serial-server/
├── sonoff_zbbridge.yaml
├── my_other_esp.yaml
├── yet_another_esp.yaml
├── ...
  • Edit sonoff_zbbridge.yaml as needed (Wifi credentials, etc.). By default, the configuration mirrors tasmota-zbbridge: same port, same baud rate, etc.
  • Compile and upload as you normally would

ZHA Configuration

  • In Home Assistant, go to Configuration > Integrations and choose ADD INTEGRATION
  • Scroll all the way down to select Zigbee Home Automation
  • Select Enter manually as serial port
  • Select Radio Type EZSP = Silicon Labs EmberZNet protocol:...
  • Set Serial device path to socket://[zbbridge_address]:[port], fill in appropriately (e.g. socket://sonoff_zbbridge.local:8888, socket://10.0.0.11:4321)
  • Set port speed to 115200 (this should be set according to the firmware present on your ZB chip, e.g. ncp-uart-sw-6.7.8_115200.ota -> 115200)
  • Click Submit and if all goes well, you should see Success!

Note that ZHA does not add your device to Home Assistant through the ESPHome integration. A discovery notification should appear separately in HA, allowing you to add your Bridge as a regular ESPHome node. That way you can monitor it, add sensors like status, wifi_status, etc., like normal. This, however, is not required for ZHA to function. If you decide not to add your device through the integration, be aware that ESPHome sets a reboot timer for 15 minutes by default, which will cause your device to reboot automatically if api: was set in sonoff_zbbridge.yaml and no Home Assistant API connection was established. You can add reboot_timeout: 0s to the api: entry to prevent this behavior.

Credits to: Oxan van Leeuwen for the original implementation and tube0013 for additional information.

esphome-zbbridge's People

Contributors

thegroove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

esphome-zbbridge's Issues

[REQUEST] Zeroconf (mDNS) automatic network discovery compatibility with Home Assistant ZHA integration

@thegroove Please consider adding automatic network discovery of this so can be discovered by Home Assistant’s ZHA integration:

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

Support for Zeroconf network discovery of Tube's ESPHome based Zigbee Gateways was recently added to the ZHA integration:

home-assistant/core#48420

I believe that would need to explicitly add support for the mDNS record name that you choose to Home Assistant for discovery:

home-assistant/core@6ba0629

PS: I think that automatically discovering it makes this more user-friendly compared to tasmota-zbbridge on ITead Sonoff ZBBridge.

sonoff_zbbridge.yaml not validating in ESPHome

The default file is not getting validated and giving following error:

`
INFO Reading configuration /config/esphome/sonoff_zbbridge.yaml...
ERROR Unable to load component serial_server.binary_sensor:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in load_unlocked
File "", line 790, in exec_module
File "", line 228, in call_with_frames_removed
File "/config/esphome/custom_components/serial_server/binary_sensor.py", line 10, in
class
= ns.class
('BinarySensor', binary_sensor.BinarySensor, cg.Nameable)
AttributeError: module 'esphome.codegen' has no attribute 'Nameable'
Failed config

binary_sensor.serial_server: [source /config/esphome/sonoff_zbbridge.yaml:37]

Platform not found: 'binary_sensor.serial_server'.
platform: serial_server
name: Zigbee to serial
`

sonoff_zbbridge.yaml compilation error

After commenting the binary sensor for serial server the sonoff_zbbridge.yaml validated correctly with out any error but the compilation is throwing another error:

`
INFO Reading configuration /config/esphome/sonoff_zbbridge.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing zigbeebridge (board: esp_wroom_02; framework: arduino; platform: platformio/espressif8266 @ 2.6.3)

HARDWARE: ESP8266 80MHz, 80KB RAM, 2MB Flash
Dependency Graph
|-- 1.0
|-- 1.2
Compiling /data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/serial_server/serial_server.cpp.o
Compiling /data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/uart/uart_component_esp8266.cpp.o
Compiling /data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/uart/uart_component_esp_idf.cpp.o
In file included from src/esphome/components/serial_server/serial_server.cpp:21:0:
src/esphome/components/serial_server/serial_server.h:33:25: fatal error: ESPAsyncTCP.h: No such file or directory

Compiling /data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/uart/uart_debugger.cpp.o



#include <ESPAsyncTCP.h>
^
compilation terminated.
Compiling /data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/wifi/wifi_component.cpp.o
*** [/data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/serial_server/serial_server.cpp.o] Error 1
Compiling /data/zigbeebridge/.pioenvs/zigbeebridge/src/esphome/components/wifi/wifi_component_esp32_arduino.cpp.o
========================== [FAILED] Took 2.84 seconds ==========================
`

Import oxan's serial stream server custom component for ESPHome as an external component in ESPHome

FYI, @oxan has now made his UART/Serial stream server available as a new external component for ESPHome v1.18+ on GitHub:

https://github.com/oxan/esphome-stream-server

external_components:
  - source: github://oxan/esphome-stream-server

stream_server:

ESPHome version 1.18 and later has added a new feature to support such external component which can now easily be imported:

https://esphome.io/components/external_components.html

Add ESPHome standard project identifier, version, logo, and link to docs in firmware

Home Assisistant announced latest ESPHome added a new standard for project identifier, version, logo, and link to docs in firmware:

https://www.home-assistant.io/blog/2021/06/16/power-up-your-esp-projects/#esphome-embracing-projects

ESPHome: embracing projects

We want to make it easy for creators to sell ESPHome powered products that offer a great user experience. ESPHome projects embrace local control and integrate nicely with Home Assistant, and so each extra ESPHome product that our users can buy is a win.

To make it easier to keep creators and users connected once a product is installed, projects can now add a project identifier and version to their firmware (docs). With today’s release this information will be available in the device information, logging output and the mDNS discovery info.

The goal is to integrate the projects tighter into the ESPHome dashboard by showing the project’s logo, link to the documentation and issue pages and allow installing updates.

https://www.esphome.io/components/esphome.html#project-information

Project information

"This allows creators to add the project name and version to the compiled code. It is currently only exposed via the logger, mDNS and the device_info response via the native API. The format of the name should be author_name.project_name."

# Example configuration
esphome:
  ...
  project:
    name: "thegroove.esphome-zbbridge"
    version: "1.0.0"

PS: This was part of a larger article about making ESP firmware and project more user-friendly and easier to get started with:

https://www.home-assistant.io/blog/2021/06/16/power-up-your-esp-projects/

PPS: They also announced ESPHome Dashboard has been updated with a simplified and streamlined wizard for new configurations:

https://www.home-assistant.io/blog/2021/06/16/power-up-your-esp-projects/#esphome-dashboard-simplified-and-streamlined

PPS: As they also announced ESP Web Tools for making onboarding easier by simplifying web flashing new firmware via webserial:

https://www.home-assistant.io/blog/2021/06/16/power-up-your-esp-projects/#esp-web-tools-installing-projects-on-your-microcontroller-via-the-browser

Could not compiling the node with serial_server component after update ESPHome to version 2021.10.02

INFO Reading configuration config/zb-bridge-e33083.yaml...
WARNING Found 'HfAEH$A-3)KSAZ#h' (see wifi->networks->1->password) which looks like a substitution, but 'A' was not declared
INFO Detected timezone 'Asia/Almaty'
INFO Generating C++ source...
INFO Backup config will take: 708 bytes
INFO Compiling app...
Processing zb-bridge-e33083 (board: esp_wroom_02; framework: arduino; platform: platformio/espressif8266 @ 2.6.2)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 2MB Flash
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 2.0.0
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ArduinoJson-esphomelib> 5.13.3
|-- <ESP8266WiFi> 1.0
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
Compiling .pioenvs/zb-bridge-e33083/src/esphome/components/serial_server/serial_server.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/color.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/component.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/controller.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/entity_base.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/helpers.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/log.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/scheduler.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/esphome/core/util.cpp.o
Compiling .pioenvs/zb-bridge-e33083/src/main.cpp.o
Generating LD script .pioenvs/zb-bridge-e33083/ld/local.eagle.app.v6.common.ld
Compiling .pioenvs/zb-bridge-e33083/lib4d9/ESP8266WiFi/BearSSLHelpers.cpp.o
Compiling .pioenvs/zb-bridge-e33083/lib4d9/ESP8266WiFi/CertStoreBearSSL.cpp.o
src/esphome/components/serial_server/serial_server.cpp: In member function 'void esphome::serial_server::SerialServer::serial_read()':
src/esphome/components/serial_server/serial_server.cpp:77:29: error: 'class esphome::serial_server::SerialServer' has no member named 'readBytes'
         size_t read = this->readBytes(buf, min(len, 128));
                             ^
src/esphome/components/serial_server/serial_server.cpp:77:56: error: 'min' was not declared in this scope
         size_t read = this->readBytes(buf, min(len, 128));
                                                        ^
src/esphome/components/serial_server/serial_server.cpp:77:56: note: suggested alternative:
In file included from /root/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/algorithm:62:0,
                 from src/esphome/core/optional.h:19,
                 from src/esphome/core/component.h:7,
                 from src/esphome/components/serial_server/serial_server.h:23,
                 from src/esphome/components/serial_server/serial_server.cpp:21:
/root/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/stl_algo.h:4226:5: note:   'std::min'
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^
In file included from src/esphome/components/uart/uart.h:6:0,
                 from src/esphome/components/serial_server/serial_server.h:24,
                 from src/esphome/components/serial_server/serial_server.cpp:21:
src/esphome/components/serial_server/serial_server.cpp: In member function 'virtual void esphome::serial_server::SerialServer::dump_config()':
src/esphome/components/serial_server/serial_server.cpp:93:64: error: 'network_get_address' was not declared in this scope
     ESP_LOGCONFIG(TAG, "  Address: %s:%u", network_get_address().c_str(), this->port_);
                                                                ^
src/esphome/core/log.h:97:90: note: in definition of macro 'esph_log_config'
   esp_log_printf_(ESPHOME_LOG_LEVEL_CONFIG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                          ^
src/esphome/components/serial_server/serial_server.cpp:93:5: note: in expansion of macro 'ESP_LOGCONFIG'
     ESP_LOGCONFIG(TAG, "  Address: %s:%u", network_get_address().c_str(), this->port_);
     ^
Compiling .pioenvs/zb-bridge-e33083/lib4d9/ESP8266WiFi/ESP8266WiFi.cpp.o
Compiling .pioenvs/zb-bridge-e33083/lib4d9/ESP8266WiFi/ESP8266WiFiAP.cpp.o
*** [.pioenvs/zb-bridge-e33083/src/esphome/components/serial_server/serial_server.cpp.o] Error 1
========================== [FAILED] Took 5.19 seconds ==========================

[Feature Request] Compatibility with new ZB-GW03 eWeLink Ethernet Zigbee Gateway (wired network bridge)

@thegroove Request esphome-zbbridge compatibility with new ZB-GW03 eWeLink Ethernet Zigbee Gateway (wired network bridge).

https://templates.blakadder.com/ewelink_ZB-GW03

ZB-GW03 eWeLink Ethernet Zigbee Gateway (wired network bridge) look to be a spiritual successor of ITead Sonoff ZBBridge.

It has the same Zigbee module but features an ESP32 chip and a wired Ethernet port (instead of older ESP8266/ESP8285 with WiFi):

https://community.home-assistant.io/t/zb-gw03-ewelink-ethernet-zigbee-gateway-now-hacked-with-tasmota-zbbridge-so-can-be-used-via-mqtt-or-as-a-remote-zigbee-adapter-with-home-assistant-zha/341223

ZB-GW03 eWeLink Ethernet Zigbee Gateway now hacked with Tasmota ZBBridge so can be used via MQTT or as a remote Zigbee adapter with Home Assistant ZHA

arendst/Tasmota#12764

ZB-GW03 v1.0 and ZB-GW03-V1.2 is apparently sold rebranded under many names, including EACHEN and SmartWise brands:

https://ewelink.eachen.cc/product/eachen-ewelink-zigbee-bridge-pro-zbbridge-pro/

https://www.okosabbotthon.hu/smartwise-zigbee-bridge-pro

https://ewelinkcommunity.net/device-lists/zigbee/eachen-zb-gw03/

https://www.aliexpress.com/item/4000459723849.html

https://www.amazon.de/APP-Fernbedienung-Sprachsteuerung-Funktioniert-Verbindung-Smart-Produkten/dp/B094JKVLNR/

[Feature Request] Compatibility with "SONOFF Zigbee Bridge Pro" (ZBBridge-P) based on ESP32 and CC2652P

This request comes a little ahead of its time since this ITead Sonoff ZBBridge-P is not available to buy yet, but it will be soon ;)

https://community.home-assistant.io/t/itead-sonoff-zbbridge-p-coming-soon-a-new-cc2652-and-esp32-based-sonoff-zigbee-bridge-and-sensors-from-itead-leaked-via-fcc/378924

UPDATE! ZBBridge-P (a.k.a. "ZB Bridge-P") has now been released as "SONOFF Zigbee Bridge Pro" as is now available for purchase:

https://itead.cc/product/sonoff-zigbee-bridge-pro/

FYI, FCC leak show CC2652P and ESP32 based Sonoff ZBBridge-P v1.1 Zigbee Bridge coming from ITead.

https://fccid.io/2APN5ZBBRIDGEP

Internal pictures posted from FCC show using an unannounced Texas Intruments CC2652P (CC2652P1) MCU chip based “SM-031 v1.1” radio module which must be made by CoolKit (the company that makes their EFR32MG21 based “SM-011 V1.0” module).

ESP32 has replaced the ESP8266/ESP8285, and it also looks like added an on-board clock-battery too, presumably for RTC (Real-Time Clock)?

https://fccid.io/2APN5ZBBRIDGEP/Internal-Photos/Internal-Photos-5613131

image

image

image

image

image

image

image

image

FFC also leaked new Sonoff branded Door/Window Sensor, Motion Sensor, Temp/Humidity Sensor, and a Button as wireless Zigbee devices, all with the same CCC2652P (CC2652P1/CC2652P1F) chip which +20 dBm capable power amplifier is really overkill for battery-operated sensors and should on theory use more battery power than if they would have used the compatible CC2652R or CC2652RB.

Sadly it looks like even this new variant of Sonoff ZBBridge still uses Wi-Fi instead of wired Ethernet network like the newer ZB-GW03:

https://community.home-assistant.io/t/zb-gw03-ewelink-ethernet-zigbee-gateway-now-hacked-with-tasmota-zbbridge-so-can-be-used-via-mqtt-or-as-a-remote-zigbee-adapter-with-home-assistant-zha-and-zigbee2mqtt/341223

Ethernet is preferred by DIY users who flash Tasmota or ESPHome in order to use it as a remote Zigbee adapter with ZHA or Zigbee2MQTT because tunnelling serial communication over a serial stream server connection and the serial APIs of the Zigbee stacks are not robust/stable over WiFi as assume a direct connection, which is why both ZHA and Zigbee warns against using WiFi-based networked-attached Serial-to-IP Zigbee bridges/gateways/adapters:

https://www.home-assistant.io/integrations/zha#warning-about-wi-fi-based-zigbee-to-serial-bridgesgateways

https://www.zigbee2mqtt.io/advanced/remote-adapter/connect_to_a_remote_adapter.html

According to digiblur who broke this news, these are slated to be released in March of 2022:

https://www.digiblur.com/2021/12/new-sonoff-zigbee-bridge-and-sensors.html

Not sure if this is intended to permanently replace the popular ITead Sonoff ZBBridge

https://community.home-assistant.io/t/sonoff-zbbridge-sonoff-zigbee-bridge-from-itead/187346

As I understand ITead have not abandoned Silicon Labs yet but it is just that Silabs chip stocks have suffered worse than most other companies during the still currently ongoing worldwide chip shortage.

PS: Assume it will use the same firmware for CC2652P as “Sonoff Zigbee 3.0 USB Dongle Plus”:

https://community.home-assistant.io/t/sonoff-zigbee-3-0-usb-dongle-plus-by-itead-is-based-on-texas-instruments-cc2652p-can-now-be-ordered-for-10-99/340705/283

[Future Request] Sending software command for reboot to bootloadre in GUI

thya ZBGW we was adding script for rebooting the NCP in bootloader mode.
If having one hardware reset and on force bootloader pin its better but some hardware dont have that implanted but the tuya is not having that.

By sending one reset command and then reading the EZSP version for knowing witch command set that need being used and then sending the right frame with reboot in bootloader mode.
The EZSP is using frame counters for all commands so need doing it in right sequence so not needing recalculating the frames all the time (static sequence).

The script is in this issue banksy-git/lidl-gateway-freedom#5.
The commands is documented and if you like have more information i can digging for getting it.

Best is making it support protocol version 7 and 8 and older is not very likely finding on newer devices.

I finding implanting x-modem is not needed better the user is using one terminal program like minicom (Linux) or extra PuTTY (Windows) for doing the upload.

If getting one firmware that is possible using in router mode is also possible making on script for leaving and joining the network with serial commands that can being triggered with the GUI.

[Feature Request] Compatibility with new ZiGate-Ethernet Gateway / Bridge

Suggest consider is also mention in readme that this firmware should also be compatible with new ZiGate-Ethernet hardware.

ZiGate-Ethernet has been released as open source hardware by Frédéric Dubois a.k.a. fairecasoimeme and is available at zigate.fr

image

https://github.com/fairecasoimeme/ZiGate-Ethernet

https://zigate.fr/produit/zigate-ethernet/

https://zigate.fr/documentation/descriptif-de-la-zigate-ethernet/

https://zigate.fr/documentation/installation-de-tasmota-pour-la-zigate-ethernet/

Note! This board ships without the PiZiGate + (Zigbee PCB antenna) as standard so you would need to add that option to use it:

https://zigate.fr/produit/pizigatev2/

image

ZiGate radio and this should work out-of-the-box with Home Assistant's ZHA integration via the zigpy-zigate radio library for zigpy

https://github.com/zigpy/zigpy-zigate

https://www.home-assistant.io/integrations/zha/

According to @fairecasoimeme it should also be compatible with ESPHome using esphome-zbbridge as alternative firmware:

https://github.com/thegroove/esphome-zbbridge

fairecasoimeme/ZiGate#366 (comment)

Board is apparently sized to fit the enclosure case made for Raspberry Pi 4

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.