Front Door Knock, Lights Turn on, Then turn off with switch


#1

1) Give a description of the problem
I copied and modified bangali’s template for motion based events and made it for a contact sensor.
I don’t know enough about the boolean or programmatic functions to be able to add a bit of code at the end of this routine.

2) What is the expected behavior?
When I turn one light off and then on again it leaves them all on, which is what i want, But the Challenge is i want to then have the piston leave all of the lights on like it currently is doing until i turn one of those switches off and it will turn them all off.

3) What is happening/not happening?
Right now the wait works perfectly like i want it to and when i turn one light off and on it keeps them all on but i cant figure out how to turn them all off once i turn one switch off.


#2

That’s a real challenge…but here’s my take on the solution. I’m going with three different states to the lights, Programmatic, manual and off. I’m using a integer variable to keep track of where things are and react accordingly. The concern might be that the value of the integer could go negative as each switch gets turned off, but I don’t see that being a problem, since it will just get reset when the motion happens again…unless I’ve missed something.


#3

Awesome! I will try it out tonight and let you know how it works.

Using the integer variable is an interesting take I didn’t even think to use that.


#4

shouldnt this work?


#5

I thought about that at first myself as well…but if he does it that way then he loses the “all lights stay on” step in the middle. As turning off one of the lights will turn off all three…and then when he turns one of them back on, only that one will be on.

He wants to have 1) motion turn on all three lights, then 2) be able to toggle one of the three lights to get all three lights to stay on and then he wants to 3) be able to turn off one of the lights and have it turn off all three of them.


#6

ahh ok. removing the turn off at line 54 of the snapshot won’t do it?

EDIT: that wont do it.


#7

The Integer version worked! with the minimal testing I did last night. (My Wife handed me our 6 week old son and said “tag you are it” when i walked in the door from work last night) We did do some basic function testing but i will do some more repetitive stuff tonight and report back.

I have another question about these threads once the solution has been found should we re-post the code into the Example piston category with descriptions or just leave them here?


#8

You can certainly mark something as a “solution” to the initial question, that’s certainly beneficial to others who might come across this thread in the future. Beyond that though I’m not sure.

Perhaps if there already is an example post that @bangali made then it could just be added there. This is really just an iteration to his original work.


#9

@Mike1616 For some reason it stopped working below is the log and a copy of the piston.

