Rest-Sensor formating Values and Attributes


I have defined a RESTful-Sensor:

 resource: "http://xxx:61208/api/3/fs"
    - name: "Data FS /"
      unique_id: data_fs_root
      json_attributes_path: $.[?(@.mnt_point == '/')]
      state_class: measurement
        - device_name
        - fs_type
        - mnt_point
        - size
        - free
        - percent
      value_template: "{{ (value_json|selectattr('mnt_point','eq','/')|first)['used'] }}"

This is a call to the Glances-Service on my Homeserver.
The call works and I get the following result:

state: 3012525264896
state_class: measurement
device_name: /dev/sdj1
fs_type: ext4
mnt_point: /mnt/extUsb
size: 11904378875904
free: 8291829956608
percent: 26.6
friendly_name: Data FS ExtUsb

Is there a way to format the values? I know I can do it with the value_template. What about the json_attributes? I would like to avoid a template sensor just to format them.

Best regards

Can’t (currently) be done. If you want to format them or assign a unit of measurement, you’ll need to set up a template sensor. This can be done quickly via the UI (under Helpers). For example, free state template:

{{ state_attr('sensor.data_fs', 'free') }}

and a device class of data_size & unit of B. You can then customise the frontend display with the units you want to show (e.g. TB).