For my NAS I created script that scans periodically all shares and provide me with information about storage consumption. Result is send to json file. Then on HA side I read this file and populate set of sensors with shares’ names and sizes. So far so good… The issue is that value for share size seems to be text, not number, so I can’t use this in cards like ApexChart, that I wanted to use to show storage consumption split.
Here is how the sensor code looks like (one for name and one for size of share):
sensor:
- platform: rest
resource: http://192.168.52.30/storage.json
name: share_name_1
value_template: '{{ value_json.data[1].share_name }}'
- platform: rest
resource: http://192.168.52.30/storage.json
name: share_size_1
value_template: '{{ value_json.data[1].share_size }}'
This returns proper values of share size, but share size it is treated as text (so ApexChart shows zero value). I tried several variations:
value_template: '{{ value_json.data[1].share_size | float }}'
or
value_template: >-
{{ value_json.data[1].share_size }}
or
value_template: >-
{{ value_json.data[1].share_size | float }}
or
value_template: >
{{ value_json.data[1].share_size }}
I even tried to create separate template sensor to convert this text to number:
- platform: template
sensors:
share_size_numeric_1:
friendly_name: 'Share Size Numeric 1'
value_template: >
{{ (states('sensor.share_size_1') | float) }}
unit_of_measurement: 'MB'
But nothing works… ApexChart shows all values as zero. The same with template editor, I can’t perform any mathematical operation on these sensors without adding float filter - they are treated as text…
So I’m scratching my head and cannot find some obvious error I’m doing here… please help!