ms ╔Received event [Outside Garage Lights].switch = off with a delay of 1253ms
+168ms ║RunTime Analysis CS > 19ms > PS > 35ms > PE > 115ms > CE
+171ms ║Runtime (41833 bytes) successfully initialized in 35ms (v0.2.102.20180116) (169ms)
+172ms ║╔Execution stage started
+185ms ║║Condition #9 evaluated false (7ms)
+186ms ║║Condition group #3 evaluated false (state did not change) (8ms)
+195ms ║║Condition #21 evaluated false (5ms)
+196ms ║║Condition group #15 evaluated false (state did not change) (7ms)
+212ms ║║Comparison (enum) off changes_to (string) off = true (1ms)
+214ms ║║Condition #28 evaluated true (15ms)
+215ms ║║Condition group #25 evaluated true (state did not change) (15ms)
+217ms ║║Cancelling statement #38’s schedules…
+223ms ║║Calculating (integer) -1 - (integer) 1 >> (integer) -2
+228ms ║║Executed virtual command setVariable (3ms)
+235ms ║║Comparison (integer) -2 is_equal_to (integer) 0 = false (1ms)
+237ms ║║Condition #40 evaluated false (6ms)
+238ms ║║Condition group #37 evaluated false (state did not change) (7ms)
+241ms ║╚Execution stage complete. (69ms)
+242ms ╚Event processed successfully (242ms)
2/1/2018, 7:03:26 PM +72ms
+1ms ╔Received event [Entry Way].switch = off with a delay of 1038ms
+167ms ║RunTime Analysis CS > 17ms > PS > 34ms > PE > 116ms > CE
+170ms ║Runtime (41816 bytes) successfully initialized in 34ms (v0.2.102.20180116) (168ms)
+171ms ║╔Execution stage started
+184ms ║║Condition #9 evaluated false (6ms)
+185ms ║║Condition group #3 evaluated false (state did not change) (8ms)
+193ms ║║Condition #21 evaluated false (5ms)
+194ms ║║Condition group #15 evaluated false (state did not change) (7ms)
+210ms ║║Comparison (enum) off changes_to (string) off = true (0ms)
+211ms ║║Condition #28 evaluated true (14ms)
+212ms ║║Condition group #25 evaluated true (state did not change) (15ms)
+215ms ║║Cancelling statement #38’s schedules…
+220ms ║║Calculating (integer) 0 - (integer) 1 >> (integer) -1
+225ms ║║Executed virtual command setVariable (3ms)
+232ms ║║Comparison (integer) -1 is_equal_to (integer) 0 = false (2ms)
+233ms ║║Cancelling condition #40’s schedules…
+234ms ║║Condition #40 evaluated false (6ms)
+235ms ║║Cancelling condition #37’s schedules…
+236ms ║║Condition group #37 evaluated false (state changed) (9ms)
+239ms ║╚Execution stage complete. (68ms)
+240ms ╚Event processed successfully (240ms)
2/1/2018, 7:03:24 PM +919ms
+1ms ╔Received event [Front Pourch].switch = off with a delay of 994ms
+190ms ║RunTime Analysis CS > 21ms > PS > 53ms > PE > 117ms > CE
+193ms ║Runtime (41824 bytes) successfully initialized in 53ms (v0.2.102.20180116) (191ms)
+194ms ║╔Execution stage started
+209ms ║║Condition #9 evaluated false (7ms)
+210ms ║║Condition group #3 evaluated false (state did not change) (9ms)
+219ms ║║Condition #21 evaluated false (6ms)
+220ms ║║Condition group #15 evaluated false (state did not change) (8ms)
+236ms ║║Comparison (enum) off changes_to (string) off = true (1ms)
+238ms ║║Cancelling condition #28’s schedules…
+239ms ║║Condition #28 evaluated true (16ms)
+240ms ║║Cancelling condition #25’s schedules…
+241ms ║║Condition group #25 evaluated true (state changed) (18ms)
+244ms ║║Cancelling statement #38’s schedules…
+250ms ║║Calculating (integer) 1 - (integer) 1 >> (integer) 0
+254ms ║║Executed virtual command setVariable (2ms)
+262ms ║║Comparison (integer) 0 is_equal_to (integer) 0 = true (2ms)
+264ms ║║Cancelling condition #40’s schedules…
+265ms ║║Condition #40 evaluated true (6ms)
+266ms ║║Cancelling condition #37’s schedules…
+267ms ║║Condition group #37 evaluated true (state changed) (9ms)
+269ms ║║Cancelling statement #35’s schedules…
+290ms ║║Executed physical command [Entry Way].off() (18ms)
+291ms ║║Executed [Entry Way].off (20ms)
+294ms ║║Skipped execution of physical command [Front Pourch].off([]) because it would make no change to the device. (0ms)
+295ms ║║Executed [Front Pourch].off (2ms)
+314ms ║║Executed physical command [Outside Garage Lights].off() (18ms)
+315ms ║║Executed [Outside Garage Lights].off (19ms)
+319ms ║╚Execution stage complete. (125ms)
+320ms ╚Event processed successfully (320ms)
2/1/2018, 7:00:36 PM +379ms
+1ms ╔Received event [Home].time = 1517540437442 with a delay of -1064ms
+234ms ║RunTime Analysis CS > 24ms > PS > 65ms > PE > 146ms > CE
+237ms ║Runtime (41826 bytes) successfully initialized in 65ms (v0.2.102.20180116) (236ms)
+238ms ║╔Execution stage started
+239ms ║╚Execution stage complete. (1ms)
+241ms ╚Event processed successfully (241ms)
2/1/2018, 6:56:10 PM +909ms
+1ms ╔Received event [Front Pourch].switch = on with a delay of 1031ms
+166ms ║RunTime Analysis CS > 17ms > PS > 36ms > PE > 114ms > CE
+169ms ║Runtime (41820 bytes) successfully initialized in 36ms (v0.2.102.20180116) (167ms)
+170ms ║╔Execution stage started
+183ms ║║Condition #9 evaluated false (7ms)
+184ms ║║Condition group #3 evaluated false (state did not change) (8ms)
+193ms ║║Condition #21 evaluated false (5ms)
+194ms ║║Condition group #15 evaluated false (state did not change) (7ms)
+210ms ║║Comparison (enum) on changes_to (string) off = false (0ms)
+212ms ║║Cancelling condition #28’s schedules…
+213ms ║║Condition #28 evaluated false (15ms)
+214ms ║║Cancelling condition #25’s schedules…
+214ms ║║Condition group #25 evaluated false (state changed) (17ms)
+217ms ║╚Execution stage complete. (47ms)
+218ms ╚Event processed successfully (218ms)
2/1/2018, 6:55:43 PM +835ms
+1ms ╔Received event [Front Pourch].switch = off with a delay of 1030ms
+170ms ║RunTime Analysis CS > 17ms > PS > 39ms > PE > 114ms > CE
+173ms ║Runtime (41821 bytes) successfully initialized in 39ms (v0.2.102.20180116) (171ms)
+174ms ║╔Execution stage started
+188ms ║║Condition #9 evaluated false (8ms)
+189ms ║║Condition group #3 evaluated false (state did not change) (9ms)
+199ms ║║Cancelling condition #21’s schedules…
+200ms ║║Condition #21 evaluated false (8ms)
+201ms ║║Cancelling condition #15’s schedules…
+202ms ║║Condition group #15 evaluated false (state changed) (9ms)
+218ms ║║Comparison (enum) off changes_to (string) off = true (1ms)
+220ms ║║Cancelling condition #28’s schedules…
+221ms ║║Condition #28 evaluated true (16ms)
+222ms ║║Cancelling condition #25’s schedules…
+223ms ║║Condition group #25 evaluated true (state changed) (19ms)
+225ms ║║Cancelling statement #38’s schedules…
+231ms ║║Calculating (integer) 2 - (integer) 1 >> (integer) 1
+236ms ║║Executed virtual command setVariable (3ms)
+244ms ║║Comparison (integer) 1 is_equal_to (integer) 0 = false (2ms)
+245ms ║║Condition #40 evaluated false (6ms)
+246ms ║║Condition group #37 evaluated false (state did not change) (7ms)
+250ms ║╚Execution stage complete. (76ms)
+251ms ╚Event processed successfully (251ms)
2/1/2018, 6:55:37 PM +210ms
+1ms ╔Received event [Front Door].acceleration = inactive with a delay of 1047ms
+188ms ║RunTime Analysis CS > 21ms > PS > 49ms > PE > 118ms > CE
+191ms ║Runtime (41833 bytes) successfully initialized in 49ms (v0.2.102.20180116) (188ms)
+192ms ║╔Execution stage started
+202ms ║║Comparison (enum) inactive changes_to (string) active = false (0ms)
+203ms ║║Condition #9 evaluated false (5ms)
+204ms ║║Condition group #3 evaluated false (state did not change) (7ms)
+211ms ║║Comparison (enum) inactive changes_to (string) inactive = true (1ms)
+212ms ║║Cancelling condition #21’s schedules…
+213ms ║║Condition #21 evaluated true (6ms)
+218ms ║║Comparison (integer) 2 is_equal_to (integer) 2 = true (1ms)
+219ms ║║Condition #24 evaluated true (5ms)
+220ms ║║Cancelling condition #15’s schedules…
+221ms ║║Condition group #15 evaluated true (state changed) (14ms)
+223ms ║║Cancelling statement #18’s schedules…
+230ms ║║Executed virtual command [Entry Way, Front Pourch, Outside Garage Lights].wait (1ms)
+231ms ║║Requesting a wake up for Thu, Feb 1 2018 @ 7:00:37 PM PST (in 300.0s)
+236ms ║╚Execution stage complete. (45ms)
+237ms ║Setting up scheduled job for Thu, Feb 1 2018 @ 7:00:37 PM PST (in 299.995s)
+247ms ╚Event processed successfully (247ms)
2/1/2018, 6:55:26 PM +325ms
+0ms ╔Received event [Outside Garage Lights].switch = on with a delay of 1045ms
+170ms ║RunTime Analysis CS > 17ms > PS > 37ms > PE > 116ms > CE
+173ms ║Runtime (41832 bytes) successfully initialized in 37ms (v0.2.102.20180116) (171ms)
+174ms ║╔Execution stage started
+188ms ║║Condition #9 evaluated false (7ms)
+189ms ║║Condition group #3 evaluated false (state did not change) (9ms)
+199ms ║║Condition #21 evaluated false (6ms)
+200ms ║║Condition group #15 evaluated false (state did not change) (8ms)
+217ms ║║Comparison (enum) on changes_to (string) off = false (1ms)
+219ms ║║Condition #28 evaluated false (15ms)
+220ms ║║Condition group #25 evaluated false (state did not change) (17ms)
+222ms ║╚Execution stage complete. (49ms)
+224ms ╚Event processed successfully (224ms)
2/1/2018, 6:55:25 PM +498ms
+1ms ╔Received event [Entry Way].switch = on with a delay of 1109ms
+174ms ║RunTime Analysis CS > 17ms > PS > 41ms > PE > 116ms > CE
+177ms ║Runtime (41821 bytes) successfully initialized in 41ms (v0.2.102.20180116) (175ms)
+178ms ║╔Execution stage started
+191ms ║║Condition #9 evaluated false (7ms)
+192ms ║║Condition group #3 evaluated false (state did not change) (8ms)
+201ms ║║Condition #21 evaluated false (5ms)
+202ms ║║Condition group #15 evaluated false (state did not change) (7ms)
+218ms ║║Comparison (enum) on changes_to (string) off = false (1ms)
+220ms ║║Condition #28 evaluated false (15ms)
+221ms ║║Condition group #25 evaluated false (state did not change) (16ms)
+224ms ║╚Execution stage complete. (45ms)
+225ms ╚Event processed successfully (225ms)
2/1/2018, 6:55:24 PM +340ms
+1ms ╔Received event [Front Pourch].switch = on with a delay of 1052ms
+197ms ║RunTime Analysis CS > 21ms > PS > 52ms > PE > 124ms > CE
+200ms ║Runtime (41823 bytes) successfully initialized in 52ms (v0.2.102.20180116) (197ms)
+201ms ║╔Execution stage started
+213ms ║║Cancelling condition #9’s schedules…
+214ms ║║Condition #9 evaluated false (8ms)
+215ms ║║Cancelling condition #3’s schedules…
+216ms ║║Condition group #3 evaluated false (state changed) (10ms)
+225ms ║║Condition #21 evaluated false (5ms)
+226ms ║║Condition group #15 evaluated false (state did not change) (6ms)
+241ms ║║Comparison (enum) on changes_to (string) off = false (0ms)
+243ms ║║Condition #28 evaluated false (13ms)
+244ms ║║Condition group #25 evaluated false (state did not change) (15ms)
+246ms ║╚Execution stage complete. (46ms)
+247ms ╚Event processed successfully (247ms)
2/1/2018, 6:55:23 PM +206ms
+1ms ╔Received event [Front Door].acceleration = active with a delay of 1072ms
+167ms ║RunTime Analysis CS > 17ms > PS > 35ms > PE > 114ms > CE
+169ms ║Runtime (41837 bytes) successfully initialized in 35ms (v0.2.102.20180116) (167ms)
+171ms ║╔Execution stage started
+181ms ║║Comparison (enum) active changes_to (string) active = true (1ms)
+183ms ║║Cancelling condition #9’s schedules…
+184ms ║║Condition #9 evaluated true (6ms)
+200ms ║║Comparison (enum) off is (string) off = true (2ms)
+202ms ║║Cancelling condition #32’s schedules…
+203ms ║║Condition #32 evaluated true (19ms)
+254ms ║║Comparison (time) 68123410 is_between (datetime) 1517535060000 … (datetime) 1517583720000 = true (7ms)
+255ms ║║Time restriction check passed
+257ms ║║Condition #33 evaluated true (53ms)
+258ms ║║Cancelling condition #3’s schedules…
+259ms ║║Condition group #3 evaluated true (state changed) (83ms)
+261ms ║║Cancelling statement #29’s schedules…
+269ms ║║Executed virtual command [Entry Way, Front Pourch, Outside Garage Lights].setVariable (3ms)
+288ms ║║Executed physical command [Entry Way].on() (17ms)
+289ms ║║Executed [Entry Way].on (17ms)
+305ms ║║Executed physical command [Front Pourch].on() (15ms)
+306ms ║║Executed [Front Pourch].on (17ms)
+323ms ║║Executed physical command [Outside Garage Lights].on() (16ms)
+324ms ║║Executed [Outside Garage Lights].on (17ms)
+332ms ║║Comparison (enum) active changes_to (string) inactive = false (1ms)
+334ms ║║Condition #21 evaluated false (5ms)
+335ms ║║Condition group #15 evaluated false (state did not change) (7ms)
+352ms ║║Condition #28 evaluated false (14ms)
+353ms ║║Condition group #25 evaluated false (state did not change) (16ms)
+356ms ║╚Execution stage complete. (186ms)
+357ms ╚Event processed successfully (357ms)
2/1/201


