Calculation with Template Sensors

HI. I never did this before and googled it for a while, maybe someone could point me in the right direction with this please?

I am simply just trying to do a normal calculation to create a new sensor.
So I got this so far:

#enrgy after Smarty
template:

  • sensor:
    • name: “Energy_after_Smarty”
      unit_of_measurement: “watt”
      state: >
      {% set t = states(‘sensor.shelly_em_channel_2_power’) | float %}
      {% set u = states(‘sensor.myenergi_zappi_21946697_internal_load_ct1’) | float %}
      {{ (t - u) }}

When I try it in the developer area it shows me the result, but I guess I do a mistake adding it to the configuration.yaml somewhere.

it says after this
{% set t = states(‘sensor.shelly_em_channel_2_power’) | float %}
missed comma between flow calculation entries

and
{% set u = states(‘sensor.myenergi_zappi_21946697_internal_load_ct1’) | float %}
bad intention of a mapping entry.

Would be very grateful for your help.
Cheers

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

I can imagine that it has been asked before a lot, and a link makes it easier to manage things fast. Believe me I have tried to search for the solution and when I would have found one I would have not posted it.
Thank you though

Please format the code you posted because it’s illegible in its current state. The link tom_l posted leads to a set of guidelines which includes instructions for formatting code properly.

Thank you Taras this was helpful and it stopped the errors. Have a nice day.