Extracting grid data from History

Hi all

I hope to be able to extract some custom data from the history log by specific times. In this case, I want my imported grid data from my solar setup, but at a different time to the default midnight to midnight.

As the import effectively ceases as the sun rises I would like to extract the import data from (nominally) 6am yesterday to 6am today as a number.

On this screen grab you can see that the data exists, and on the day depicted a total of approximately 8 kWh would be the response.

I have approached this via the history_stats sensor explained here:

with the following entry into configuration.yaml

sensor:
    - platform: history_stats
      name: Grid Input Last 24
      entity_id: sensor.power_grid_in_today_kw
      state: "*"
      type: count
      end: "{{ now().replace(hour=6, minute=0, second=0, microsecond=0) }}"
      duration:
        days: 1

The response in sensor.grid_input_last_24 is zero when the history shows approximately 1 kWh for the recent 24 hours.

I note that the ‘type’ string limits to time, ratio, and count so I assume these do not aggregate the data over the period. I have tried the other two without (as expected) success.

I have searched the forum without success

Are there any suggestions to achieve what I want? Thanks for reading