Free space calculation from 2.7tb minus 2.5tb string. How?

I’ve followed the instruction to get my Synology sensors working, as shown below


I’ve tried this config to calculate my Synology disk free space, but it still showed unknown value. What should be the right config? Thanks

  - platform: template
    sensors:
      syno_free_space:
#        value_template: "{{ states(sensor.synology_dsm_total_size_volume_1) | float - states(sensor.synology_dsm_used_space_volume_1) | float }}"
        value_template: >-
            {% set t = sensor.synology_dsm_total_size_volume_1 %}
            {% set u = sensor.synology_dsm_used_space_volume_1 %}
            {{ t[:3] | float - u[:3] | float }}
        value_template: >-
            {% set t = states('sensor.synology_dsm_total_size_volume_1')|float %}
            {% set u = states('sensor.synology_dsm_used_space_volume_1')|float %}
            {{ t - u }}

Thanks. I use your template and get value 0.0. It’s supposed to be 0.2. What else I need to do?
The values of the source sensors are 2.7Tb and 2.5Tb. Are they string, and not value?
Thanks

The were strings until we cast them as floating point numbers.

Try this in the development tools template editor:

t = {{ states('sensor.synology_dsm_total_size_volume_1')|float }} 
u = {{ states('sensor.synology_dsm_used_space_volume_1')|float }}

t - u = { states('sensor.synology_dsm_total_size_volume_1')|float - states('sensor.synology_dsm_used_space_volume_1')|float }}

It should give:

t = 2.7
u = 2.5
t - u = 0.2

It’s sources are zeroes!

The t - u template was missing double braces {{ at the begging of the template sorry. It does not matter though as you have identified the problem.

Now check the developer tools states menu and check that these entity ids are correct (and what their values are):

sensor.synology_dsm_total_size_volume_1
sensor.synology_dsm_used_space_volume_1

They have values.

They also have the unit in the value string :roll_eyes:

Try this in the template editor:

t = {{ states('sensor.synology_dsm_total_size_volume_1')|replace('Tb','')|float }} 
u = {{ states('sensor.synology_dsm_used_space_volume_1')|replace('Tb','')|float }}
2 Likes

Wow, it is working now. Thanks a lot.
image

I add round(1) to make it one decimal place.

  - platform: template
    sensors:
      syno_free_space:
        value_template: "{{ (states('sensor.synology_dsm_total_size_volume_1')|replace('Tb','')|float - states('sensor.synology_dsm_used_space_volume_1')|replace('Tb','')|float)|round(1) }}"
1 Like

Can I add the Tb again afterwards?

Yes, use:

unit_of_measurement: Tb