Calculating and displaying the historic daily duration of a variable (e.g. sunlight hours)

Hello,

I started using HA with my climatic sensors (which I also plot in a google spreadsheet) and I’m now able to display almost all the wanted variables (added through MQTT).

One point which I’m struggling a bit is the plot of the historical stats of a particular charachteristic which in google spreadsheet I succeeded:
using the daily solar panel voltage I’m extracting (just with a treshold value) the “sunrise” and “sunset” time and then calculating the daily sunlight hours. In this way I can then save and plot the “sinusoidal” function over time of the sunlight during the year.
like here
image

in HA I have tried to do something similar, search and found different discussion but no one yet with the same configuration like mine. Just understood that maybe is possible with the “history stats” features:
I first had to create a boolean variable which shows me when there’s sunlight (“Sun detection”): this is then controlled (On or Off) from an automation which reads the treshold of the solar panel voltage.

here the history and correlation of the Solar Panel with the variable

once I add the “history stats” in the configuration.yaml and then the card in dashboard it plots me a very strange graph. I understood that the maximum displayable time window is 30 days, but maybe I’m wrong and wish it was possible for an entire year. Read about the memory problems, but don’t really get how the logging of a single variable (or 365 values in a text file) somewhere could become much of a problem…
anyway here my settings

...
input_boolean:
  sun_detection:
    name: "Sun detection"
    icon: mdi:sun
...
sensor:  
  - platform: history_stats
    name: Daily_Sun_Hours
    entity_id: input_boolean.sun_detection
    state: 'on'
    type: time
    start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - 30 * 86400 
    }}'
    #start: "{{ 0 }}"
    end: '{{ now() }}'

I was expecting (hoping) the plots of the daily hours (period when the variable is ON) but instead I have this

image
I don’t know from where it reads the offset of ~560 hours.

I would prefere to have a float variable in which each day I calculate the duration time of “input.boolean.sun_detection” so to display it at least in the “history” section, but not sure how or where to do it.

maybe there’s a better way to do this, how?

Thanks