Page 1 of 1

Retrieve and average past values of variables

PostPosted: Thu May 03, 2018 7:13 am
by bluehouse
Is it possible to retrieve and average say, the last 5 stored values of a variable? For instance, I want to compare the most recent period between sump cycles with an average of the last few and alert me if it’s overdue. (Sump failure: the whole reason I started down the home automation path; now I have a whole house full of fun!)

I could do it by storing each of the five most recent in separate variables and updating all of them each cycle but wondered if there was a more elegant & efficient way to do it?

Thanks for any thoughts!


Sent from my iPhone using Tapatalk

Re: Retrieve and average past values of variables

PostPosted: Thu May 03, 2018 10:37 am
by kw123
thats roughly it, you could use one complicated variable ( with json)

indigo does NOT offer averages etc. you could also use sql retrieval from the last events, but that requires some programing
Indigo utilities has a menu and action that retrieves the last xx values of a device/state, but does not do averages.

Karl

Re: Retrieve and average past values of variables

PostPosted: Fri May 04, 2018 7:36 am
by Colorado4Wheeler
The way I handle this (and it's something I've written into Device Extensions if I ever get time to finish the updates and release it) is to stash the variable into a single variable in JSON format so you can extract it easily. That way you can stash as many days worth of variables as you want in one called, for instance, "DailyValues" and use json.dumps and json.get to store or use them.

Re: Retrieve and average past values of variables

PostPosted: Sat May 05, 2018 5:52 pm
by bluehouse
Thanks guys. I’ll take a look at options you suggested when I’m back at my computer.


Sent from my iPhone using Tapatalk