#10

I opened and then shut the front door
Then the 3 lights came on
Then I turned off and then on one of the switches
waited a few seconds
then turned the same switch off
nothing happened
then turned it back on and then off again
nothing happened(its supposed to turn off at this point)
then waited for the 5 min and it stayed on…

So the staying on part is working but then when i want to turn it off it doesnt turn all the lights off again.

Thanks!!!


#11

This appears to be a log of it working as intended. I see the variable get set to 0, and then I see the commands being sent to turn off the lights. I don’t see anything in the logs that show what you’re describing. Odd.

This piston would probably be better if line 36 was changed to:

Contact Sensor acceleration stays inactive for 5 minutes

Then remove line 43.

But I don’t think that’s the culprit of what you’re seeing.


#12

I think the issue is at the end when I go to turn them all off with one switch. It works as intended but then at the very end when i want to turn them all off i am supposed to click one of the switches off and they all shut off but it doesnt do that.

The rest seems to work as planned…


#13

Yeah, I hear what you’re saying. However, the logs that you posted show that the piston sent the commands to turn off all the lights that it was supposed to turn off. I even highlighted the lines where it sent those commands.

I understand you’re saying that it isn’t working, but nothing in the logs back that up. The logs show that it worked.


#14

So this still is not working right and going through the Code below do i need to define or do something with the -1 integer? Or put anything in there about if any switch is turned back on pause piston till any switch is turned off then turn them all off? The way i read the piston the -1 integer is just hanging out there and there is nothing that tells the piston to turn them all off once I hit the off switch again.


