Value_template for a sensor connected to tasmota + zbbridge

Hello, given this MQTT msg, which gives me the state (ZoneStatusChange) of my door sensor:

tele/tasmota_9D7F89/SENSOR = {"ZbReceived":{"0xB396":{"Device":"0xB396","Name":"contatto-2","0500<00":"000000010000","ZoneStatusChange":0,"ZoneStatusChangeZone":1,"Contact":0,"Endpoint":1,"LinkQuality":123}}}

…I can exctract that state for Home Assistant by using the following value_template in configuration.yaml:

- platform: mqtt
    name: "contatto-2"
    state_topic: "tele/tasmota_9D7F89/SENSOR"
    value_template: '{{ value_json["ZbReceived"]["0xB396"]["ZoneStatusChange"] }}'
    payload_on: 1
    payload_off: 0
    device_class: Door

But I wonder: how can modify the value_template parameter in configuration.yaml, so to use the key “contatto-2” (this is the friendly name of the sensor, in tasmota), instead of the 0xB396 key?

Thanks

You can’t. That is not how the json data is constructed. You have the one and only correct path to the value for ZoneStatusChange.

I mean you could do this but it is pointless:

    value_template: >
      {% set contatto_2 = "0xB396" %}
      {{ value_json["ZbReceived"][contatto_2]["ZoneStatusChange"] }}

Note that I changed the dash - to an underscore _ as dashes are not allowed in variable names.

I think there is a way to do it.

value_json[“ZbReceived”] should return a dict of entries (or something like it). I could iterate this dict and then find the entry with “Name” == “contatto-2”.
But I don’t know the syntax to implement it in the value_template

thanks for your help.

You could do that but it would be very Rube Goldberg.

I agree. But at this point I don’t understand if this is a Tasmota issue, given that the short name (0xB396) is randomly assigned to the device by tasmota. In this way, it would be clumsy to map the tasmota’s devices in the yaml file, especially if for some reason the short name randomly changes when I re-pair the same sensor. Any help/idea of how to solve this is greatly appreciated.

It’s ages since I used Tasmota, but I’ll try to remember.

Go to the web interface of the device and go to the settings page, is there a device id for the sensor there you can edit?

Unfortunately it seems there is not.

I could set the devices’s name only through the command “ZbName 0xB396,contatto-2” , see
https://tasmota.github.io/docs/Commands/#zigbee

But the random ID is still a substring of the mqtt msg. Then the Rube Goldberg would be necessary. (I cross-posted this to the Tasmota forum, meanwhile)

For future reference, I just solved the issue by using the SetOption83 1 command

See:

https://tasmota.github.io/docs/Zigbee/#setting-friendly-name

1 Like

I’ve just found this, and have run “SetOption83 1”, but I think I must have the template syntax wrong. This is what I’m using:

"{{ value_json['ZbReceived']['pir-lounge']['Occupancy'] }}"

…and this is an example of a message:

{"ZbReceived":{"pir-lounge":{"Device":"0x3025","Name":"pir-lounge","0500<00":"000000010000","ZoneStatusChange":0,"ZoneStatusChangeZone":1,"Occupancy":0,"Endpoint":1,"LinkQuality":79}}}

Can anyone confirm what the correct syntax should be?