Help with sensor calculation with SNMP sensors of Synology Diskstation

Hi,
I want to calculate the Free Disk Space in percentage for Volume 1 from a Synology Diskstation. Therefor I created 3 SNMP-sensors:

# Berechnungen fuer Volume 1
# Volume 1 Groesse der Bloecke in Bytes:
  - platform: snmp
    host: 192.168.178.99
    community: public
    name: supernova_volume1_block_size
    baseoid: 1.3.6.1.2.1.25.2.3.1.4.1
    unit_of_measurement: "Bytes"
# Volume 1 Anzahl der Bloecke in Bytes insgesamt:
  - platform: snmp
    host: 192.168.178.99
    community: public
    name: supernova_volume1_blocks
    baseoid: 1.3.6.1.2.1.25.2.3.1.5.1
    unit_of_measurement: "Bytes"
# Volume 1 Anzahl der belegten Bloecke in Bytes:
  - platform: snmp
    host: 192.168.178.99
    community: public
    name: supernova_volume1_blocks_used
    baseoid: 1.3.6.1.2.1.25.2.3.1.6.1
    unit_of_measurement: "Bytes"

All three sensors get valid values. But the calculation of the Percentage seems to be wrong and get a “non numeric” error.

# Benutzter Platz Volume 1
  - platform: template
    sensors:
      supernova_volume1_used_space_percent:
        friendly_name: "SuperNova Volume 1 Used Space"
        value_template: >
          {% set usedspace = (states('supernova_volume1_block_size')| float) * (states('supernova_volume_1_blocks_used')| float) %}
          {% set maxspace = (states('supernova_volume1_block_size')| float) * (states('supernova_volume_1_blocks')| float) %}
          {{ (((usedspace / maxspace) | float) | round(0)) }}
        unit_of_measurement: "%"

I am not a Pro in YAML so I can’t see the error. Can someone help me?

Why don’t you use the synology “integration”?

I have the 2-Factor-Autentication for admins on the synology activated and don’t want to deactivate this security feature. But with the 2FA i can’t use the synology integration.

Ah, pity. Can’t make a very complex user and pass without 2fa?

No. Synology wants the 2FA just for all admins or for no one. And the user must be an admin to use the synology integration. So for me the best way is to work with SNMP.

Now here is the correct calculation, after finding some errors in the above code. It works fine:

# Berechnungen fuer Volume 1
# Volume 1 Free Space
  - platform: snmp
    host: 192.168.178.99
    community: public
    name: supernova_volume1_free_space
    baseoid: .1.3.6.1.4.1.6574.3.1.1.4.1
    version: '2c'
    unit_of_measurement: "TB"
    value_template: >
      {{ (((value | float) / 1099511627776) | round(2)) }}
# Volume 1 Size
  - platform: snmp
    host: 192.168.178.99
    community: public
    name: supernova_volume1_size
    baseoid: .1.3.6.1.4.1.6574.3.1.1.5.1
    version: '2c'
    unit_of_measurement: "TB"
    value_template: >
      {{ (((value | float) / 1099511627776) | round(2)) }}
# Benutzer Platz Volume 1 absolut
  - platform: template
    sensors:
      supernova_volume1_used_space:
        friendly_name: "SuperNova Volume 1 Used Space"
        value_template: >
          {% set free_space = states.sensor.supernova_volume1_free_space.state | float %}
          {% set size = states.sensor.supernova_volume1_size.state | float %}
          {{ (((size - free_space) | float) | round(2)) }}
        unit_of_measurement: "TB"
# Benutzter Platz Volume 1 in Prozent
  - platform: template
    sensors:
      supernova_volume1_used_space_percent:
        friendly_name: "SuperNova Volume 1 Used Space Percent"
        value_template: >
          {% set usedspace = (states.sensor.supernova_volume1_used_space.state | float) %}
          {% set size = states.sensor.supernova_volume1_size.state | float %}
          {{ (((usedspace / size) * 100 ) | round(0)) }}
        unit_of_measurement: "%"