Auto front porch light with Ring doorbell


#1

1) Give a description of the problem
Designing a piston that turns on front porch light when Ring doorbell is pressed once, sends a notification, waits for 10 minutes, then front porch light auto turns off. If Ring doorbell is pressed a second time, turns on the front porch light and stays on indefinitely until manually turned off

2) What is the expected behavior?

3) What is happening/not happening?
Not able to code for the second pushed mode

Could someone see how I would code for the second part (Regarding the second doorbell push)? I don’t think my logic is correct using the variables. Also is using {$time} correct in the notification if I want it to send a message of what time the doorbell was pushed? I’m pretty new to using webcore. Thank you!


#2

This is an interesting one… It’s going to require some lesser used features of WC to make this one happen.

I will say that what you have so far isn’t going to work though… Because right now you’re not at all differentiating between a single button press on Monday followed by a single button press on Tuesday versus two button presses within 5 minutes of each other.

So I think you need to base your decision on whether or not to turn off the light using Time rather than an Integer. So if you get 2 button presses within X minutes, then leave the light on. But if the two button presses are hours apart then just follow the normal pattern.

Let me look through some examples and I’ll see what I can dig up for you on this one…


#3

I think you have to tackle it something like this…

Using the time when the button was last pushed to determine whether or not it was within the time frame you decide to tell if it’s the first push or the second push. Right now this is configured for 10 minutes, that’s the 600000 part.

I believe the Cancel all pending tasks part should cancel the wait command and the Turn off command in case someone pushes the doorbell again during the 10 minutes when the piston is waiting.

I’ve not tested that part though…

Oh…change the restriction (Time is any) back to your times. I just made it that way for testing.


#4

Thanks for the design code :), I tried it tonight, and it seems that the double push of the button works (the light stays on). However, the single push does not work (it won’t turn off automatically). Below are the logs. Any suggestions?

Btw, what is the 60000 unit means? 60000 ms? and is that the interval between the two button pushes before the piston starts over?

2/16/2018, 11:13:53 PM +200ms
+1ms â•”Received event [Front Doorbell].button = default with a delay of 79ms
+85ms â•‘RunTime Analysis CS > 11ms > PS > 50ms > PE > 24ms > CE
+87ms â•‘Runtime (39770 bytes) successfully initialized in 50ms (v0.2.102.20180116) (85ms)
+88ms â•‘â•”Execution stage started
+115ms ║║Comparison (time) 83633293 is_between (time) 1518831360000 … (time) 18000000 = true (6ms)
+115ms â•‘â•‘Time restriction check passed
+117ms â•‘â•‘Condition #24 evaluated true (25ms)
+118ms â•‘â•‘Condition group #1 evaluated true (state did not change) (25ms)
+123ms â•‘â•‘Comparison (enum) default gets (string) pushed = false (0ms)
+124ms ║║Cancelling condition #15’s schedules…
+124ms â•‘â•‘Condition #15 evaluated false (6ms)
+125ms ║║Cancelling condition #1’s schedules…
+126ms â•‘â•‘Condition group #1 evaluated false (state changed) (8ms)
+128ms â•‘â•šExecution stage complete. (40ms)
+129ms â•šEvent processed successfully (129ms)


#5

It’s odd. From what you’ve posted the logs show that the “button push” event did not come in as a button push but rather as an event named “default”.

Is that the case all the time? Do the logs always show “default” instead of “pushed”? That seems strange to me.

It’s actually 600,000 milliseconds. I’m using that as an arbitrary value for identifying the “second push” of the button. So if the button was pushed less than 10 minutes ago (60 * 1000 * 10) then treat that as the second push. If it’s been longer than that then treat it as the first push. You can make that value whatever you want.

So the piston reads like this…

If the doorbell was last pushed more than 10 minutes ago
Then treat that as the first push of the doorbell and setup the wait timer to turn it off 10 minutes in the future
Otherwise, treat it as the second push of the doorbell and then
Cancel the wait timer which would turn off the light
And for good measure make sure the light is on (which really it should be anyway, unless you changed the age part to say 15 minutes instead of 10).

