GroveStreams
HSBSmartHome private msg quote post Address this user
I have a feed that shows when a light was turned on and turned off... could someone direct me to how I could calculate the duration that the light was on?
Post 1 IP   flag post
MikeMills private msg quote post Address this user
If you can pass the time in as a separate DATE stream, then you can create another derived stream that is derived from that stream's current sample time minus the previous sample time to get the number of milliseconds elapsed.
Post 2 IP   flag post
PigFarmer private msg quote post Address this user
I agree with MikeMills - I have similar issue in getting a time lapse stream and have it working pretty good.

If you could play around with a stream that is like an on off switch, a 1 (on) or 0 (off). Then another stream that gives you the time epoch of the event (light turning on or off either one. Then a third stream that says if switch == 0, time(0) - time(-1)

You could also play around with interval streams and gap filling to get the value. Hope that helps!
Post 3 IP   flag post
MikeMills private msg quote post Address this user
You can create a 2nd stream that is derived from SAMPLE_TIME of the feed stream too if you can't pass the sample time.
Post 4 IP   flag post
Avocadodude private msg quote post Address this user
Sorry to post to old thread, but I'm trying to figure this out. In my feed I'm sending the state (True, False) and time, do I need to send these as a separate post (one for state and one for time)?

samples.append({ 'compId': component_id, 'streamId' : 'pump', 'data' : pump_state, 'time' : sample_time })

I just can't figure out calculating the amount of time the pump was in a "True" state. The boolean state feed is good. So I'm trying to figure out if I need to create a derived stream of SAMPLE_TIME the another derived stream that is pump == 0, time(0) - time(-1).

Thanks for any help.
Post 5 IP   flag post
MikeMills private msg quote post Address this user
You don't have to pass the sample time anymore.

Create a derived stream that is derived from the state feed. The expression will just be SAMPLE_TIME. Or it might have to be:
SAMPLE_TIME//var1

I think you need to use the variable somewhere in the expression to save it so I just put it in a comment.

Then create a 2nd derived stream that is derived from the sample time stream with something like this:
if(isNull(LAST_VALUE), 0, (var1 - LAST_VALUE)/1000)

That will return seconds.
Post 6 IP   flag post
Avocadodude private msg quote post Address this user
Thanks Mike. I'll play around with the formula.
Post 7 IP   flag post
2965 7 7
Log in or sign up to compose a reply.