Calculate current nett usage from consumption and production

Hi! I’m using HASS for a while now, but I want to have a card on my dashboard that shows my current actual power usage (which can be negative due to solar production). The problem lies with the calculation for the nett usage for me: It should be as simple as ‘current consumption - current production’, but it’s not that simple it seems.
I currently have this in my template.yaml:

  - sensor:
#Huidig netto verbruik
    - name: 'Nett usage'
      device_class: energy
      unit_of_measurement: kW
      state: >
        {% if is_number(states('sensor.power_consumption')) and is_number(states('sensor.power_production')) %}
          {{ (states('sensor.power_consumption') - states('sensor.power_production')) | float (0) }}
        {% else %}
         0
        {% endif %}

Is there something I’m missing?

you’re missing the float filter on the first item you’re subtracting from. Notice how the production has | float, that’s your filter. And before you say “It’s from the docs”. Yes, the docs are wrong and it’s getting fixed in the next version.