MQTT demultiplexer automatic sensor discovery for tasmota2zigbee

I have automations that take the MQTT published by tasmota2zigbee gateway and demultiplex them to new MQTT topics, which then allows me to create template MQTT sensors for door sensors andtemp/humidity sensors etc. Mostly based on help from MQTT - topic - help

What I would really like now, is to change these demultiplexer rules, so that I do not need to create the MQTT template sensors myself, but that HomeAssistant will automatically detect the new sensors, exactly how HomeAssistant automatically detect them for other Tasmota Wifi devices when using SetOption19 1

so

  1. Can this be done by publishing something else in the demultiplexer rules?
  2. If yes for 1, what is needed to do this?

Here is a sample of what I currently have:

Sample template sensors

binary_sensor:
#DS Baby room
- platform: mqtt
  name: "Baby Room Door"
  state_topic: "tele/zigbee/0xA3EF/ZoneStatusChange"  
  json_attributes_topic: "tele/zigbee/0xA3EF/Attr"
  #expire_after: 7200   #v0.100 and above
  device_class: opening
  payload_off: '0'
  payload_on: '1'

sensor:
#DS Baby room
- platform: mqtt
  name: "Baby Room Door Battery"
  state_topic: "tele/zigbee/0xA3EF/Battery"  
  expire_after: 7200   #v0.100 and above
  device_class: battery
  unit_of_measurement: '%'

#TH Outside
- platform: mqtt
  name: "Outside Temperature"
  state_topic: "tele/zigbee/0x9870/Temperature"
  json_attributes_topic: "tele/zigbee/0x9870/Attr"
  unit_of_measurement: "°C" 
  expire_after: 7200
  device_class: temperature
- platform: mqtt
  name: "Outside Humidity"
  state_topic: "tele/zigbee/0x9870/Humidity"
  unit_of_measurement: "RH%" 
  expire_after: 7200
  device_class: humidity
- platform: mqtt
  name: "Outside TH Battery"
  state_topic: "tele/zigbee/0x9870/Battery"  
  expire_after: 7200   #v0.100 and above
  device_class: battery
  unit_of_measurement: '%'

And here is a copy of my demulitplexer rules as they are currently:

automation:
  ## Zigbee2tasmota MQTT demultiplexer automations
  - alias: 'MQTT Zigbee Occupancy'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Occupancy' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Occupancy
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Occupancy }}
          retain: true

  - alias: 'MQTT Zigbee Zone Status'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'ZoneStatusChange' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/ZoneStatusChange
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].ZoneStatusChange }}
          retain: true

  - alias: 'MQTT Zigbee Humidity'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Humidity' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Humidity
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Humidity }}
          retain: true

  - alias: 'MQTT Zigbee Temperature'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Temperature' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Temperature
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Temperature }}
          retain: true

  - alias: 'MQTT Zigbee Pressure'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Pressure' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Pressure
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Pressure }}
          retain: true

  - alias: 'MQTT Zigbee Illuminance'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Illuminance' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Illuminance
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Illuminance }}
          retain: true

  - alias: 'MQTT Zigbee Attribute'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: "{{ 'BatteryPercentage' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}"
      - condition: template
        value_template: "{{ 'BatteryVoltage' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}"
    action:
      - service: mqtt.publish
        data_template:
          topic: tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Attr
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {"voltage":{{ trigger.payload_json.ZbReceived[code].BatteryVoltage }},"battery level":{{ trigger.payload_json.ZbReceived[code].BatteryPercentage }}}

  - alias: 'MQTT Zigbee Battery'
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: "{{ 'BatteryPercentage' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}"
    action:
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Battery
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].BatteryPercentage }}
          retain: true

Sample JSON sent by the tasmota2zigbee gateway:

{"ZbReceived":{"0x785A":{"Device":"0x785A","Name":"th_scullery","Temperature":20.24,"Endpoint":1,"LinkQuality":37}}}
{"ZbReceived":{"0x2C10":{"Device":"0x2C10","Name":"th_fridge","Temperature":3.64,"Humidity":23.78,"Endpoint":1,"LinkQuality":37}}}
{"ZbReceived":{"0xE209":{"Device":"0xE209","Name":"sw_master_bedroom","Power":0,"Endpoint":1,"LinkQuality":21}}}
{"ZbReceived":{"0x75D2":{"Device":"0x75D2","Name":"th_main_bathroom","BatteryVoltage":2.97,"BatteryPercentage":86,"Temperature":18.19,"Humidity":70,"Endpoint":1,"LinkQuality":29}}}

Many thanks in advance for any insights on how to do this!

That’s because the “other Tasmota WiFi devices” are publishing topics and payloads that conform with the specifications for Home Assistant’s MQTT Discovery service.

