Sensor start time defined by another sensors state

Hi All,

I’m trying to log and average time for a machine cycle which is calculated daily.

I’m using an ESP32 that sends the start cycle pulse, which im logging then capturing the cycles time in Home assistant. I’m trying to display an average cycle time based on the data recorded for the time th machine is turned on.

I’m generating a start time when the machine turns on but want the average code to use this start time to generate the daily average.

 - platform: average
   name: 'Average Cycle Time'
   start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
   end: '{{ now() }}'
   entities:
     - sensor.cycle_time

 - platform: history_stats
   type: time
   name : 2030 on Today
   entity_id: "binary_sensor.esphome_web_380dec_2030_ridat_status"
   state: "on"
   start: "{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}"
   end: "{{ now() }}"

This code only shows the complete day. Is there an easy way to use the 2030_on_today state to act as the average start time?

any help would be great as I’m abit lost as to where to start.

In developer tools → states, what is the state of sensor.2030_on_today?

The state is a number 3.37 and increases

So it is a duration, not a time. So no this is not possible:

Could I do it from a last triggered time? This is the sensor that triggers the duration.