So what I don’t get is why the logs show button default instead of button pushed. That’s why nothing happened in the logs that you posted. Not sure why the light would have turned on at all.

Did you take out the Log statements I put in the piston? I had those there to help with the testing on this one. Might want to put them back to help trace this one out a bit better.


#6

Just did another test, this time, I put 10000 ms and waited 1 minute to see if it’ll auto turn off or not, and it doesn’t. The light does turn on with the first push though.

This is the full logs I have, I did not delete any debugs or modified anything except those variables mentioned above. I checked the config for the button being pushed. It reads “Any” “button” of the device:doorbell “gets” “pushed.”

2/17/2018, 4:54:39 PM +348ms
+1ms â•”Received event [Front Doorbell].button = default with a delay of 185ms
+80ms â•‘RunTime Analysis CS > 11ms > PS > 34ms > PE > 34ms > CE
+82ms â•‘Runtime (39765 bytes) successfully initialized in 34ms (v0.2.102.20180116) (80ms)
+83ms â•‘â•”Execution stage started
+95ms â•‘â•‘Comparison (time) 60879437 is_any = true (5ms)
+96ms â•‘â•‘Time restriction check passed
+97ms â•‘â•‘Condition #24 evaluated true (8ms)
+98ms â•‘â•‘Condition group #1 evaluated true (state did not change) (10ms)
+104ms â•‘â•‘Comparison (enum) default gets (string) pushed = false (1ms)
+105ms ║║Cancelling condition #15’s schedules…
+106ms â•‘â•‘Condition #15 evaluated false (7ms)
+107ms ║║Cancelling condition #1’s schedules…
+108ms â•‘â•‘Condition group #1 evaluated false (state changed) (9ms)
+110ms â•‘â•šExecution stage complete. (27ms)
+111ms â•šEvent processed successfully (111ms)
2/17/2018, 4:54:09 PM +754ms
+2ms â•”Received event [Front Doorbell].button = pushed with a delay of 92ms
+115ms â•‘RunTime Analysis CS > 18ms > PS > 59ms > PE > 38ms > CE
+117ms â•‘Runtime (39774 bytes) successfully initialized in 59ms (v0.2.102.20180116) (114ms)
+118ms â•‘â•”Execution stage started
+128ms â•‘â•‘Comparison (time) 60849877 is_any = true (4ms)
+129ms â•‘â•‘Time restriction check passed
+130ms â•‘â•‘Condition #24 evaluated true (7ms)
+131ms ║║Cancelling condition #1’s schedules…
+132ms â•‘â•‘Condition group #1 evaluated true (state changed) (9ms)
+137ms â•‘â•‘Comparison (enum) pushed gets (string) pushed = true (1ms)
+138ms ║║Cancelling condition #15’s schedules…
+139ms â•‘â•‘Condition #15 evaluated true (6ms)
+139ms â•‘â•‘Condition group #1 evaluated true (state did not change) (7ms)
+141ms ║║Cancelling statement #16’s schedules…
+151ms â•‘â•‘241
+152ms â•‘â•‘Executed virtual command log (1ms)
+163ms â•‘â•‘Comparison (long) 252 is_greater_than (integer) 10000 = false (1ms)
+164ms ║║Cancelling condition #23’s schedules…
+165ms â•‘â•‘Condition #23 evaluated false (10ms)
+165ms ║║Cancelling condition #19’s schedules…
+166ms â•‘â•‘Condition group #19 evaluated false (state changed) (12ms)
+168ms ║║Cancelling statement #2’s schedules…
+172ms â•‘â•‘Executed virtual command [Front Porch].cancelTasks (0ms)
+178ms ║║Second button push within the window…
+178ms â•‘â•‘Executed virtual command [Front Porch].log (1ms)
+198ms â•‘â•‘Executed physical command [Front Porch].on() (18ms)
+199ms â•‘â•‘Executed [Front Porch].on (20ms)
+205ms â•‘â•šExecution stage complete. (87ms)
+206ms â•šEvent processed successfully (206ms)


#7

