Simple on/off based on time, if device is off


#1

1) Give a description of the problem
When turning on or off the switch manually during or outside of the “on” timeframe the switch will constantly cycle on/off… My goal is to have an outlet controlled by this piston and have it “correct” itself in the event of a power outage when it’s supposed to be on/off. ie: power comes back on, piston checks time, sets the switch accordingly if it needs to be changed. I’m sure there’s a better way to do this.

2) What is the expected behaviour?
If the device is on during timeframe, and I turn it off, I want it to simply turn back on within 10 seconds of it being off. If it is off outside of this timeframe and I turn it on manually, I want it to turn itself off again within 10 seconds.

3) What is happening/not happening?
The outlet powers on and off repeatedly. Before adding the 10 second wait it would do it repeatedly without a pause on/off/on/off/on/off.

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full

7/28/2020, 12:43:01 PM +922ms
+107ms	╔Stopping piston...
+181ms	╚Piston successfully stopped (75ms)
7/28/2020, 12:42:57 PM +622ms
+1ms	╔Received event [Outlet 2].switch = on with a delay of 49ms
+112ms	║RunTime Analysis CS > 21ms > PS > 54ms > PE > 38ms > CE
+115ms	║Runtime (37478 bytes) successfully initialized in 54ms (v0.3.110.20191009) (112ms)
+116ms	║╔Execution stage started
+123ms	║║Comparison (enum) on is_not (string) on = false (1ms)
+124ms	║║Cancelling condition #7's schedules...
+125ms	║║Condition #7 evaluated false (6ms)
+126ms	║║Cancelling condition #1's schedules...
+127ms	║║Condition group #1 evaluated false (state changed) (8ms)
+129ms	║║Cancelling statement #3's schedules...
+134ms	║║Executed virtual command [Outlet 2].wait (0ms)
+135ms	║║Requesting a wake up for Tue, Jul 28 2020 @ 12:43:07 PM PDT (in 10.0s)
+139ms	║╚Execution stage complete. (24ms)
+141ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 12:43:07 PM PDT (in 9.995s), with 1 more job pending
+250ms	╚Event processed successfully (249ms)
7/28/2020, 12:42:57 PM +40ms
+1ms	╔Received event [Home].time = 1595965378749 with a delay of -1709ms
+105ms	║RunTime Analysis CS > 19ms > PS > 54ms > PE > 32ms > CE
+108ms	║Runtime (37486 bytes) successfully initialized in 54ms (v0.3.110.20191009) (105ms)
+109ms	║╔Execution stage started
+290ms	║║Executed physical command [Outlet 2].on() (170ms)
+291ms	║║Executed [Outlet 2].on (172ms)
+294ms	║╚Execution stage complete. (186ms)
+296ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 9:00:00 PM PDT (in 29822.665s)
+315ms	╚Event processed successfully (315ms)
7/28/2020, 12:42:48 PM +596ms
+2ms	╔Received event [Outlet 2].switch = off with a delay of 53ms
+111ms	║RunTime Analysis CS > 21ms > PS > 53ms > PE > 36ms > CE
+113ms	║Runtime (37483 bytes) successfully initialized in 53ms (v0.3.110.20191009) (111ms)
+114ms	║╔Execution stage started
+122ms	║║Comparison (enum) off is_not (string) on = true (2ms)
+123ms	║║Cancelling condition #7's schedules...
+124ms	║║Condition #7 evaluated true (6ms)
+133ms	║║Comparison (time) 45768721 is_between (time) 21600000 .. (time) 75600000 = true (6ms)
+134ms	║║Time restriction check passed
+136ms	║║Condition #8 evaluated true (11ms)
+137ms	║║Cancelling statement #8's schedules...
+141ms	║║Requesting time schedule wake up at Tue, Jul 28 2020 @ 9:00:00 PM PDT
+143ms	║║Cancelling condition #1's schedules...
+144ms	║║Condition group #1 evaluated true (state changed) (26ms)
+146ms	║║Cancelling statement #5's schedules...
+151ms	║║Executed virtual command [Outlet 2].wait (1ms)
+152ms	║║Requesting a wake up for Tue, Jul 28 2020 @ 12:42:58 PM PDT (in 10.0s)
+156ms	║╚Execution stage complete. (42ms)
+158ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 12:42:58 PM PDT (in 9.996s), with 1 more job pending
+176ms	╚Event processed successfully (176ms)
7/28/2020, 12:42:48 PM +64ms
+0ms	╔Received event [Home].time = 1595965369947 with a delay of -1884ms
+119ms	║RunTime Analysis CS > 28ms > PS > 60ms > PE > 32ms > CE
+122ms	║Runtime (37490 bytes) successfully initialized in 60ms (v0.3.110.20191009) (121ms)
+123ms	║╔Execution stage started
+286ms	║║Executed physical command [Outlet 2].off() (149ms)
+287ms	║║Executed [Outlet 2].off (151ms)
+290ms	║╚Execution stage complete. (168ms)
+292ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 9:00:00 PM PDT (in 29831.645s)
+315ms	╚Event processed successfully (315ms)
7/28/2020, 12:42:39 PM +815ms
+1ms	╔Received event [Outlet 2].switch = on with a delay of 52ms
+108ms	║RunTime Analysis CS > 20ms > PS > 52ms > PE > 36ms > CE
+110ms	║Runtime (37478 bytes) successfully initialized in 52ms (v0.3.110.20191009) (108ms)
+111ms	║╔Execution stage started
+119ms	║║Comparison (enum) on is_not (string) on = false (2ms)
+120ms	║║Cancelling condition #7's schedules...
+121ms	║║Condition #7 evaluated false (6ms)
+122ms	║║Cancelling condition #1's schedules...
+123ms	║║Condition group #1 evaluated false (state changed) (8ms)
+125ms	║║Cancelling statement #3's schedules...
+130ms	║║Executed virtual command [Outlet 2].wait (0ms)
+131ms	║║Requesting a wake up for Tue, Jul 28 2020 @ 12:42:49 PM PDT (in 10.0s)
+135ms	║╚Execution stage complete. (24ms)
+137ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 12:42:49 PM PDT (in 9.996s), with 1 more job pending
+155ms	╚Event processed successfully (155ms)
7/28/2020, 12:42:39 PM +56ms
+0ms	╔Received event [Home].time = 1595965360787 with a delay of -1732ms
+108ms	║RunTime Analysis CS > 20ms > PS > 57ms > PE > 32ms > CE
+110ms	║Runtime (37486 bytes) successfully initialized in 57ms (v0.3.110.20191009) (109ms)
+111ms	║╔Execution stage started
+468ms	║║Executed physical command [Outlet 2].on() (333ms)
+469ms	║║Executed [Outlet 2].on (335ms)
+471ms	║╚Execution stage complete. (360ms)
+473ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 9:00:00 PM PDT (in 29840.472s)
+489ms	╚Event processed successfully (488ms)
7/28/2020, 12:42:30 PM +624ms
+2ms	╔Received event [Outlet 2].switch = off with a delay of 55ms
+117ms	║RunTime Analysis CS > 24ms > PS > 58ms > PE > 35ms > CE
+120ms	║Runtime (37483 bytes) successfully initialized in 58ms (v0.3.110.20191009) (117ms)
+121ms	║╔Execution stage started
+129ms	║║Comparison (enum) off is_not (string) on = true (1ms)
+131ms	║║Cancelling condition #7's schedules...
+132ms	║║Condition #7 evaluated true (7ms)
+142ms	║║Comparison (time) 45750757 is_between (time) 21600000 .. (time) 75600000 = true (6ms)
+143ms	║║Time restriction check passed
+145ms	║║Condition #8 evaluated true (11ms)
+146ms	║║Cancelling statement #8's schedules...
+150ms	║║Requesting time schedule wake up at Tue, Jul 28 2020 @ 9:00:00 PM PDT
+153ms	║║Cancelling condition #1's schedules...
+154ms	║║Condition group #1 evaluated true (state changed) (28ms)
+156ms	║║Cancelling statement #5's schedules...
+161ms	║║Executed virtual command [Outlet 2].wait (0ms)
+162ms	║║Requesting a wake up for Tue, Jul 28 2020 @ 12:42:40 PM PDT (in 10.0s)
+167ms	║╚Execution stage complete. (45ms)
+168ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 12:42:40 PM PDT (in 9.995s), with 1 more job pending
+197ms	╚Event processed successfully (197ms)
7/28/2020, 12:42:30 PM +155ms
+1ms	╔Received event [Home].time = 1595965351824 with a delay of -1669ms
+113ms	║RunTime Analysis CS > 19ms > PS > 63ms > PE > 31ms > CE
+116ms	║Runtime (37490 bytes) successfully initialized in 63ms (v0.3.110.20191009) (115ms)
+117ms	║╔Execution stage started
+178ms	║║Executed physical command [Outlet 2].off() (46ms)
+179ms	║║Executed [Outlet 2].off (48ms)
+182ms	║╚Execution stage complete. (65ms)
+183ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 9:00:00 PM PDT (in 29849.662s)
+217ms	╚Event processed successfully (217ms)
7/28/2020, 12:42:21 PM +693ms
+1ms	╔Received event [Outlet 2].switch = on with a delay of 51ms
+108ms	║RunTime Analysis CS > 20ms > PS > 55ms > PE > 33ms > CE
+111ms	║Runtime (37478 bytes) successfully initialized in 55ms (v0.3.110.20191009) (108ms)
+112ms	║╔Execution stage started
+119ms	║║Comparison (enum) on is_not (string) on = false (1ms)
+120ms	║║Cancelling condition #7's schedules...
+121ms	║║Condition #7 evaluated false (5ms)
+122ms	║║Cancelling condition #1's schedules...
+123ms	║║Condition group #1 evaluated false (state changed) (8ms)
+125ms	║║Cancelling statement #3's schedules...
+130ms	║║Executed virtual command [Outlet 2].wait (0ms)
+131ms	║║Requesting a wake up for Tue, Jul 28 2020 @ 12:42:31 PM PDT (in 10.0s)
+135ms	║╚Execution stage complete. (24ms)
+137ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 12:42:31 PM PDT (in 9.995s), with 1 more job pending
+150ms	╚Event processed successfully (149ms)
7/28/2020, 12:42:21 PM +228ms
+1ms	╔Received event [Home].time = 1595965342969 with a delay of -1741ms
+127ms	║RunTime Analysis CS > 22ms > PS > 76ms > PE > 29ms > CE
+130ms	║Runtime (37486 bytes) successfully initialized in 76ms (v0.3.110.20191009) (127ms)
+131ms	║╔Execution stage started
+166ms	║║Executed physical command [Outlet 2].on() (23ms)
+167ms	║║Executed [Outlet 2].on (26ms)
+169ms	║╚Execution stage complete. (39ms)
+171ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 9:00:00 PM PDT (in 29858.602s)
+179ms	╚Event processed successfully (179ms)
7/28/2020, 12:42:12 PM +813ms
+1ms	╔Received event [Outlet 2].switch = off with a delay of 55ms
+113ms	║RunTime Analysis CS > 19ms > PS > 54ms > PE > 40ms > CE
+116ms	║Runtime (37483 bytes) successfully initialized in 54ms (v0.3.110.20191009) (113ms)
+117ms	║╔Execution stage started
+125ms	║║Comparison (enum) off is_not (string) on = true (1ms)
+126ms	║║Cancelling condition #7's schedules...
+127ms	║║Condition #7 evaluated true (6ms)
+137ms	║║Comparison (time) 45732941 is_between (time) 21600000 .. (time) 75600000 = true (6ms)
+138ms	║║Time restriction check passed
+139ms	║║Condition #8 evaluated true (11ms)
+140ms	║║Cancelling statement #8's schedules...
+145ms	║║Requesting time schedule wake up at Tue, Jul 28 2020 @ 9:00:00 PM PDT
+147ms	║║Cancelling condition #1's schedules...
+148ms	║║Condition group #1 evaluated true (state changed) (27ms)
+150ms	║║Cancelling statement #5's schedules...
+155ms	║║Executed virtual command [Outlet 2].wait (0ms)
+156ms	║║Requesting a wake up for Tue, Jul 28 2020 @ 12:42:22 PM PDT (in 10.0s)
+160ms	║╚Execution stage complete. (44ms)
+162ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 12:42:22 PM PDT (in 9.995s), with 1 more job pending
+195ms	╚Event processed successfully (195ms)
7/28/2020, 12:40:35 PM +631ms
+1ms	╔Starting piston... (v0.3.110.20191009)
+289ms	║╔Subscribing to devices...
+319ms	║║Subscribing to Outlet 2.switch...
+400ms	║╚Finished subscribing (116ms)
+425ms	║Comparison (enum) on is_not (string) on = false (2ms)
+437ms	║Comparison (time) 45636058 is_between (time) 21600000 .. (time) 75600000 = true (8ms)
+438ms	║Time restriction check passed
+442ms	║Cancelling statement #8's schedules...
+447ms	║Requesting time schedule wake up at Tue, Jul 28 2020 @ 9:00:00 PM PDT
+466ms	║Setting up scheduled job for Tue, Jul 28 2020 @ 9:00:00 PM PDT (in 29963.903s)
+491ms	╚Piston successfully started (491ms)

