Difference between 2 sensors

Good day everyone… I’m try to do something similar, but i have always error report from HA

Can you please check this code for me?

# Calculated Value Sensor : Battery_Garage_KWH
  - platform: template
    sensors:
      Battery_Garage_KWH2:
        entity_id:
        - sensor.energy_meter_1_energia 
        - sensor.inv_gar_out_energia
        value_template: =
          {set BatGarIn2 = states.sensor.energy_meter_1_energia.state| float }
          {set BatGarOut2 = states.sensor.inv_gar_out_energia.state| float }
          {{ (BatGarIn2 - BatGarOut2)|round(1) }}

What error?

(I can probably guess, looking at that template, but it really helps people help you if you actually share these things)

1 Like

The bracket starts a Jinja2 line.
The characters following the bracket decide how the line should be treated.
{% is an internal handled line
{{ is a line that returns a result

YAML is key-value pairs.
The format is key: value, like platform: template

1 Like

Where exactly did you get all that template code?

I’m guessing some sort of hallucinogenic AI?

1 Like