Setting up a Zigbee WiFi bridge using Tasmota and Sonoff hardware

Introduction

This post is about bridging Zigbee devices to my Home Assistant server.

From Wikipedia : “Zigbee is a low-cost, low-power, wireless mesh network standard targeted at battery-powered devices in wireless control and monitoring applications. Zigbee delivers low-latency communication. Zigbee chips are typically integrated with radios and with microcontrollers.”

zigbee logo

Make sure to not confuse with Z-Wave, they are not compatible even if they are wireless low-power mesh networks.

Being low-power, Zigbee is especially useful to battery powered devices like:

In case you’re wondering, left box is the Sonoff Zigbee Bridge (ZBBridge) and is required.

Mesh network

The zigbee wireless networking uses a mesh topology, meaning that devices known as routers are speaking to each other, routing message all around as needed to reach far nodes. One cost is that this drains battery, so having always on nodes is not practical when running on batteries. I recommend on any big network to have a few nodes powered by main, such as plugs, light switches or light bulbs.

ZBMINI

Requirements

This post assumes you already have a working installation of Home Assistant on your LAN network.

To build below minimum setup, on top of your Wi-Fi and Home Assistant, you need a Sonoff Zigbee Bridge (ZBBridge) and a Sonoff temperature / humidity sensor (SNZB-02).

The flashing process is done using a Serial-to-USB adapter, easiest is to grab one based on the CH340G chip or FTDI. Always double check voltage when using such adapter, using accordingly either 3.3V or 5V.

The zigbee bridge has two chips to connect to both zigbee and Wi-Fi networks, assuming the routing between both networks.

The nodes have a single zigbee chip for networking.

Getting started

We are going to setup a few things to use our temperature sensor node. Here are the building blocks, starting from the end node:

  • The temperature sensor has a single button to pair it to the zigbee network.
  • The Sonoff zigbee bridge is powered over USB and has a single button to enable pairing of new sensors. To use it with Home Assistant instead of the built-in eWeLink cloud app, we are going to flash a new firmware called Tasmota.
  • Lastly Home Assistant needs to add an integration to use zigbee bridge. This integration also helps manage the zigbee sensors.

The trickiest part being to flash Tasmota, most of this post is about that specific step.

Flashing Tasmota to Sonoff ZBBridge

A note about Tasmota and requirements

Tasmota is an open source firmware aimed at ESP8266 or ESP8285 based devices. It features a great flexibility and abilities to set it up using its built-in web interface.

Using the dedicated ZBBridge image (tasmota-zbbridge.bin), it is very easy to set its Wi-Fi network and MQTT connection settings.

So the macro steps are:

  • Open the ZBBridge device to access the PCB
  • Wire the Serial-to-USB on the ZBBridge PCB
  • Flash Tasmota using Tasmotizer
  • Disconnect the adapter
  • Power the ZBBridge over regular USB
  • Access the Tasmota web interface and finally configure the device
  • If everything went fine, put back the PCB in its enclosure

You’ll need some hardware:

  • Sonoff Zigbee bridge as our main victim of the day
  • Serial-to-USB adapter to flash firmware, one supporting 3.3V (5V would likely destroy your chip)
  • Breadboard and jumping wires
  • Computer with Wi-Fi or smartphone to setup Tasmota over Wi-Fi
  • Obviously, a computer with a USB port

… and a few pieces of software:

  • Tasmotizer for flashing. This is an all-in-one tool to automatically flash Tasmota to a device
  • Windows, if you use Tasmotizer as in this guide
  • A web browser, I’m using Google Chrome

Refer to Tasmota Getting Started page if you’re new or not using Windows.

Wiring the ZBBridge to the Serial-to-USB adapter

If you’re used to flashing, don’t get fooled, you have to ground an extra pin, also there are multiple TX/RX on the ZBBridge.

Here is the correct wiring:

