How to set separate unit_of_measurement on json_attributes_template?

I am gettings device info as mqtt like this:

Topic: deviceinfo/newlogserver
{
  "state": 6.8,
  "attributes": {
    "newlogserver_minne_totalt": 1971,
    "newlogserver_minne_anvant": 1729,
    "newlogserver_minne_ledigt": 241,
    "newlogserver_hdd_totalt": 19.5,
    "newlogserver_hdd_anvant": 11.7,
    "newlogserver_hdd_ledigt": 6.8
  }
}

HA configuration.yaml

mqtt:
  sensor:
    - name: "Deviceinfo newlogserver"
      unique_id: "deviceinfo_newlogserver"
      state_topic: "deviceinfo/newlogserver"
      value_template: "{{ value_json.state }}"
      json_attributes_topic: "deviceinfo/newlogserver"
      json_attributes_template: "{{ value_json.attributes | tojson }}"
      unit_of_measurement: 'GB free'

I am sending this data to InfluxDB2.
My initial problem was that I had trouble finding the data.
So I added unit_of_measurement of GB free and I could find the data.
GB Free is not a very good unit for all the measurements, it does not really matter but it looks bad.

Is there a way of settings a separate unit for the attributes? It could be data or something.
… or is it better to separate it all to separate sensors? I have six devices sending this data so that would make 36 sensors.

Better to separate it out. And I’d personally name it Memory Free with a unit_of_measurement as GB.

1 Like

For anyone who might be interested, I changed it so the mqtt looks like:

Topic: deviceinfo/newlogserver/diskfree
{
  "state": "5.1"
}

… and the configuration.yaml:

    - name: "Deviceinfo newlogserver Disk Free"
      unique_id: "deviceinfo_newlogserver_diskfree"
      state_topic: "deviceinfo/newlogserver/diskfree"
      value_template: "{{ value_json.state }}"
      unit_of_measurement: 'GB'
      icon: mdi:server

So every reported measurement makes one sensor.
Thanks petro.