#15

I’m not sure what you mean by that, what is the -1 integer?

This part tells them all to turn off.

If motion turns on the lights, State is set to 2, that’s in the first trigger.
If nothing is done, and motion stays inactive for 5 minutes and motion turned the lights on (state = 2) then the second trigger turns off all the lights.
But if you turn one of the lights off manually then back on again, so that you can keep them on, then the third trigger should run. The state should be at 2 initially because motion turned on the lights. Then when you turn off one light, the value in the state variable changes from 2 to 1. Then when you turn off the switch the last time, state should now be equal to 1, so subtracting 1 from it again should get you down to 0 and once at zero the command is sent to turn off all three lights.

I’m not seeing where the problem is in the logic part of the piston. You even posted some logs previously and when I traced through those it looked to me like it was working just fine.

The only suggestion I’d have would be to add in a bunch of log to console commands to this piston so that you can show what the value of the state variable is as it moves along. I realize that lines 48, 55, and 57 set up a recursive process…but the piston just needs the value for state to be at 1 in order for it to turn off all the lights when it hits that section. The logs you posted previously show that it did that.

But it all boils down to what’s the value of the state variable as the piston goes along. So I’d add a bunch of logging to the piston to gain an insight into how that variable is being set.


#16

The -1 is created by this:
image
The IF statement preceding this sets state = 0 if acceleration stays inactive for 5 minutes and state = 2.

