I’d like to calculate a daily average for an item. For example, how long has a light been ON every night between 8pm and midnight ?
The averageSince persistence extension computes an average since a point in time but I am looking for an interval average. Could you please tell me if there is a quick and easy way for retrieving my daily averages ?
Thank you for your help,
If nothing else works, I guess you could create a rule that triggers at the end of your interval (cron trigger) and then use .averageSince back to the start of your interval.
Thank you for your answer but I am a bit concerned about :
-The method to use for persisting the results of my daily calculations.
-Having to identify specifically what are the items I want to be able to compute afterward.
I am not sure I understand what you mean. Are you saying that you don’t know how to do the above? Or that you are concerned about having to do this?
Anyway, when I read your description in the top post again I think you will have to go about this in some other way.
If your item is a light switch (that can be either ON or OFF), using persistence and .averageSince will not give you information about how long it has been in a certain state (e.g. ON) over a period of time.
To do this I think you need to setup some rules.
One rule that triggers on “Item Switch changed to ON”. The rule should capture and store the current time in a variable (or another item).
One rule that triggers on “Item Switch changed to OFF”. The rule should subtract the capture time (see above) from the current time, and add this to yet another variabel (or item) that keeps your accumulated “ON time”.
The you will need another rule that triggers on the start of your interval (using cron) and resets (i.e. sets back to zero) the accumulated “ON time”.
And yet another rule that triggers on the end of your inteval (using cron) and stores and/or presents the accumulated “ON time” for the period in question.
Are we getting closer to what you want/need?
I am very grateful for the time you put in your answer. I was not trying to have it get it done by someone else
My first point was about how to persist the value but I suppose that I should use an item of type number.
However, I think the “rules solution” doesn’t fill my need right now as I want to be able to dynamically change my interval afterwards. Plus I’d like to do the sum for a bunch of items and I guess that all the needed rules will a big overhead to maintain for my “simple” need.
As I use a mysql persistence service, I think I will do an external script/sql query to extract the value in “real time”.
I am trying to find an alternative, and because I have no need for a really small granularity, I could be able to use .historicState to iterate in 5 minutes increments throughout all my interval and get a pretty decent value of the ON state time.
This could allow me to do the compute on the fly with different intervals each time.
@x02a did you find a solution? Would you mind to share it?