Measure Energy from power for Energy Dashboard

Hello
I have Sonoff POWR320D (Firmware: 1.1.1)
SonoffLAN: 3.6.0

Device provides Power, Current and Voltage entities.
Energy dashboard in HA requires Energy entity
(having device class=energy, state_class=total_increasing)

I tried few ways to get energy from power.
One i tried is as follow:

sensor:
  - platform: integration
    source: sensor.sonoff_10017fa545_power
    name: Sensor Terrace Heater energy_spent
    unit_prefix: k
    round: 2

Issue: However, this gives wrong result. Numbers are almost double then actual energy usage.

Another method i tried:

utility_meter:
  powr320d_daily_energy:
    source: sensor.sonoff_10017fa545_power 
    cycle: daily

Issue: This entity is not shown in Energy dashbaord.
Following is the detail about entity. May be since unit is W, it is not showing in energy dashboard.

state_class: total_increasing
source: sensor.sonoff_10017fa545_power
status: collecting
last_period: 147065.97
last_valid_state: 2241.29
meter_period: daily
cron pattern: 0 0 * * *
last_reset: 2024-02-23T18:30:00.015233+00:00
unit_of_measurement: W

And also it gives too much high reading than actual usage.
Actual usage was 13kwh, while showed 62kwh when i checked entity properties.

Method 3 Tried:

template:
  - sensor:
      - name: "Heater Energy"
        unique_id: "heater_energy"
        unit_of_measurement: "kWh"
        state_class: "total_increasing"
        device_class: "energy"
        state: >
          {{ (states('sensor.sonoff_10017fa545_power') | float / 1000) * (1 / 60) }}
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"

Issue: It shows double usage than actual usage in Energy dashboard.
Error Log: Entity sensor.heater_energy from integration template has state class total_increasing, but its state is not strictly increasing.

Please suggest, what is the right method to get energy from power and usable under energy dashboard.

Thanks

The fist method was correct but likely you were seeing approximation errors from using the default trapezoidal integration method. Try this:

sensor:
  - platform: integration
    source: sensor.sonoff_10017fa545_power
    name: Sensor Terrace Heater energy_spent
    method: left
    unit_prefix: k
    round: 2

You can read about the integration method choice in the documentation, https://www.home-assistant.io/integrations/integration/#integration-method

The sensor.sonoff_10017fa545_power sensor needs the following attributes:

device_class: power
state_class: measurement

If any are missing use customize to add them.