Can Webcore totalize time a switch is on?


#1

1) Give a description of the problem
I don’t know where to start with this one, so there won’t be much beyond this section.

Say I have a switch that comes on intermittently over the course of a day. Can Webcore totalize the time that the switch has been on over a 24-hour period, and send a push notification with the total time that it’s been on?

For example:
Switch is on for 10 minutes from 08:09 to 08:19. It then comes on for 7 minutes from 15:30 to 15:37. Can Webcore somehow totalize the time on during that day and report at midnight that the switch had been on for 17 total minutes?

Thanks in advance for any sample code if this is possible.

2) What is the expected behavior?
(PUT YOUR INFO HERE)

3) What is happening/not happening?
(PUT YOUR INFO HERE)

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

Something like this?


#3

This is very interring to me. Looks like it will do exactly what was requested (with the additional time limit added in). I am curious on the logic. This implies that the trigger will get executed on any switch change and the on will go to the true and off to the false. Is this how WebCore works? I thought I had to look specifically for both the on and off.:thinking: I think I just learned something new and very useful. thanks. :grin:


#4

This is kind of what I was looking for, though I must admit I don’t quite know how it works…

After running for a few minutes, it’s showing a “totalOn” of 08:28:57. I’m guessing that’s 8 hours, 28 minutes, 57 seconds - which would be odd for a variable that just initialized.

I think it is incrementing the variable properly. I left the switch on for about a minute and the “totalOn” changed to 08:30:01, which is about a minute more than its previous reading.

I’m not sure the significance of the “timeLimit” being 600000, either. The switch I’m monitoring could be on for a minute, it could be on for hours, maybe even all day. Does this value impact the potential to log all of the time?


#5

I guess I also need a creative way to get the current cumulative time and/or post/push the day’s total cumulative time before it hits midnight, without needing to live log in the IDE. Thanks.


#6

I forgot about that time limit part, it was an example from a while back. I believe it was used for a robot vac that was only supposed to run for an hour a day but sometimes it is interrupted by other events that forces it to park itself.

Maybe this will work…


#7

Yes, but sometimes the else gets me in trouble if I don’t think the whole logic through lol.


#8

This version almost worked. It was tracking cumulative time perfectly throughout the day. At 10:06 PM the cumulative time on was 00:31:00 (31 minutes).

The switch never came back on, but at midnight, the cumulative time was logged as 02:31:53 (2 hours, 31 minutes, 53 seconds).

Not sure why, wondering if it’s a Smartthings glitch, or a timing issue with trying send the logged value and reset it at the same time.


#9

Hmm, that is strange. Did you have full logging on? That might help clue us on where things went funky.

I’m going to monitor one of if my switches here and try it out myself.


#10

I will try with full logging in Webcore today/tonight. Will post back results tomorrow.
Thanks.


#11

It is the else that is getting you. Because the if time happens every day at midnight trigger will execute the entire piston top to bottom, it is running the cumulative time portion of the code (since the switch is not changing to on). You can easily fix this by changing to an every day loop in which case only that section of the code will execute.

(See your post #7 above)


#12

I will try to change this to an every day at 12:00AM loop to see the difference. Thanks.


#13

I went ahead and modified the piston account for the off event, also added the midnight reset in case the switch is still on (haven’t tested that one)

Edit: I uploaded a new import code, the reset at midnight if the switch is still on didn’t work out right on my last version.


Trying to ensure HVAC fan runs for at least ten minutes every hour, but hourly conditionals not working
#14

just what I was looking for. Cheers!


#15

Another variant link: