UPDATE: A Wired Sonoff Zigbee Alternative

ORIGINAL POST

UPDATE 10/18: READ IF YOU PLAN TO USE HUB WITH Zigbee2Tasmota

So while the documentation in the initial post on how to compile and flash Tasmota to the ZB-GW03 works, there is a bug when using the Tasmotized device with Home Assistant.

After changing the device to a ZHA Bridge, a power disruption will prevent a reconnection to Home Assistant once power is restored. The only way to reconnect appears to be by switching the device template back to Zigbee2Tasmota, letting it start, and then back to the ZHA Bridge template. Afterwards it will reconnect as usual. A software initiated reboot DOES NOT cause the same issue.

I do not know enough to say exactly why this is the case, but my theory is that the Zigbee2Tasmota template initializes the Zigbee Radio when it boots up and maybe that is not happening with Home Assistant when the device is shut down in an unsafe state.

Fortunately, I have developed a work around which appears to work well and essentially fixes the problem without further intervention.

It requires two rules:

  1. Turning on after an unsafe shutdown changes the device back to Zigbee2Tasmota
  2. Once the device boots into Zigbee2Tasmota and the Zigbee radio is fully initialized, the device switches back to ZHA bridge.

In my somewhat brief testing, this has worked really well and the device reconnects as expected after an unsafe shutdown without any user intervention.

Unfortunately, to accomplish this, requires a bit more work than one would think. Tasmota only saves one user defined Module at a time, and I was not able to save a rule with template information, probably due to the fact that it is in JSON format. Therefore, I had to compile a new Tasmota firmware, with the two file modifications on the initial instruction page, plus two new modules, one for each template.

To compile it yourself, you just need to replace tasmota_template.h with the following. Towards the end are the modules for ESP32 devices and you can see two additional modules for the ZB-GW03, one for ZHA and one for Zigbee2Tasmota.

  1. Module 2 – ZHA_Bridge
  2. Module 3 – Zigbee2Tasmota

If you prefer, you can just download the updated firmware below:

Once you have the new firmware installed, you can use the following rules:

backlog rule1 on system#boot do backlog wifi 0; TCPStart 8888 endon; rule1 on
backlog rule2 on Info3#RestartReason=Vbat power on reset do module 3 endon; rule2 on
backlog rule3 on ZbState#Message=Started do module 2 endon; rule3 on

The first rule combines rules 1 and 2 from the initial post and sets up the Zigbee Web Server and turns off wifi. If you intend to use wifi (which I probably wouldn’t recommend), just use the following instead for the first rule:

backlog rule1 on system#boot do TCPStart 8888 endon; rule1 on

Rule2 changes the module to Zigbee2Tasmota ONLY when the power is cut and the device undergoes an unsafe shutdown.

Rule3 as soon as the device boots to Zigbee2Tasmota and the Zigbee radio is fully initialized, it switched back to ZHA Radio at which point the device should be able to reconnect to Home Assistant as expected.

An issue has been opened on Github so please reply if you have experienced the same problem:

https://github.com/arendst/Tasmota/issues/13350

Please let me know about any additional issues or if you have any problems with the above solution.

ORIGINAL POST

UPDATE 10/18: READ IF YOU PLAN TO USE HUB WITH Zigbee2Tasmota

