Using The Zigbee to Tasmota Gateway

The Zigbee to Tasmota gateway allows you to control and manage your Zigbee devices using the MQTT protocol

Ii is modelled on the Zigbee2MQTT gateway, but it runs on a dedicated gateway device, and doesn’t require a physical connection to a computer.

It is obtained by flashing an existing commercial Zigbee device with the Tasmota firmware.



Suitable hardware devices and flashing instructions are  here

For my gateway I used a Sonoff Zigbee bridge.

Initial Configuration

Assuming you have flashed the device then we need to configure it for our network.

When you start the Zigbee2tasmota gateway for the first time it uses default Zigbee settings.

These settings do not normally need to be changed.

The settings that you need to change are the MQTT settings. To do this you need to connect to the gateway using a web browser and for that we will need to know the IP address.

This you can find by looking at the DHCP server entries or using my node-red tool.

Therefore you will need to go to the DHCP server and look at the IP assignments.

My DHCP server client list is shown below.

dhcp-client-list

There may be many entries in the list ,but what you are looking for is a entry with a long expiry time as that will indicate that has recently been assigned.

The expiry time on most DHCP server is 24 hours by default.I have circled an entry above with a time of 23 hours as an illustration.

Video- Find IP Address of a New Network Device

This video takes you through the process and also show you how to assign a static IP address to a Device. This you should do for the Gateway.

Wi-Fi and MQTT Configuration

On the configuration settings of the gateway you will need to edit the Wi-Fi and MQTT settings to suit your network.

For the Wi-Fi you will to to set the Wi-Fi networks to use if not already done.

wi-fi-tasmotta-config

For the MQTT settings you need to enter the IP address /name and port of the MQTT server, and also a user name/password if used.

You will also need to configure the topic and the full topic.

MQTT-Config-tasmota

The topic is actually the name of the device and mine is called tasmota2mqtt.

The full topic is of the form (default):

  • base_topic/%topic%/%prefix%/
  • base_topic/%prefix%/%prefix%/
  • %topic%/%prefix%/
  • %prefix%/%prefix%/

The prefix is one of the standard Tasmota prefixes -Tele, Result, cmnd, INFO etc.

I have used the %topic%/%prefix%/ topic structure so you should expect to see messages with the topics like

  • tasmota2mqtt/tele
  • tasmota2mqtt/result

For my management control application I just need to subscribe to the topic tasmota2mqtt/# to see all messages to and from the Gateway.

Below is a screen shot using mosquitto_sub to subscribe to the topics.

tasmota_sensor_zigbee

The thing to notice is that all device information uses the SENSOR topic in this configuration.

Alternative Topic Form

An alternative form is to publish the device ID (short address) as part of the topic. So instead of

tasmota2mqtt/tele/SENSOR

we have

tasmota2mqtt/DC07/tele/SENSOR

Where DC07 is the device short address. In order to do this we need to enable it using the command

ZbDeviceTopic 1

and to disable it (default) use

ZbDeviceTopic 0

Note: see Zigbee commands later on

Zigbee Device Identifiers

A Zigbee device can be identified by 3 mechanisms

  • Short Address e.g 0x6C0E
  • Long Address e.g 0xA4C138DB67B5AA90
  • Friendly name e.g zbsocket1

Joining Devices to the Zigbee Network

For Zigbee devices to join the network you will first need to put the Gateway into permit to join mode which you can do using the web interface as shown below:

zigbee-tasmota-permit-join

It is also possible to do this using MQTT or by sending a command direct from the Gateway console.

The Gateway Console

The Gateway has a console that lets you view MQTT messages, and also to send Zigbee commands to the Gateway.

zigbee-tasmota-gateway console

Sending Zigbee Commands Using the Gateway Console

This I find very useful for getting familiar with the Gateway and also for testing.

For example to set a friendly name for the device 0xDC027 enter the command

zbname 0xd027,socket3

tasmota-console-setname

Notice that a response is sent out over MQTT on the topic :

tasmota2mqtt/stat/RESULT

Zigbee commands almost always have a confirmation response.

