Stats of my ON/Off device

Hi, I’ve been looking for this for a while now … I know there is a lot of subject on that but I can’t do what I want and all the info I found is only part of what I need and I can’t put them together. (also real exemple could really help :laughing: )

Ok so I have a lot of ON/OFF device like light that I would like to have some stats on it like How many time Item X was ON today/last week/this month etc…

Then I would like to compare the info with a group if item. Ex: lets said I have Item1 Item2 and Item3, I want to know witch one is more use

etc… I would like to have A LOT of stats ! Average, Percent, Not use since

P.s I’m using Mysql Persistence