Energy Dashboard Inconsistent with PVOutput

Hi,

I am running an ESP32 with 4 pulse kwh meters (Grid Import, Solar Export, House Usage and Solar Generation). All meters are 1000/pulses per kWh except Solar Export which is 1600. I realise that HA doesn’t need data from my House Usage sensor

I have these set up and working well with PVoutput and sql and other data formats. I have just started to play around with getting the data into Home Assistant Energy Dashboard.

As PVoutput takes data in 5 minute intervals I was planning to do the same cycle time and sending the data to HA Energy via MQTT. I have this seemingly working as data is coming through to HA Energy but my data seems off. Also to clarify the values I am sending just relate to the last 5 minutes (ie. not hourly or daily totals etc.).

Firstly the data I am sending to PVoutput is basically just the number of measured watt hours (for 3 of the meters that is just the number of pulses) and times by 12 (as there is 12 x 5 minutes in an hour.

I have my config file configured as follows (have all 4 sensors but only showing 1 here

mqtt: 
  sensor:
    - name: "SolarGeneration kwh"
      state_topic: "PowerESP32/SolarGeneration"
      value_template: "{{ value | float(0) / 12 }}"
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: total #measurement
      force_update: true

With my config above I have a couple of queries

  1. Does my value template look right. In essence the incoming value received via MQTT is the average WattHour value over that 5 minute period. My value template should be converting that back to Wh by dividing it by 12. I am assuming I am accounting for everything right here
  2. Guides I had seen indicated having state_class as “measurement” but when I have it as this it fails and indicates it wants me to use a last_reset variable also

More generally do I also need to let HA know anywhere that I am sending data in 5 minute increments.

The reason I find my data looks wrong is it appears to kind of graph correctly in the History Tab but in the energy tab it shows data in 24 bars but it ranges between 0.25 and -0.25kWh (for context my usage for that period in PVoutput is 22.6kWh (minus solar 4.8kWh).

Any tips and clarification would be appreciated. Thanks.

Thinking I have solved it

I was finding issues with getting it to divide my data by 12 regardless of various things I tried so I have changed my ESP32 code to send the data in Wh direct in that 5 minute interval
My configuration.yaml now is like this

mqtt: 
  sensor:
    - name: "GridImport Wh"
      state_topic: "PowerESP32/GridImport"
      value_template: "{{ value }}"
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: measurement
      force_update: true

I have then set up a helper (Utility Meter) for each sensor as Periodic Resetting, Reset Daily and Delta Values.

It has only been running for a few hours but it appears to be recording and displaying valid data. Will know more tomorrow once I have some solar data as well.

Just wish there was more of a guide somewhere on how to set this up so it wasn’t so much of a fumble your way. Good learning curve though. Will post back if I do happen to still have issues