Topic variable in MQTT json_attributes_template

Hi,

I am trying to setup a MQTT Sensor that subscribes to a wildcard topic and then sets attributes based on the topic that triggered the update.

I was thinking something along these lines (pseudo code):


binary_sensor:
  - platform: mqtt
    name: "My Sensor"
    state_topic: "/some/topic"
    json_attributes_topic: "/some/other/topic/#"
    json_attributes_template: "{{ { 'last_attribute_topic': topic } | tojson }}"

topic doesn’t exist as a usable variable. Two questions:

  1. Does this variable exist under a different name and I am just not able to find it?
  2. If it does not exist, it seems like it might be relatively straightforward to add. Where would I start with that?

Thanks!

How would that wildcard even work? Surely it should only goto one topic?

The template then defines which values to take from that topic.

I would use a tool like Node-Red choose the relevant topic that way and push the correct topic via MQTT Discovery