#2

Well, you have to realize any change in the switch will trigger the piston. So, say you turn it off (In the on timeframe), that will trigger the piston, see the switch is off and time is correct and turn it back on. Then, because the switch changed status, the piston will run again. Now it will find it is on so the condition will fail and go to the else which turns the switch back off. That will trigger the piston again…

So it is doing what you programmed. I assume you just want to be sure the light is on during your set timeframe and off otherwise. I would suggest keeping it simple:

If outlet 2's switch changes
then
  if time is between 6 Am and 9 PM
     turn on
  else
     turn off
  end if
end if

Webcore is smart enough not to send a repeated on command if it is already on of repeated off if already off. And this will never turn off during the on timeframe or vice versa.


#3

That’s how I had it originally, but didn’t think it would ensure that it was of or on after direct intervention.

The weird thing is, it catches up and figures itself out. Like right now the switch is currently on, after all that back and forth cycling.

Thanks for the advice. Fresh convert from CoRE and so far very impressed.

Also, I didn’t notice “changes” was an option. I like that, much more logical.


#4

WebCoRE doesn’t really care whether it is turning something on or off or it is happening manually. It will react the same so this will always do what you want.

What this doesn’t do is actually change the switch when the time changes from inside your range to outside or vice versa. For that, you might want to add a timer in this or another piston. Otherwise, you will have to switch it on every morning and off at night.


