Create Energy kwh measurement for energy dashboard from

Hey
I’m trying to make a sensor for the energy dashboard (from watts reading with a couple of conditions) but for some reason it’s not working.




  - platform: template
    sensors:
     energy_in:
       friendly_name: "Energy Into House"
       device_class: energy
       unit_of_measurement: 'W'
       value_template: >
         {% set watts_out = states('sensor.shelly_shem_3_######_1_current_consumption') | float %}
         {% if watts_out <= 0 %}
             {{states('sensor.shelly_shem_3_######_1_current_consumption')| float * -1 }}
         {% elif watts_out > 0 %}
             {{states(0) }}
         {% endif %}

  - platform: integration
    source: sensor.energy_in
    name: energy_from_grid
    unit_prefix: k
    method: left
    round: 2
    unit: kWh

Please help

Nvm Solved