Adapter side ZBBridge side Notes
GND GND Power
GND IO0 Enable flashing of ESP chip
VCC 3V3 Power, don’t forget to set adapter to 3V3 and NOT 5V
RX ETX Data exchange
TX ERX Data exchange

I’m using breadboard jumper wires, there pins are thinner than usual Dupont cables. A Dupont won’t fit the small thru holes of the ZBBridge. Having proper connection might get tricky.

Connecting to Tasmota

After successfully flashing Tasmota firmware, the device starts a new Wi-Fi hotspot in the form tasmota_XXXXXX-####.

Connect to it and open http://192.168.4.1/ to administrate the device.

Tasmota configuration

Tasmota needs a few tweaks to work properly in our situation:

  • Updated firmware for the zigbee chip
  • Setup MQTT server and credentials
  • Activate Home Assistant ZHA template, delegating full control to Home Assistant
  • Optional : Network configuration, always nice to set a static IP address on the network

Flashing Zigbee firmware

Get latest firmware for zigbee chip from https://github.com/arendst/Tasmota/tree/development/tools/fw_SonoffZigbeeBridge_ezsp

From the Tasmota web UI, go to Firmware Upgrade > Upgrade by file upload

Note: Might be possible to use the direct OTA URL but I haven’t tried 🙂

Updating MQTT

From the Tasmota web UI, go to Console this time.

Issue below command to setup your MQTT server (you COULD use Configuration > Configure MQTT but I had issues saving credentials).

Adjust the command as per your requirements, especially mqtthost, mqttuser and mqttpassword.

Backlog mqtthost 192.168.0.xxx; mqttport 1883; mqttuser XXXX; mqttpassword XXXX; topic zigbridge;

Device will restart.

Activate Home Assistant ZHA template

Back to the console, use this line as-is, except if you want to use a custom port (default is 8888).

backlog rule1 on system#boot do TCPStart 8888 endon ; rule1 1 ; template {"NAME":"Sonoff ZHABridge","GPIO":[56,208,0,209,59,58,0,0,0,0,0,0,17],"FLAG":0,"BASE":18} ; module 0

Defining a static IP address

This is optional but my ISP router limits DHCP to range x.x.x.2 to x.x.x.26.

The “IPAddressX” commands means:

  1. IP address
  2. Gateway
  3. Mask
  4. DNS server (here, Google)
IPAddress1 192.168.0.XXX
IPAddress2 192.168.0.1
IPAddress3 255.255.255.0
IPAddress4 8.8.8.8
restart 1

Restart one more time, but the device is very fast to reboot and reconnect!

See Tasmota Commands / Wi-Fi for full reference. If you do this often, consider using backlog command.

Adding ZBBridge to Home Assistant

Finally, let’s add the Zigbee bridge to Home Assistant.

In Home Assisstant, go to Configuration > Integrations > Add integration

Select Zigbee Home Automation from the list of integrations.

Configure using :

  • Serial port : Enter manualy
  • Ratio type : EZSP
  • Serial device path : socket://<IP of device>:8888
  • Speed: 115200

It should detect your bridge and add it to integrations.

Adding devices

To add a zigbee device, go to Configuration > Integrations and hit Configure on your Zigbee Home Automation integration.

At the bottom right is a “+ Add device” button, hit it.

This starts pairing mode for the coordinator, it’s time to press pairing button on the SNZB-02 temp/humidity device.

As you add devices, they’ll appear in the screen, proposing to set their name.

About devices

Once you’re done adding devices, you can review what’s done from Devices menu.

Since these are not using WiFi, that’s the only place you can check their state and especially the battery level.

The sensors are automatically created for them. You’re done for the zigbee configuration!

About sensors

When sensors are created, use the Developer Tools menu of Home Assistant to have a look.

I’m filtering here on the one added for the demo:

References

The official Tasmota getting started doc

This post is partially based on Sonoff Zigbee Bridge ZBBridge Zigbee compatibility info.

Zigbee Home Automation for Home Assistant.

Post Author: Shut

Leave a Reply

Your email address will not be published. Required fields are marked *