19 thoughts on “UPDATE: A Wired Sonoff Zigbee Alternative”

  1. For me the first rule did not result in a TCP server restart, only the WIFI is turned off. I changed the syntax a bit, now it seems to work:

    backlog rule1 on system#boot do backlog wifi 0 endon on system#boot do TCPStart 8888 endon; rule1 on

  2. Hey,

    nice guideline, thanks for that.
    However I’m a perfect noob, just starting with HA and have a question: what is the tasmota-template file? Where to use that? Or when I’m done with the soldering, can I just upload the tasmota32-EWELINK-updated firmware to this gateway with ESP flasher and run these rules in Tasmota console and I’m done? Or do I have to combine these with the ones you described in your previous guideline?

    Thanks.

    1. Hey, it is probably easiest just to download the precompiled bin file I have posted above- tasmota32-EWELINK-updated. Then yes, you will solder the connections and use ESP Flasher to flash that firmware directly. Then you remove the connections and have to turn on the device.

      When you turn on a tasmota device for the first time, it creates an access point called “TASMOTA-” something. Log in with your phone or whatever and then set up your wifi credentials for the device as you want- this will be temporary since we will rely on ethernet.

      Once your device is on your wifi network, find its IP address from your router and enter it into a browser. Also plug in ethernet since the next step will disable wifi. From the homepage of the device, click on Consoles –> Console. Type “module 3” enter. Then you need to follow the instructions in my original post on how to flash the zigbee radio.

      Once the zigbee radio is flashed and you have confirmed that you have access over ethernet, you can enter the above rules, one at a time in the console again.

      Unplug the device from the wall and plug it back in.

      You should then be able to pair it with your home assistant instance using the ZHA instance and following digiblur’s instructions linked in the original post.

      Hope that helps!

      1. Thanks, that really helps a lot.

        But what about the rules you mention here?

        backlog rule1 on system#boot do backlog wifi 0; TCPStart 8888 endon; rule1 on
        backlog rule2 on Info3#RestartReason=Vbat power on reset do module 3 endon; rule2 on
        backlog rule3 on ZbState#Message=Started do module 2 endon; rule3 on

          1. I see. But only after I processed all commands in the original article. So these are not changing any of these, these are just additions, right?
            Sorry for being so rookie and thanks for the great help.

  3. Hi,

    Thanks for good tutorial. I tried to install tasmota32-EWELINK-1.bin but when I use ‘module 3’, device going to restart and after while returning to ‘module 2’ mode. More over, if I tried to update radio I’ve got message: ‘Upload Failed Invalid file signature’ It wasn’t happened with previously tasmota32-EWELINK.bin version.
    Should I use any other radio firmware?

    Regards,
    pancio

    1. Hey im glad you like the tutorial. If you already updated the zigbee radio firmware once, you don’t need to do it again. Maybe thats the issue? It sounds like the firmware and rules are working as expected Module 2 is for ZHA and the rules are designed to switch to module 2 after startup as a way to reset the zigbee radio when using ZHA. If youll see my edit from my original post, theres a fix in the latest tasmota firmware so that you dont need to toggle back and forth between ZHA and Z2T anymore. If you want zigbee2tasmota, and dont want to charge firmwares, just disable rules 2 and 3:
      rule2 off
      rule3 off

      let me know how that works for you!

  4. Thanks for tips.

    I tried to do everything from the beginning, but effect was pretty the same: restart devices after pairing device.
    Additional I tried to use newest image delivered by Tasmota ( ZIGBEE1 Version 10.0.0.1(zig_bridge32)-2_0_1_rc1(2021-11-02T17:49:20) ) and finally I’m pretty sure that my module is broken… according to logs:
    [12:24:51]Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.
    [12:24:51]
    [12:24:51]Core 1 register dump:
    [12:24:51]PC : 0x401c0b7a PS : 0x00060630 A0 : 0x800f8145 A1 : 0x3ffb2520
    [12:24:51]A2 : 0x00000000 A3 : 0x00000001 A4 : 0x3ffd7d46 A5 : 0x0000ff00
    [12:24:51]A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00060023 A9 : 0x00000000
    [12:24:51]A10 : 0x00000000 A11 : 0x00000001 A12 : 0x80091888 A13 : 0x3ffb2400
    [12:24:51]A14 : 0x00000000 A15 : 0x3ffb08c0 SAR : 0x00000007 EXCCAUSE: 0x0000001c
    [12:24:51]EXCVADDR: 0x00000001 LBEG : 0x401c05be LEND : 0x401c05d4 LCOUNT : 0x00000007
    [12:24:51]
    [12:24:51]
    [12:24:51]Backtrace:0x401c0b77:0x3ffb25200x400f8142:0x3ffb2540 0x400f90c1:0x3ffb2560 0x40101251:0x3ffb25c0 0x401016c5:0x3ffb2660 0x401017c5:0x3ffb26d0 0x400e9fb1:0x3ffb26f0 0x400ff609:0x3ffb2710 0x4010093d:0x3ffb2730 0x40100ad8:0x3ffb2760 0x401020f9:0x3ffb27a0 0x400f1755:0x3ffb27c0 0x40112e75:0x3ffb27e0 0x40112f30:0x3ffb2800 0x4013764c:0x3ffb2820
    [12:24:51]
    [12:24:51]ELF file SHA256: 0000000000000000
    [12:24:51]
    [12:24:51]Rebooting…
    [12:24:51]ets Jul 29 2019 12:21:46
    [12:24:51]
    [12:24:51]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    [12:24:51]configsip: 0, SPIWP:0xee
    [12:24:51]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    [12:24:51]mode:DOUT, clock div:2
    [12:24:51]load:0x3fff0018,len:4
    [12:24:51]load:0x3fff001c,len:1044
    [12:24:51]load:0x40078000,len:10124
    [12:24:51]load:0x40080400,len:5828
    [12:24:51]entry 0x400806a8
    [12:24:51]E (536) psram: PSRAM ID read error: 0xffffffff
    [12:24:51]E (536) spiram: SPI RAM enabled but initialization failed. Bailing out.
    [12:24:51]
    [12:24:51]00:00:00.003 HDW: ESP32-D0WDQ6-V3
    [12:24:51]00:00:00.044 UFS: FlashFS mounted with 304 kB free
    [12:24:51]00:00:00.094 CFG: Loaded from File, Count 37
    [12:24:59]E (16151) wifi:Association refused temporarily, comeback time 0 mSec
    [12:24:59]E (16161) wifi:Association refused temporarily, comeback time 0 mSec
    [12:24:59]E (16167) wifi:Association refused temporarily, comeback time 0 mSec
    [12:24:59]E (16174) wifi:Association refused temporarily, comeback time 0 mSec

    Probably PSRAM is malfunctioned.
    Device starting, reading configuration for paired device and after a few seconds going to reboot again:

    12:28:07.657 ZIG: Resetting EZSP device
    12:28:08.976 RSL: RESULT = {“ZbState”:{“Status”:1,”Message”:”EFR32 booted”,”RestartReason”:”Power-on”,”Code”:2}}
    12:28:09.076 RSL: RESULT = {“ZbState”:{“Status”:55,”Version”:”6.7.8.0″,”Protocol”:8,”Stack”:2}}
    12:28:09.079 RSL: RESULT = {“ZbState”:{“Status”:3,”Message”:”Configured, starting coordinator”}}
    12:28:11.527 RSL: RESULT = {“ZbState”:{“Status”:56,”IEEEAddr”:”0x60A423FFFE23BFD6″,”ShortAddr”:”0x0000″,”DeviceType”:1}}
    12:28:11.725 ZIG: Subscribe to group 0 ‘ZbListen0 0’
    12:28:11.826 RSL: RESULT = {“ZbState”:{“Status”:0,”Message”:”Started”}}
    12:28:11.828 ZIG: Zigbee started
    12:28:11.858 ZIG: Zigbee device information found in EEPROM (1 devices – 40 bytes)
    12:28:11.878 ZIG: No Zigbee device data
    12:28:12.188 RSL: STATE = {“Time”:”2021-11-03T12:28:12″,”Uptime”:”0T00:00:21″,”UptimeSec”:21,”Heap”:155,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:19,”MqttCount”:0,”Wifi”:{“AP”:1,”SSId”:”Kameleon2_MiWiFi2″,”BSSId”:”18:E8:29:A1:00:07″,”Channel”:6,”Mode”:”11n”,”RSSI”:100,”Signal”:-43,”LinkCount”:1,”Downtime”:”0T00:00:14″}}
    12:28:12.195 RSL: SENSOR = {“Time”:”2021-11-03T12:28:12″,”ESP32″:{“Temperature”:38.3},”TempUnit”:”C”}
    12:28:23.091 RSL: RESULT = {“ZbParent”:{“Device”:”0x0000″,”Children”:1,”ChildInfo”:[“0x04CF8CDF3C78D21C”]}}

    I’m wondering to change PSRAM chip if it’s possible…

  5. Hi again,

    So finally I managed to get some time to do the Tasmota install and it looks all went through well, however I can’t manage to integrate to HA with ZHA. Whenever I try to add it with the below parameters, I get a message that it failed to connect. I’m following digiblur’s guideline.

    Parameters I’m using:
    – Serial device path: socket://192.168.1.74:8888
    – Port speed: 115200
    – Data flow control: software
    (this value must be something new as it was not mentioned in digiblur’s instructions, but I get the same error if I chose hardware)

    I tried restarting the gateway several times as well and based on the console log, it seems to be ok for me (see below after a fresh start).

    If you have idea what I’m doing wrong or what should I try, it would really be appreciated.

    Thank you.

    00:00:00.002 HDW: ESP32-D0WDQ6-V3
    00:00:00.009 UFS: FlashFS mounted with 304 kB free
    00:00:00.022 CFG: Loaded from File, Count 23
    00:00:00.028 QPC: Count 1
    00:00:00.044 BRY: Berry initialized, RAM used=1760
    00:00:00.048 BRY: no ‘preinit.be’
    00:00:00.052 Project tasmota Tasmota Version 9.5.0(tasmota)-1_0_6(2021-10-14T02:47:55)
    00:00:00.066 BRY: no ‘autoexec.be’
    00:00:04.032 ETH: Connected at 100Mbps Full Duplex
    00:00:04.494 HTP: Web server active on tasmota_D0A2B0-0688_eth with IP address 192.168.1.74
    12:17:17.156 RSL: INFO1 = {“Info1”:{“Module”:”ZHA_Bridge”,”Version”:”9.5.0(tasmota)”,”FallbackTopic”:”cmnd/DVES_D0A2B0_fb/”,”GroupTopic”:”cmnd/tasmotas/”}}
    12:17:17.163 RSL: INFO2 = {“Info2”:{“WebServerMode”:”Admin”,”Hostname”:”tasmota_D0A2B0-0688_eth”,”IPAddress”:”192.168.1.74″}}
    12:17:17.170 RSL: INFO3 = {“Info3”:{“RestartReason”:”Software reset CPU”}}
    12:17:18.967 QPC: Reset
    12:17:21.971 RSL: STATE = {“Time”:”2021-11-28T12:17:21″,”Uptime”:”0T00:00:10″,”UptimeSec”:10,”Heap”:225,”SleepMode”:”Dynamic”,”Sleep”:50,”LoadAvg”:22,”MqttCount”:0}
    12:17:21.977 RSL: SENSOR = {“Time”:”2021-11-28T12:17:21″,”ESP32″:{“Temperature”:53.3},”TempUnit”:”C”}

      1. I used only the files you have here provided.

        Program Version 9.5.0(tasmota)
        Build Date & Time 2021-10-14T02:47:55
        Core/SDK Version 1_0_6/v3.3.5-1-g85c43024c

        It turned out that I made a mistake while I was messing around with the IP addresses.

        I like to have all my smart devices on a static IP, so it is always the same for them, so I did change the IP for the gateway as well. The problem was that I run the rules after I changed the IP, but still was connected to the gateway through the old IP and I assume TCP was started on that IP and that’s why it didn’t work after restart on the new IP.

        So I rerun all three rules you just wrote above and voila, it works now. So many thanks again for your help and support.

        Just one question: should I ever update via Tasmota or will it break any of the settings and better to stick to what I have now (using a version from October)?

        1. I think a good rule (especially for tasmota) is not to update unless you have a problem. The device isn’t directly exposed to the internet or anything so the latest security updates aren’t super critical. If you update a docker package and it breaks it’s easy to roll back- often more difficult with tasmota. I have a ton of switches in my house still on 8.2.0. Don’t want to touch them since everything works perfectly.

  6. I have a ZB-GW03-V1.3 but have never flashed a device before. Does anyone sell these pre-flashed with Tasmota for ZHA?

Leave a Reply

Your email address will not be published.