Are you using this (ZigBee2Tasmota)? I may be wrong but I can’t find anything in its documentation indicating it supports Home Assistant’s MQTT Discovery.

1 Like

Yes thats (ZigBee2Tasmota) exactly what I am using. It definitely doesn’t support it it.

Alright so the doc show I need to publish the configuration as json to the discovery prefix. That makes sense and makes me believe its possible building this using automation rules in the demultiplexer rules.

now to figure this out.

This might help:

1 Like

Alright thanks for all the tips in this thread, I was able to have it post configs to auto discover my devices I add to the gateway.

So far, only for sensors.
Still need to work on the switches and figure out how to deal with buttons.

automation:
  ## Zigbee2tasmota MQTT demultiplexer automations
  # Motion sensors
  - alias: 'MQTT Zigbee Occupancy'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Occupancy' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/binary_sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}Occupancy/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Motion",
              "device_class": "motion",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Occupancy",
              "payload_off": "0",
              "payload_on": "1"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Occupancy
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Occupancy }}
          retain: true

  # Opening (Door) sensors
  - alias: 'MQTT Zigbee Zone Status'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'ZoneStatusChange' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/binary_sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}ZoneStatusChange/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }}",
              "device_class": "opening",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/ZoneStatusChange",
              "payload_off": "0",
              "payload_on": "1"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/ZoneStatusChange
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].ZoneStatusChange }}
          retain: true

  # Humidity
  - alias: 'MQTT Zigbee Humidity'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Humidity' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}Humidity/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Humidity",
              "device_class": "humidity",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Humidity",
              "expire_after": "7200",
              "unit_of_measurement": "%"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Humidity
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Humidity }}
          retain: true

  # Temperature
  - alias: 'MQTT Zigbee Temperature'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Temperature' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}Temperature/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Temperature",
              "device_class": "temperature",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Temperature",
              "expire_after": "7200",
              "unit_of_measurement": "°C"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Temperature
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Temperature }}
          retain: true

  # Pressure
  - alias: 'MQTT Zigbee Pressure'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Pressure' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}Pressure/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Pressure",
              "device_class": "pressure",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Pressure",
              "expire_after": "7200"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Pressure
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Pressure }}
          retain: true

  # Illuminance
  - alias: 'MQTT Zigbee Illuminance'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: >
          {{ 'Illuminance' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}Illuminance/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Illuminance",
              "device_class": "illuminance",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Illuminance",
              "expire_after": "7200"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Illuminance
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Illuminance }}
          retain: true

  # Battery
  - alias: 'MQTT Zigbee Battery'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: "{{ 'BatteryPercentage' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}"
    action:
      - service: mqtt.publish
        data_template:
          topic: homeassistant/sensor/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}Battery/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Battery",
              "device_class": "battery",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Battery",
              "expire_after": "7200",
              "unit_of_measurement": "%"
            }
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Battery
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].BatteryPercentage }}
          retain: true

1 Like

Hi All, this is something I’ve been scavenging for. I have a ZBBridge and initially I configured it with ZHA, however I wasn’t able to get the state of my IKEA Tradfri kitchen lights from ZHA (say if I turned them on manually). I’ve switched to tasmota2mqtt with the ZBBridge which seems both stable and capable of reading state changes however its a pain to set up devices with. I can’t find a way to add my tradfri LED 30W driver to home assistant via ZBBridge, is this something someone else has figured out using these templates?

Thanks

Hey @gorbek

So a light is one device type I don’t have on my zigbee network, also I don’t have access to an ikea shop in my country. However I can try and guide you to figure it out.

The closest device type I have figured out for you, to show how it works, is the Sonoff ZBR3 (basic zigbee switch that also act as a repeater for me).

The latest version of these templates I am using myself is on github here.

So what you need to do is, look at the JSON output on the tasmota console, when you turn on/off the light (but also the other actions it support, I suspect dimming and cold or warm mode in your case).

So when I turn on the ZBR3, I see this:

04:48:23 MQT: tele/tasmota_zbbridge/SENSOR = {"ZbReceived":{"0xE209":{"Device":"0xE209","Name":"Main Bedroom ZBR","Power":1,"Endpoint":1,"LinkQuality":8}}}

The JSON these templates receive will look like this:

{
    "ZbReceived": {
        "0xE209": {
            "Device": "0xE209",
            "Name": "Main Bedroom ZBR",
            "Power": 1,
            "Endpoint": 1,
            "LinkQuality": 8
        }
    }
}

That will change the state of the switch in Home Assistant to on.