Hah… As I was typing up this reply I realized the mistake that I made in this piston Thanks for posting those logs…a light bulb did go on…the one in my head.

Let me make you something that will work…because this one never will. I feel silly. :slight_smile:

I’ll explain later…in case you don’t see the error also.


#8

Alright, this should work. The last one was flawed as the Age of the event “button pushed” was always going to only contain the value for the current event…doh…and not the previous event. I believe there may be a value for PreviousAge, but we’ll just keep track of time ourselves on this one and be done with it.

I added a few more debug statements so that you can tweak the values to your liking.

The comparison right now is set for only 1 minute (60000 * 1) so if you want that longer just adjust that value there. Also adjust your wait time for turning off the light as needed.

Just know, if you make the wait time too long (for WC) then you’ll likely need to change that with part to “Never Cancel” so that the lights do turn off at the end of the wait…but then that could get interesting with the part where we tell it to cancel all pending tasks… Hmm…I wonder how those would interact. Hopefully we don’t need to find out…


#9

Still doesn’t work? The front porch turns on with the button, but continue to stays on. Below are the full logs. I have not changed any variables in your code.

2/18/2018, 6:52:31 PM +310ms
+1ms â•”Received event [Front Doorbell].button = default with a delay of 136ms
+202ms â•‘RunTime Analysis CS > 11ms > PS > 165ms > PE > 26ms > CE
+205ms â•‘Runtime (41221 bytes) successfully initialized in 165ms (v0.2.102.20180116) (203ms)
+206ms â•‘â•”Execution stage started
+234ms ║║Comparison (time) 67951521 is_between (time) 1519004280000 … (time) 1518964320000 = true (7ms)
+235ms â•‘â•‘Time restriction check passed
+237ms â•‘â•‘Condition #24 evaluated true (26ms)
+237ms â•‘â•‘Condition group #1 evaluated true (state did not change) (27ms)
+243ms â•‘â•‘Comparison (enum) default gets (string) pushed = false (1ms)
+244ms ║║Cancelling condition #15’s schedules…
+245ms â•‘â•‘Condition #15 evaluated false (7ms)
+246ms ║║Cancelling condition #1’s schedules…
+247ms â•‘â•‘Condition group #1 evaluated false (state changed) (8ms)
+249ms â•‘â•šExecution stage complete. (43ms)
+250ms â•šEvent processed successfully (249ms)
2/18/2018, 6:52:01 PM +128ms
+2ms â•”Received event [Front Doorbell].button = pushed with a delay of 101ms
+97ms â•‘RunTime Analysis CS > 15ms > PS > 49ms > PE > 33ms > CE
+99ms â•‘Runtime (41198 bytes) successfully initialized in 49ms (v0.2.102.20180116) (97ms)
+100ms â•‘â•”Execution stage started
+131ms ║║Comparison (time) 67921234 is_between (time) 1519004280000 … (time) 1518964320000 = true (7ms)
+132ms â•‘â•‘Time restriction check passed
+134ms â•‘â•‘Condition #24 evaluated true (29ms)
+135ms ║║Cancelling condition #1’s schedules…
+135ms â•‘â•‘Condition group #1 evaluated true (state changed) (30ms)
+141ms â•‘â•‘Comparison (enum) pushed gets (string) pushed = true (1ms)
+143ms ║║Cancelling condition #15’s schedules…
+143ms â•‘â•‘Condition #15 evaluated true (7ms)
+144ms â•‘â•‘Condition group #1 evaluated true (state did not change) (8ms)
+146ms ║║Cancelling statement #16’s schedules…
+154ms â•‘â•‘Calculating (datetime) 1519008721279 - (datetime) 1519008721225 >> (datetime) 54
+158ms â•‘â•‘Calculating (string) Elapsed time since doorbell was last pushed: + (string) 00:00:00 >> (string) Elapsed time since doorbell was last pushed: 00:00:00
+161ms â•‘â•‘Elapsed time since doorbell was last pushed: 00:00:00
+162ms â•‘â•‘Executed virtual command log (1ms)
+170ms â•‘â•‘Calculating (datetime) 1519008721295 - (datetime) 1519008721225 >> (datetime) 70
+173ms â•‘â•‘Calculating (string) Raw value (in ms): + (string) 70 >> (string) Raw value (in ms): 70
+177ms â•‘â•‘Raw value (in ms): 70
+177ms â•‘â•‘Executed virtual command log (1ms)
+185ms â•‘â•‘Calculating (datetime) 1519008721309 - (datetime) 1519008721225 >> (datetime) 84
+189ms â•‘â•‘Calculating (integer) 60000 * (integer) 1 >> (integer) 60000
+192ms â•‘â•‘Comparison (datetime) 84 is_greater_than (integer) 60000 = false (1ms)
+194ms â•‘â•‘Condition #23 evaluated false (13ms)
+194ms â•‘â•‘Condition group #19 evaluated false (state did not change) (14ms)
+197ms ║║Cancelling statement #2’s schedules…
+206ms â•‘â•‘Executed virtual command [Front Porch].setVariable (3ms)
+207ms â•‘â•‘Executed virtual command [Front Porch].cancelTasks (0ms)
+213ms ║║Second button push within the window…
+214ms â•‘â•‘Executed virtual command [Front Porch].log (1ms)
+239ms â•‘â•‘Executed physical command [Front Porch].on() (24ms)
+240ms â•‘â•‘Executed [Front Porch].on (25ms)
+243ms â•‘â•šExecution stage complete. (143ms)
+244ms â•šEvent processed successfully (244ms)
2/18/2018, 6:50:22 PM +893ms
+1ms ╔Starting piston… (v0.2.102.20180116)
+310ms ║╔Subscribing to devices…
+335ms ║║Subscribing to Front Doorbell.button…
+410ms ║║Subscribing to Front Porch…
+411ms â•‘â•šFinished subscribing (112ms)
+473ms ║Comparison (time) 67823326 is_between (time) 1519004280000 … (time) 1518964320000 = true (12ms)
+474ms â•‘Time restriction check passed
+476ms ║Cancelling condition #24’s schedules…
+477ms ║Cancelling condition #1’s schedules…
+486ms ║Cancelling condition #1’s schedules…
+497ms â•‘Calculating (datetime) 1519008623385 - (datetime) 1519008623189 >> (datetime) 196
+502ms â•‘Calculating (integer) 60000 * (integer) 1 >> (integer) 60000
+508ms â•‘Comparison (datetime) 196 is_greater_than (integer) 60000 = false (4ms)
+546ms â•šPiston successfully started (546ms)


