Usage Per Hours Counter

Hi,

I have an aux generator works automatically when the power is cut, I installed esp current sensor that send current readings to HA,

Is there any way to calculate generator operating hours/day depending on the current meter? Such as when the readings above 0.5A a counter start to calculate the hours and rese every 24 hours