Here are the templates for I have for this.
First, the receiving automation:

  # Switch (WIP)
  - alias: 'MQTT Zigbee Switch State'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/tasmota_zbbridge/SENSOR'
    condition:
      - condition: template
        value_template: "{{ 'Power' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}"
      - condition: template
        value_template: >
          {{ 'Name' in ((trigger.payload_json.ZbReceived.values() | list)[0].keys() | list) }}
    action:
      ### 1 automatic home assistant configuration
      - service: mqtt.publish
        data_template:
          topic: homeassistant/switch/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/config
          retain: true
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {
              "name": "{{ trigger.payload_json.ZbReceived[code].Name }}",
              "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Power",
              "command_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/SetPower",
              "state_off": "0",
              "state_on": "1",
              "payload_off": "Off",
              "payload_on": "On"
            }
      ### 2 update state
      - service: mqtt.publish
        data_template:
          topic: > 
            tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Power
          payload: >
            {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %}
            {{ trigger.payload_json.ZbReceived[code].Power }}
          retain: true

There are 2 parts above, 1 the automatic configuration part, 2 the part that update states.

Next, the part where we can send an on/off command back to the switch from home assistant:

  # Switch (WIP)
  - alias: 'MQTT Zigbee Switch Set Power'
    mode: parallel
    initial_state: true
    trigger:
      - platform: mqtt
        topic: 'tele/zigbee/+/SetPower'
    action:
      - service: mqtt.publish
        data_template:
          topic: cmnd/tasmota_zbbridge/ZbSend
          payload: >
            {"Device":"{{ (trigger.topic.split('/') )[2] }}","Send":{"Power":"{{ trigger.payload }}"}}
          retain: false

So you will need to look at the json messages on the tasmota console to see what the ikea light driver reports.
Then build a mqtt light device based on that while building the demultiplexing part.
Then you need to build the part sending commands back to the driver from home assistant.
Then once you have done all of that and it works, then only build the automatic configuration part.

Hope that helps you.

1 Like

Very Helpful David, thanks and good work pulling this together. I’ve actually enabled my tradfri light as a switch for now (it appears to be working using “Power” for on and off) but it has no dimming functionality - which I’m ok with at the moment. When I get some time I might build out your script to include that as well per your explanation.

I’ll also note my sonoff motion detectors have different templates and states compared to the ones you have used, however that’s easy enough to account for to get them working (they actually paired as door sensors via the zonechange state).

I added 2 rows so the sensors appear as 1 device
Visible in mqtt integration (device and entity)
You can edit the entity and set the area

Works with my Sonoff SNBZ-02 (temperature, humidity sensor)

Create automation for each sensor
for example:

alias: MQTT Zigbee Humidity
trigger:
  - platform: mqtt
    topic: tele/tasmota_zbbridge/SENSOR
condition:
  - condition: template
    value_template: >
      {{ 'Humidity' in ((trigger.payload_json.ZbReceived.values() |
      list)[0].keys() | list) }}
action:
  - service: mqtt.publish
    data_template:
      topic: >-
        homeassistant/sensor/{{ (trigger.payload_json.ZbReceived.keys() |
        list)[0] }}Humidity/config
      retain: true
      payload: |
        {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %} {
          "name": "{{ trigger.payload_json.ZbReceived[code].Name }} Humidity",
          "device_class": "humidity",
          "state_topic": "tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0] }}/Humidity",
          "expire_after": "7200",
          "unit_of_measurement": "%",
          "unique_id": "{{ trigger.payload_json.ZbReceived[code].Device }}_humidity",
          "device": {"identifiers": ["{{ trigger.payload_json.ZbReceived[code].Device }}"], "name": "{{ trigger.payload_json.ZbReceived[code].Name }}"}
        }
  - service: mqtt.publish
    data_template:
      topic: >
        tele/zigbee/{{ (trigger.payload_json.ZbReceived.keys() | list)[0]
        }}/Humidity
      payload: >
        {% set code = (trigger.payload_json.ZbReceived.keys() | list)[0] %} {{
        trigger.payload_json.ZbReceived[code].Humidity }}
      retain: true
mode: parallel
initial_state: true
max: 10

unique_id:
An ID that uniquely identifies this sensor. If two sensors have the same unique ID, Home Assistant will raise an exception.

device:
You must have the same parameters for each entity

change the device name in the tasmota console:
for examlpe: ZbName 0x128F,sonoff SNZB-02

if you edit your existing automation
don’t forget to put a comma at the end of line “unit_of_measurement”: “%”

if the device does not appear, use MQTT Explorer
look for the homeassistant topic and clear the retain message from the sensor and
Restart HA

sorry for my english

mqtt_integration

2 Likes

I found that using SetOption89 to split message directly on the mqtt server and then configuring the right discovery messages for home assistant allows you to use everything without automation.

To help generate the required JSON message to be publish I built a helper tool. Maybe it is useful to someone else. https://github.com/bfritscher/homeassistant-mqtt-ui

Thanks for great idea, I just converted your solution into a generic one using pyscript.

1 Like