Zigbee2Tasmota - Same MQTT topic for every device

Hi everyone,
I’m testing Zigbee2Tasmota to get my window and door sensors status.
It works, but I’ve got a problem.

Every device has a unique ShortAddr (eg. 0x123F).
My devices are 0x2E8F and 0xF34F.
This is what Tasmota sends to MQTT broker for 0x2E8F:

tele/sonoff-z2t/SENSOR = {"ZigbeeReceived":{"0x2E8F":{"Power":false,"LinkQuality":65}}}

and this is what it sends for 0xF34F:

tele/sonoff-z2t/SENSOR = {"ZigbeeReceived":{"0xF34F":{"Power":false,"LinkQuality":70}}}

As you can see it sends same topic but with different payload.

On homeassistant I’ve created two binary sensors…

- platform: mqtt
  name: "finestra_soggiorno_01"
  state_topic: "tele/sonoff-z2t/SENSOR"
  value_template: "{{ value_json.ZigbeeReceived['0x2E8F'].Power }}"
  device_class: window
  payload_on: true
  payload_off: false
  
- platform: mqtt
  name: "porta_ingresso"
  state_topic: "tele/sonoff-z2t/SENSOR"
  value_template: "{{ value_json.ZigbeeReceived['0xF34F'].Power }}"
  device_class: door
  payload_on: true
  payload_off: false

they works, but if I open/close the 0x2E8F window I see this on HA log…

2019-12-05 23:56:32 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute '0xF34F' (value: {"ZigbeeReceived":{"0x2E8F":{"Power":true,"LinkQuality":60}}}, template: {{ value_json.ZigbeeReceived['0xF34F'].Power }})
2019-12-05 23:56:35 WARNING (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: porta_ingresso with state topic: tele/sonoff-z2t/SENSOR. Payload: {"ZigbeeReceived":{"0x2E8F":{"Power":true,"LinkQuality":60}}}, with value template Template("{{ value_json.ZigbeeReceived['0xF34F'].Power }}")`

…and if I open/close the 0xF34F door I see this…

2019-12-05 23:56:45 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'dict object' has no attribute '0x2E8F' (value: {"ZigbeeReceived":{"0xF34F":{"Power":true,"LinkQuality":60}}}, template: {{ value_json.ZigbeeReceived['0x2E8F'].Power }})
2019-12-05 23:56:47 WARNING (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: finestra_soggiorno_01 with state topic: tele/sonoff-z2t/SENSOR. Payload: {"ZigbeeReceived":{"0xF34F":{"Power":true,"LinkQuality":70}}}, with value template Template("{{ value_json.ZigbeeReceived['0x2E8F'].Power }}")`

How can I solve this problem ?

Thank you

Sorry I can’t help. I had to google about Zigbee2Tasmota, did not know it existed. I’m currently running zigee2mqtt on an CC2530/ESP01 combo as a coordinator, but have no intention on reflashing the ESP01 at the moment. However, on black Friday I ordered an extra CC2530 and some Xiaomi motion sensors, door sensors and an extra temperature/humidity sensor. Sure going to try this one out when they arrive.

Take a look here

Thank you, it works :slight_smile:

Could you share your configuration?

This is one of my binary sensors

- platform: mqtt
  state_topic: "tele/sonoff-z2t/SENSOR"
  name: "finestra_soggiorno_01"
  value_template: >
    {% if value_json.ZigbeeReceived['0x2E8F'] is defined %}
      {% if value_json.ZigbeeReceived['0x2E8F'].Power == true %}on{% else %}off{% endif %}
    {% else %}
      {{ states('binary_sensor.finestra_soggiorno_01') }}
    {% endif %}
  payload_on: "on"
  payload_off: "off"
  availability_topic: "tele/sonoff-z2t/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"
  device_class: window

Another solution is to create an homeassistant automation (called demultiplexer) to create a unique device topic (I called z2t/sensor/)

### AUTOMATION ###

- id: '1575665811777'
  alias: sonoff-z2t demultiplexer
  hide_entity: true
  trigger:
    platform: mqtt
    topic: tele/sonoff-z2t/SENSOR
  action:
    service: mqtt.publish
    data_template:
      topic: '{{ ''z2t/sensor/'' + (trigger.payload_json.ZigbeeReceived.keys() | list)[0]
        | string }}'
      payload_template: '{{ trigger.payload }}'
      retain: true

### BINARY_SENSOR ###

- platform: mqtt
  state_topic: "z2t/sensor/0x2E8F"
  name: "finestra_soggiorno_01"
  value_template: >
    {% if value_json.ZigbeeReceived['0x2E8F'].Power is defined %}
      {% if value_json.ZigbeeReceived['0x2E8F'].Power == true %} on {% else %} off {% endif %}
    {% else %}
      {{ states('binary_sensor.finestra_soggiorno_01') }}
    {% endif %}
  payload_on: "on"
  payload_off: "off"
  availability_topic: "tele/sonoff-z2t/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"
  device_class: window

It works, but now I changed again my architecture. I don’t like same topic for all devices…so I’m trying zigbee2mqtt + remote nodemcu (esphome fw) + CC2530

Can you share your esphome setup ? I’m currently using a cc2530 + esp01 with espeasy, but if possible I would like to switch to esphome.

Here it is…

Unfortunately, that is the espeasy setup which I have, not the esphome setup.

Right! Sorry…my mistake about the name. I have espeasy

hey! Try this :
SetOption89 1
here is related website where I get this from.

Topic is device specific, to allow more effective retained messages, if you set SetOption89 1

MQT: tele/%topic%/8F20/SENSOR ={"ZbReceived": {"Kitchen": {"Device": "0x8F20", "Voltage": 2.995, "Battery": 98, "Temperature": 21.01, "Humidity": 53.68, "Pressure": 1004.04, "PressureUnit": "hPa", "Endpoint": 1, "LinkQuality": 88}}

note that this will give specific topic for each sensor!