#10

That could just be from the system initiating the value in the LastPush variable for the first time.

It’s still thinking it’s the second press of the button.

So…wait a few minutes and try it again.

Also make sure a valid value is stored in the piston for the variable LastPush.


#11

I’ve only pressed it once, but let me try it again tonight when I return from work. I just tried it again. Here’s the full logs. Still does not turn off automatically from 1 button pushed.

2/19/2018, 9:01:09 PM +346ms
+0ms â•”Received event time = 1519102870143 with a delay of -798ms
+134ms â•‘RunTime Analysis CS > 28ms > PS > 56ms > PE > 50ms > CE
+137ms â•‘Runtime (41210 bytes) successfully initialized in 56ms (v0.2.102.20180116) (135ms)
+139ms â•‘â•”Execution stage started
+140ms â•‘â•šExecution stage complete. (2ms)
+141ms â•šEvent processed successfully (141ms)
2/19/2018, 9:00:39 PM +204ms
+2ms â•”Received event [Front Doorbell].button = default with a delay of 75ms
+108ms â•‘RunTime Analysis CS > 23ms > PS > 51ms > PE > 34ms > CE
+111ms â•‘Runtime (41202 bytes) successfully initialized in 51ms (v0.2.102.20180116) (107ms)
+111ms â•‘â•”Execution stage started
+121ms â•‘â•‘Comparison (time) 75639320 is_any = true (5ms)
+122ms â•‘â•‘Time restriction check passed
+123ms â•‘â•‘Condition #24 evaluated true (7ms)
+123ms â•‘â•‘Condition group #1 evaluated true (state did not change) (8ms)
+128ms â•‘â•‘Comparison (enum) default gets (string) pushed = false (0ms)
+129ms ║║Cancelling condition #15’s schedules…
+129ms â•‘â•‘Condition #15 evaluated false (5ms)
+130ms ║║Cancelling condition #1’s schedules…
+131ms â•‘â•‘Condition group #1 evaluated false (state changed) (6ms)
+133ms â•‘â•šExecution stage complete. (21ms)
+133ms â•šEvent processed successfully (133ms)
2/19/2018, 9:00:09 PM +956ms
+1ms â•”Received event [Front Doorbell].button = pushed with a delay of 54ms
+76ms â•‘RunTime Analysis CS > 15ms > PS > 29ms > PE > 31ms > CE
+78ms â•‘Runtime (41206 bytes) successfully initialized in 29ms (v0.2.102.20180116) (76ms)
+79ms â•‘â•”Execution stage started
+89ms â•‘â•‘Comparison (time) 75610039 is_any = true (5ms)
+90ms â•‘â•‘Time restriction check passed
+91ms â•‘â•‘Condition #24 evaluated true (7ms)
+91ms ║║Cancelling condition #1’s schedules…
+92ms â•‘â•‘Condition group #1 evaluated true (state changed) (9ms)
+103ms â•‘â•‘Comparison (enum) pushed gets (string) pushed = true (4ms)
+104ms ║║Cancelling condition #15’s schedules…
+105ms â•‘â•‘Condition #15 evaluated true (12ms)
+106ms â•‘â•‘Condition group #1 evaluated true (state did not change) (14ms)
+107ms ║║Cancelling statement #16’s schedules…
+117ms â•‘â•‘Calculating (datetime) 1519102810070 - (datetime) 1519008721328 >> (datetime) 94088742
+120ms â•‘â•‘Calculating (string) Elapsed time since doorbell was last pushed: + (string) 1d 02:08:08 >> (string) Elapsed time since doorbell was last pushed: 1d 02:08:08
+123ms â•‘â•‘Elapsed time since doorbell was last pushed: 1d 02:08:08
+123ms â•‘â•‘Executed virtual command log (1ms)
+130ms â•‘â•‘Calculating (datetime) 1519102810083 - (datetime) 1519008721328 >> (datetime) 94088755
+132ms â•‘â•‘Calculating (string) Raw value (in ms): + (string) 94088755 >> (string) Raw value (in ms): 94088755
+136ms â•‘â•‘Raw value (in ms): 94088755
+136ms â•‘â•‘Executed virtual command log (1ms)
+142ms â•‘â•‘Calculating (datetime) 1519102810095 - (datetime) 1519008721328 >> (datetime) 94088767
+145ms â•‘â•‘Calculating (integer) 60000 * (integer) 1 >> (integer) 60000
+147ms â•‘â•‘Comparison (datetime) 94088767 is_greater_than (integer) 60000 = true (1ms)
+148ms â•‘â•‘Condition #23 evaluated true (10ms)
+149ms â•‘â•‘Condition group #19 evaluated true (state did not change) (11ms)
+151ms ║║Cancelling statement #21’s schedules…
+158ms â•‘â•‘Executed virtual command [Front Porch].setVariable (3ms)
+177ms â•‘â•‘Executed physical command [Front Porch].on() (18ms)
+178ms â•‘â•‘Executed [Front Porch].on (19ms)
+183ms ║║First button push…
+183ms â•‘â•‘Executed virtual command [Front Porch].log (1ms)
+186ms â•‘â•‘Executed virtual command [Front Porch].wait (1ms)
+187ms â•‘â•‘Requesting a wake up for Mon, Feb 19 2018 @ 9:01:10 PM PST (in 60.0s)
+191ms â•‘â•šExecution stage complete. (113ms)
+192ms â•‘Setting up scheduled job for Mon, Feb 19 2018 @ 9:01:10 PM PST (in 59.995s)
+202ms â•šEvent processed successfully (202ms)