Problem with integration sensor

Hello, I have an off-grid solar installation that uses Epever’s SHI2000 inverter, powering 10 groups of LED spotlights totaling 600W. The inverter is programmed to turn on at a certain time and turn off at another, so its operation is not continuous. I got the inverter protocol from Epever with the description of the Modbus registers. With this I developed a YAML program to obtain the data of interest when the inverter operates. The program is working, but I have two problems that I can’t resolve.

  1. When the inverter is off, ESPhome continues to show the values of the entities from the last activation, when, as it is off, it should show “unavailable”.

  2. One of the entities is an “integration” whose purpose is to show the energy (Kwh) spent by the reflectors in an accumulated manner. Therefore, it should not accumulate when the inverter is turned off, but it continues to accumulate depending on the values of the last activation. This gives wrong values for the energy consumed.

  - platform: integration
    sensor: ac_output_power
    name: "11 - Energia total consumida"
    id: entocoqui
    accuracy_decimals: 3
    unit_of_measurement: "Kwh"
    time_unit: h
    integration_method: left 
    state_class: total_increasing
    device_class: energy
      - multiply: 0.0001 

Data with the inverter switched off

Inversor quiosque

01 - DATA e HORA 01-10-2023 17:15
02 - Status inversor Working
03 - Voltagem DC entrada 23,97 V
04 - Corrente DC entrada 0,00 A
05 - Potencia DC entrada 619,11 W
06 - Voltagem AC saida 219,30 V
07 - Corrente AC saida 2,68 A
08 - Potencia AC saida 587,72 W
09- Temperatura do inversor 30,0 °C
10 - Temperatura do Mosfet 29,0 °C
11 - Energia total consumida 0,034 Kwh

How to solve these problems? I appreciate the help.```

Solved ! Thank you.