Solar power clamp spikes

Dear community

I use a HA running in a VM on a Synology
I have two sets of solar panels ; the 2nd is integrated properly via the inverter however the first one has a broken API and cant integrate it easily via its inverter. So I have attached a power metering clamp on the cable directly
I have adjusted the sensor output via trial and error (I have good data on what is being generated and consumed on my grid) in configuration yaml as seen:

compensation:
    solar_clamp_compensated:
      unique_id: ID_Clamp_compensated
      source: sensor.solar_clamp_power
      unit_of_measurement: W
      lower_limit: true
      data_points:
      - [0.0, 0.0]
      - [0.1, 0.1]      
      - [1.0, 1.0]
      - [500, 875]

Though the values generated ending up in my power dashboard are quite accurate, there is an exception :
in the mornings , the first hour of the day, it generates a spike that makes no sense

in the picture above I would expect the first hour with sun to be less than 1KWh

a) why is this spike created?
b) how can I avoid it?

Regards
Ilias

Share the history graph of the power sensor.

How are you converting the power to energy for the energy dashboard?

Share the history graph of the energy sensor.

This is how i am converting the sensor input to a format that can appear in the energy dahsboard.

this is included in customise.yaml:

sensor.clamp_kwh_sensor:
  state_class: total_increasing
  status: collecting
  last_period: 0
  last_valid_state: 1190.0
  unit_of_measurement: Wh
  #device_class: energy
  device_class: energy
  friendly_name: Custom_Compensated_clamp_power

this is in my sensor.yaml

- platform: template
  sensors:
    clamp_kwh_sensor:
      friendly_name: clamp_kwh_sensor
      device_class: energy 
      unit_of_measurement: W
      value_template: "{{states('sensor.solar_clamp_compensated')|float(0)}}"

the raw input from the sensor is like this

and here the compensated one

You can’t just add attributes to a power sensor to make it an energy sensor. It needs to be integrated with respect to time. Feed your power sensor to this to get an energy sensor:

Use method: left

I had the integrator already in place, sorry i did not mention it.

So on the occasion of HACS not working after HAOS update to 2025.1, I had a look in the logs. I fixed HACS and I noticed my conversion to energy had a warning , I was using unit “W” while i had to use “Wh”. I changed this, I had multiple restarts due to 2025.1 updates and since then… it has been working excellently :