Example commands

  • ZbPermitJoin 1 //allow joining
  • ZbPermitJoin 0 //disable joining

The screen shot below shows the results:

permit-join.png

The ZbInfo command lets you get the status of individual devices or of all devices. The screen shot below is taken from the documentation page.

zbinfo-tasmo

Zbsend command

This is an important command and is used to send a command to a Zigbee device or to read/write device attributes.

The screen shot below is taken from the documentation:

zbsend-docs

Examples:

To turn a zigbee switch on/off

ZbSend {"Device":"0x6C0E","Send":{"Power":1}}

and

ZbSend {"Device":"0x6C0E","Send":{"Power":0}}

Command List

A full list of commands is available here

Sending Command Using MQTT

We can also do the same using MQTT. In which case we require an MQTT client (mosquitto_pub) .The command to change the friendly name of a device is shown below:

mosquitto_pub -h mqtt2.home -t tasmota2mqtt/cmnd/zbname -m "0xD027,zbsocket2"

Notice the MQTT topic. The command we are sending is zbname to change the friendly name of the device.

The MQTT payload contains the actual Zigbee device ID (short address)  followed by the friendly name and separated with a comma .-“0xDC027,zbsocket2

To view the response we nee to subscribe to the topic tasmota2mqtt/#.

mosquitto_sub -h mqtt2.home -t tasmota2mqtt/# -d

mqtt-commands-tasmota-zigbee

Grouping Zigbee Devices

Zigbee devices can be grouped together so that a collection of devices can be controlled with a single command.

It only makes sense to group devices of a similar type e.g lights,switches etc.

A group consists of a 16 bit number and the first step is to add a device to a group which in turn also creates the group.

I have two switches the device ids are 0x6C0E and 0xD027

To add them to a group (100) using the Zigbee console I use.

Zbsend {“device”:”0xD027″,”Send”:{“AddGroup”:100}}

and

Zbsend {“device”:”0x6C0E”,”Send”:{“AddGroup”:100}}

To turn both switch one I send a command to the group

ZbSend {“group”:100,”Send”:{“Power”:1}}

to remove from a group use RemoveGroup as shown:

Zbsend {“device”:”0x6C0E”,”Send”:{“RemoveGroup”:100}}

and you can remove all groups a deive belongs to using

Zbsend {“device”:”0x6C0E”,”Send”:{“RemoveAllGroups”:true}}

You can list all groups that a device belongs to using:

Zbsend {“device”:”0x6C0E”,”Send”:{“GetAllGroups”:true}}

Using MQTT and mosquitto_pub

We can work with groups by sending commands using an MQTT client (mosquitto_pub) as shown earlier.

to add out device to a group (group number 200) we use the command (windows and Linux)

mosquitto_pub -h mqtt2.home -t tasmota2mqtt/cmnd/Zbsend -m "{\"device\":\"0xD027\",\"Send\":{\"AddGroup\":200}}"

Notice we need to use a delimiter \.

Using the example above .What are the command to:

  • Add device 0x6C0E to the group 200
  • Add device 0x6C0E to the group 300
  • List groups device 0x6C0E belongs to
  • Remove device 0x6C0E from the group 300

Answers:

1. mosquitto_pub -h mqtt2.home -t tasmota2mqtt/cmnd/Zbsend -m “{\”device\”:\”0x6C0E\”,\”Send\”:{\”AddGroup\”:200}}”

2. mosquitto_pub -h mqtt2.home -t tasmota2mqtt/cmnd/Zbsend -m “{\”device\”:\”0x6C0E\”,\”Send\”:{\”AddGroup\”:300}}”

3. mosquitto_pub -h mqtt2.home -t tasmota2mqtt/cmnd/Zbsend -m “{\”device\”:\”0x6C0E\”,\”Send\”:{\”GetAllGroups\”:true}}”

4. mosquitto_pub -h mqtt2.home -t tasmota2mqtt/cmnd/Zbsend -m “{\”device\”:\”0x6C0E\”,\”Send\”:{\”RemoveGroup\”:300}}”

Related Tutorials and Resources:

Please Let me Know if you found it Useful
[Total: 1 Average: 5]

Leave a Reply

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