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
- Can this be done by publishing something else in the demultiplexer rules?
- 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!