HAving power in W and also KW, possible?

Hi, I wish to show the power in Watt, and then I wish to calculate daily energy in KWh (so I need the sensor in KW), is it possible to have both in ESPhome code?


sensor:
  - platform: wifi_signal
    name: " AC power plug WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: " AC power plug Uptime"
  - platform: hlw8012
    update_interval: 2s  
    sel_pin: 5
    cf_pin: 14
    cf1_pin: 13
    current:
      name: " AC Current"
    voltage:
      name: " AC Voltage"
    power:
      name: " AC Power"
      id:  ac_power_plug_power
      filters:
        # Multiplication factor from W to kW is 0.001
    #    - multiply: 0.001
      unit_of_measurement: W
      on_value_range:
        - above: 4.0
          then:
            - light.turn_on: led
        - below: 3.0
          then:
            - light.turn_off: led

  - platform: total_daily_energy
    name: " AC Total Daily Energy"
    power_id:  ac_power_plug_power

You can use a platform sensor for the conversion:

  - platform: template
      sensors:
        solaredge_energy_this_year_kwh:
            friendly_name: 'This Year'
            unit_of_measurement: 'kWh'  
            value_template: "{{(states('sensor.solaredge_energy_this_year') | float / 1000) | round(2)}}"
            icon_template: mdi:white-balance-sunny

Thanks, I wish to have everything inside ESPhome, (I would then use that value to calculate daily energy inside ESPhoime), having Esphome+HASS is, for me lots of additional maintenance

  - platform: total_daily_energy
    name: "Well Pump Energy Today"
    power_id: well_power
    accuracy_decimals: 3
    unit_of_measurement: kWh
    filters:
      - multiply: 0.001

I tried this, but when using it in Lovelace i get either “unknown” or when using a gauge “Entity is non-numeric”. Did i do something wrong here?

sensor:
  - platform: template
    sensors:
      energy_this_year:
        friendly_name: "This year"
        unit_of_measurement: 'kWh'
        value_template: "{{ state_attr('sensor.solaredge_energy_this_year') | int / 1000 | round(2)}}"

Edit : This is configuration code not Lovelace code

        value_template: "{{ state_attr('sensor.solaredge_energy_this_year') | int / 1000 | round(2)}}"

Should be

            value_template: "{{(states('sensor.solaredge_energy_this_year') | float / 1000) | round(2)}}"

state_attr --> states, as the sensor does not have numeric attributes

That worked, thanks for the quick response!
One more question, rounding the value should result in a whole number right?
But im still getting a value like: 124.866.
Or do i have to use a different function for this?