Summarize stateduration to have total "on" hours per day

HI @Lorenzo_Mao and welcome to the InfluxDB forum.

Instead of the stateDuration function, use elapsed(). Have a look at this post. You should be able to modify for your purposes.