Getting data from MQTT JSON message

Hi! I’m using Telegraf to create MQTT messages from Ubuntu to HASS Mosquito MQTT broker. I do this to get, amongst other things, hard drive temperatures.

The path is telegraf/my_home_server/hddtemp. It works nicely, but the JSON is for a single disk, where the device name (in this example “sdd”) is inside the JSON:

{"fields":{"temperature":0},"name":"hddtemp","tags":{"device":"sdd","host":"my_hist_name","model":"TOSHIBA MG07ACA14TE","source":"127.0.0.1","status":"SLP","unit":"*"},"timestamp":1651054380}

I get one such JSON message for each disk. I use the configuration below, but it will obviously get the temperature of each disk, and assign them one by one to the same entity, instead of getting one entity per disk. Which is not helpful.

 - platform: mqtt
     name: "HD temperature for /dev/sdc"
     unique_id: "hddtemp_sdc"
     state_topic: "telegraf/my_home_server/hddtemp"
     unit_of_measurement: "°C"
     value_template: "{{ value_json.fields.temperature }}"

So the question then becomes, how can I create one entity per JSON message. Or perhaps: how can I apply the temperature value ONLY if the the disk name in the JSON matches the entity?

I think you should send to different topics, like telegraf/my_home_server/hddtemp/sdd

I admit I’m not very familiar with Telegraf, but it doesn’t appear to be any way neither on the input hddtemp plugin side, nor the output MQTT plugin side to force the reporting to be split into topics, but I could be wrong.

Are you saying there is no way of dismissing the JSON messages which do not apply with Jinja or some other way? Any filtering mechanism would do really.