If any of those lights turn off after the above condition evaluates true, you’ll get -1 for your State.


#17

I agree. But the value should not stay that way as turning on the lights by the acceleration event will reset it back to 2. But that’s not the issue he’s reporting anyway.

I think he’s saying that when he toggles the lights to keep them on…that they then do not all turn off when he hits the off switch again.

The Toggle (which must be done within the 5 minute window) would make state go from 2 to 1. Then the off command again should result in state dropping down to 0 and then should turn off all the lights.

Now, if there’s a way to turn on the lights without the acceleration event happening (and therefore never putting state back to 2) then yeah, this thing could be busted.

Thus…I think I need to see more detail about what the value is in the variable as the piston performs.

However, the logs I looked at in detail before, showed that it was doing exactly what it was designed to do.


#18

If he’s getting a -1 integer, then the “switch the 3 lights off” won’t run because State is not 0. That’s all I was pointing out. That seemed to be his issue in the latest post (not blending things in from 2 weeks ago) but it’s hard to tell.


#19

So after reading through this I think I found the issue. Right now it says the Local Variable state is -1

image
One of the switches controls an entry way light that my wife uses without triggering the acceleration sensor on the front door. so by her turning on and off that light during one of these events could be throwing the piston off.

@Mike1616 Thank you for the explanation I now understand that its like a math equation and the integer state changes adds and subtracts to get you back to 0.


#20

Yes, that’s all the piston is doing. It’s just keeping track of the order of things so that it can turn off all the lights at the end. Accounting for the lights switch being turned off outside of this was not part of the plan. :slight_smile:

The initial value of state should be 2. Maybe you need to add something in there so that if it falls below 0 then you reset it to 2. You’d have to test that out though to make sure that it behaves properly.