val numberOns = MyLight.sumSince(now.minusHours(1))
Will give the total number of times the value 1 (i.e. ON) appears in the database for the past hour. What that means though depends on how you have configured your persistence. For example, if you are saving the value every minute then it would be the number of minutes over the past hour that the Light was ON. But if you store every update it means that the light was updated with ON that many times over the past hour which may be meaningless.
There is no way to count the zeros (i.e. OFFs).
Ultimately you will probably have to write rules to keep track of the count that way.
You would need the JSONPATH transformation service instaled for this. You may wonder why I’m dividing by two… for items of OnOffType, the REST API will add in an additional state for each change to improve charting. If you look at the data, before every ON you’ll see an extra OFF, and vice-versa.
And as @rlkoshak pointed out, this would only work correctly if you are persistence strategy is everyChange.