#5

That’s kinda what I was attempting. As of now, running the modified version you suggested it doesn’t do anything after turning it off manually (when it should be on). I have this functionality with a basic timer switch, so was trying to be a little more fancy with SmartThings, sorta to get my feet wet.

For my own info, this is how you meant right?


#6

No, this is not quite right. You need to split the time check into separate internal if statement. For some reason my green snapshot is not working right but the structure should look like this.

Note that he nice thing about ‘every’ in this case is it will only run what is inside that statement at the designated time and will not run the rest of the piston. Also, when the rest of the piston runs, it will not run what is in the ‘every’ statement.


#7

This still isn’t working as intended. Based on the “if X switches” trigger, I would expect it to trigger if I manually turn that switch off during the timeframe. Currently that is not happening.

However, when I go into my Smartthings classic app, it’s saying I’m having internet issues (not the case). Not sure if related, since I can still control the switch with google home/alexa.


#8

Piston looks good. Is smartthings reporting the change in the switch? WebCoRE can’t react if SmartThings doesn’t report. It is strange that it would not react otherwise. I suggest waiting until your SmartThings connection issues are resolved before testing any further as your results won’t be reliable.


#9

Edit:

nm,
we good.

:man_facepalming:, had it paused from the previous troubleshooting. I’ll report back if I have other issues.


#10

Thank you for all your help!