Maths using two existing mqtt sensors

I’m fairly new the home assistant and I have setup ModbusTCP2MQTT to pull in data on my Sungrow Inverter

I just want to setup another sensor which finds the difference between two values so I can use the “Return to Grid” in the Energy Dashboard but I can’t get it to output a value

This is in my configration.yaml file

template:
  - sensor:
      - name: "Grid Feed Out"
        unit_of_measurement: "kWh"
        state: >
          "{{ (float(states('sensor.inverter_energy_today')) - float(states(sensor.inverter_energy_consumption_today))) }}"
  • Don’t quote multi-line templates, only single line templates.
  • You didn’t quote the entity id in the second states() function.
  • Provide a default value for the float filter.
template:
  - sensor:
      - name: "Grid Feed Out"
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.inverter_energy_today')|float(0) - states('sensor.inverter_energy_consumption_today')|float(0) }}"

How can I do this but divide “sensor.inverter_energy_consumption_today” by 1000 (because my sensor is setoff for some reason)

template:
  - sensor:
      - name: "Grid Feed Out"
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.inverter_energy_today')|float(0) - states('sensor.inverter_energy_consumption_today')|float(0) }}"

template:
  - sensor:
      - name: "Grid Feed Out"
        unit_of_measurement: "kWh"
        state: "{{ states('sensor.inverter_energy_today')|float(0) - states('sensor.inverter_energy_consumption_today')|float(0)/1000 }}"

huh
problem it says sensor.inverter_energy_today = 48.2kwh and sensor.inverter_energy_consumption_today is 6,553.5 kwh (which is actually 6.5535kwh irl, hence the divide by 1000 but thats besides the point) but its saying that Grid Feed Out is equal to 48.2kwh
do you know whats wrong?

Try using the template editor to evaluate bits of the template, e.g. what is:

{{ states('sensor.inverter_energy_consumption_today')|float(0)/1000 }}

My guess is 0 (the float default when it cant convert a number).

What does this give?

{{ states('sensor.inverter_energy_consumption_today') }}

Does it include the unit or comma?

i’ll give it a whirl in the morning, thanks for the help so far