Concatenating json values into a single output

Would appreciate some guidance with the following.

I am publishing the following json string over MQTT to my HA server.

‘{“json” : {“source” : “/dev/sda1”, “target” : “/”, “fstype” : “ext4”, “size” : “28G”, “avail” : “20.2G”, “used” : “6.4G”}}’

This is received correctly and I am able to extract the individual values

Client mosqsub|9750-dnsdhcp received PUBLISH (d0, q0, r0, m0, ‘sensor/dnsdhcp/drives’, … (121 bytes))
{“json” : {“source” : “/dev/sda1”, “target” : “/”, “fstype” : “ext4”, “size” : “28G”, “avail” : “20.2G”, “used” : “6.4G”}}

However I would like to concatenate the values and display as two lines, something like the following.
Volume /dev/sda1 to / as ext4
Stats 28G, 20.2G, 6.4G

I have tried the following…

-   platform: mqtt
    state_topic: "sensor/dnsdhcp/root"
    name: "Volume"
    qos: 0
    value_template: >-
      "{{ (value_json['json'].source) }} to {{ (value_json[json].target) }}" as  {{ (value_json[json].fstype) }}

But this just produces an output of Uknown, if I just use the following for the value template

`"{{ (value_json['json'].source) }} to"`  

It will display “/dev/sda1 to”

I have searched the forums and google for pointers but can’t seem to find anything that helps.

Is it possible to create a value template with concatenated json values on one single line?
Would it be possible to concatenate the two sets of values onto two lines? Or do I need to send the two sets of values as two topics?

Any suggestions greatly welcomed.

You overlooked to add quotes to the word json in the second and third templates.

    value_template: >-
      {{ (value_json['json'].source) }} to {{ (value_json['json'].target) }}" as  {{ (value_json['json'].fstype) }}

Taras, thanks for the reply.
I couldnt see the wood for the trees :smiley:

1 Like

You’re welcome!

Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It helps others find answers to similar questions.

Taras, marked as the solution and have now completed what I wanted to do, which was basically build a monitor page for my network connected devices and servers.
Thanks for your help, very much appreciated.

1 Like