Create a template sensor for energy calculation

Hi!

I am trying to create a template sensor that subtracts one from the other and one of them is derrived from my solar panels.

- platform: rest
 resource: http://192.168.1.35:8484/getdevdata.cgi?device=2&sn=SP001260322C0277
  scan_interval: "00:00:10"
  name: sensor.solar_realtime_kW
  device_class: energy
  value_template: "{{ value_json.pac | float / 1000 | round(2) }}"
  unit_of_measurement: "kW"

and another api sensor sensor.power_production_trollslandevagen_3

But when i use developer tools>templates and put the first sensor in

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

I get an unknown result. and

but in when looking at the sensor in entities it gives me the readout.

What am i missing?

Entity IDs are always slugs, so they will never contain uppercase letters:

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

Also, keep in mind that states are always strings, so if you are going to perform mathematical operations on them you will need to convert them to a numeric data type.

{{ states('sensor.solar_realtime_kw') | float(0) - states('sensor.power_production_trollslandevagen_3') | float(0) }}

You don’t need to add the sensor domain to the name either, home assistant will do that for you.

This:

name: Solar Realtime kW

Will create the entity id, sensor.solar_realtime_kw

Yes that was the problem.
No i know not to name the sensor sensor:)

Thank you!