Light that turns on by switch, motion, or unlock with different actions


#1

1) Give a description of the problem
I think I have this worked out, but the coding seems complex and messy and I was wondering if someone could just take a look at it and give some advice. Everything is working the way I want, but at times it is slow and throws semaphore errors.

2) What is the expected behaviour?
I have an entry light in a landing coming up to my living room on a dimmer. The light can be turned on manually with a switch, and we use the light sometimes like when we watch TV or have a lot of people over. It also is at the front door, so if its night time, and now I got it to when it’s raining, it comes on when you unlock the door. Its also tied to a motion sensor, so if the doorbell senses motion, it turns on so if someone comes up to the house in the middle of the night it looks like they were spotted and the light comes on. So a little tricky, basically if its switched on I don’t want the lock or motion to impact the light. If its triggered by unlocking and off, I don’t want motion to impact it either. If motion impacts it, I want it to turn off after five minutes. If its locked manually, like we come inside and lock it, take off our shoes and coats, it shuts off after a few minutes. If its locked by the keypad or app, the light shuts off immediately, and stays off for five minutes so motion does not turn it back on as the car pulls away. Maybe I’m trying to do a little to much, but after motion or lock turns it on, the next “entry light on” event always causes a semaphore. I’m wondering if there are any tips for a better way to write it.

3) What is happening/not happening?
Its working but slow occasionally and has semaphore errors from time to time.

**4) Post a Green Snapshot of the piston![image|45x37]

Logs:
7/29/2020, 9:05:37 PM +200ms
+1ms â•”Received event [Front Door].motion = inactive with a delay of 130ms
+92ms â•‘RunTime Analysis CS > 20ms > PS > 8ms > PE > 64ms > CE
+95ms â•‘Runtime (56969 bytes) successfully initialized in 8ms (v0.3.110.20191009) (93ms)
+96ms â•‘â•”Execution stage started
+107ms â•‘â•‘Condition #11 evaluated false (7ms)
+108ms â•‘â•‘Condition group #1 evaluated false (state did not change) (8ms)
+114ms â•‘â•‘Comparison (enum) inactive changes_to (string) active = false (1ms)
+115ms â•‘â•‘Condition #24 evaluated false (4ms)
+116ms â•‘â•‘Condition group #23 evaluated false (state did not change) (5ms)
+122ms â•‘â•‘Condition #33 evaluated false (4ms)
+123ms â•‘â•‘Condition group #32 evaluated false (state did not change) (5ms)
+132ms â•‘â•‘Condition #43 evaluated false (6ms)
+133ms â•‘â•‘Condition group #42 evaluated false (state did not change) (7ms)
+134ms â•‘â•‘Condition group #41 evaluated false (state did not change) (9ms)
+139ms â•‘â•‘Comparison (enum) inactive changes_to (string) inactive = true (1ms)
+140ms ║║Cancelling condition #75’s schedules…
+141ms â•‘â•‘Condition #75 evaluated true (5ms)
+145ms â•‘â•‘Comparison (string) motion is (string) motion = true (1ms)
+146ms ║║Cancelling condition #52’s schedules…
+147ms â•‘â•‘Condition #52 evaluated true (5ms)
+148ms ║║Cancelling condition #51’s schedules…
+149ms â•‘â•‘Condition group #51 evaluated true (state changed) (13ms)
+151ms ║║Cancelling statement #98’s schedules…
+156ms â•‘â•‘Executed virtual command setVariable (2ms)
+166ms â•‘â•‘Condition #15 evaluated false (7ms)
+167ms â•‘â•‘Condition group #14 evaluated false (state did not change) (8ms)
+174ms â•‘â•‘Condition #60 evaluated false (5ms)
+175ms â•‘â•‘Condition group #59 evaluated false (state did not change) (6ms)
+181ms â•‘â•‘Comparison (boolean) false stays (boolean) true = false (1ms)
+183ms â•‘â•‘Cancelling any timed trigger schedules for condition 83
+184ms ║║Cancelling statement #83’s schedules…
+185ms â•‘â•‘Condition #83 evaluated false (7ms)
+186ms â•‘â•‘Condition group #82 evaluated false (state did not change) (9ms)
+193ms â•‘â•‘Comparison (string) delayoff stays (string) delayoff = true (1ms)
+194ms â•‘â•‘Adding a timed trigger schedule for condition 101
+197ms â•‘â•‘Condition #101 evaluated false (7ms)
+197ms â•‘â•‘Condition group #100 evaluated false (state did not change) (9ms)
+200ms â•‘â•šExecution stage complete. (103ms)
+201ms â•‘Setting up scheduled job for Wed, Jul 29 2020 @ 9:10:37 PM EDT (in 299.995s)
+209ms â•šEvent processed successfully (209ms)
7/29/2020, 9:04:57 PM +925ms
+1ms â•”Received event [Entry light].switch = on with a delay of 119ms
+9863ms â•‘RunTime Analysis CS > 24ms > PS > 9770ms > PE > 70ms > CE
+9864ms â•‘Piston waited at a semaphore for 9764ms
+9867ms â•‘Runtime (57039 bytes) successfully initialized in 9770ms (v0.3.110.20191009) (9865ms)
+9868ms â•‘â•”Execution stage started
+9879ms â•‘â•‘Condition #11 evaluated false (7ms)
+9880ms â•‘â•‘Condition group #1 evaluated false (state did not change) (8ms)
+9888ms ║║Cancelling condition #24’s schedules…
+9889ms â•‘â•‘Condition #24 evaluated false (6ms)
+9890ms ║║Cancelling condition #23’s schedules…
+9891ms â•‘â•‘Condition group #23 evaluated false (state changed) (9ms)
+9898ms â•‘â•‘Condition #33 evaluated false (5ms)
+9899ms â•‘â•‘Condition group #32 evaluated false (state did not change) (6ms)
+9906ms â•‘â•‘Condition #43 evaluated false (4ms)
+9907ms â•‘â•‘Condition group #42 evaluated false (state did not change) (5ms)
+9908ms â•‘â•‘Condition group #41 evaluated false (state did not change) (7ms)
+9915ms â•‘â•‘Condition #75 evaluated false (3ms)
+9916ms â•‘â•‘Condition group #51 evaluated false (state did not change) (5ms)
+9921ms â•‘â•‘Comparison (enum) on changes_to (string) on = false (1ms)
+9922ms â•‘â•‘Condition #15 evaluated false (4ms)
+9923ms â•‘â•‘Condition group #14 evaluated false (state did not change) (5ms)
+9928ms â•‘â•‘Comparison (enum) on changes_to (string) off = false (1ms)
+9929ms â•‘â•‘Condition #60 evaluated false (4ms)
+9930ms â•‘â•‘Condition group #59 evaluated false (state did not change) (5ms)
+9936ms â•‘â•‘Comparison (boolean) false stays (boolean) true = false (1ms)
+9938ms â•‘â•‘Cancelling any timed trigger schedules for condition 83
+9939ms ║║Cancelling statement #83’s schedules…
+9940ms â•‘â•‘Condition #83 evaluated false (7ms)
+9941ms â•‘â•‘Condition group #82 evaluated false (state did not change) (9ms)
+9947ms â•‘â•‘Comparison (string) motion stays (string) delayoff = false (1ms)
+9949ms â•‘â•‘Cancelling any timed trigger schedules for condition 101
+9950ms ║║Cancelling statement #101’s schedules…
+9950ms â•‘â•‘Condition #101 evaluated false (7ms)
+9951ms â•‘â•‘Condition group #100 evaluated false (state did not change) (8ms)
+9953ms â•‘â•šExecution stage complete. (85ms)
+9954ms â•šEvent processed successfully (9954ms)
7/29/2020, 9:04:57 PM +476ms
+2ms â•”Received event [Front Door].motion = active with a delay of 125ms
+83ms â•‘RunTime Analysis CS > 19ms > PS > 7ms > PE > 56ms > CE
+86ms â•‘Runtime (56940 bytes) successfully initialized in 7ms (v0.3.110.20191009) (84ms)
+87ms â•‘â•”Execution stage started
+98ms â•‘â•‘Condition #11 evaluated false (8ms)
+99ms â•‘â•‘Condition group #1 evaluated false (state did not change) (9ms)
+104ms â•‘â•‘Comparison (enum) active changes_to (string) active = true (1ms)
+105ms ║║Cancelling condition #24’s schedules…
+106ms â•‘â•‘Condition #24 evaluated true (5ms)
+148ms ║║Comparison (time) 75897583 is_between (time) 1596069540000 … (time) 1596016980000 = true (8ms)
+149ms â•‘â•‘Time restriction check passed
+151ms â•‘â•‘Condition #25 evaluated true (44ms)
+154ms â•‘â•‘Comparison (string) off is (string) off = true (1ms)
+155ms â•‘â•‘Condition #26 evaluated true (4ms)
+159ms â•‘â•‘Comparison (boolean) false is_not (boolean) true = true (2ms)
+160ms â•‘â•‘Condition #80 evaluated true (4ms)
+167ms â•‘â•‘Comparison (enum) off is (string) off = true (1ms)
+168ms ║║Cancelling condition #115’s schedules…
+169ms â•‘â•‘Condition #115 evaluated true (7ms)
+170ms ║║Cancelling condition #23’s schedules…
+170ms â•‘â•‘Condition group #23 evaluated true (state changed) (69ms)
+172ms ║║Cancelling statement #28’s schedules…
+371ms â•‘â•‘Executed physical command [Entry light].setLevel([100]) (194ms)
+372ms â•‘â•‘Executed [Entry light].setLevel (196ms)
+374ms ║║Cancelling statement #30’s schedules…
+379ms â•‘â•‘Executed virtual command setVariable (3ms)
+386ms â•‘â•‘Calculating (string) On From Motion (at + (string) 9:04 P.M. >> (string) On From Motion (at 9:04 P.M.
+389ms â•‘â•‘Calculating (string) On From Motion (at 9:04 P.M. + (string) on >> (string) On From Motion (at 9:04 P.M. on
+391ms â•‘â•‘Calculating (string) On From Motion (at 9:04 P.M. on + (string) Wednesday >> (string) On From Motion (at 9:04 P.M. on Wednesday
+394ms â•‘â•‘Calculating (string) On From Motion (at 9:04 P.M. on Wednesday + (string) ) >> (string) On From Motion (at 9:04 P.M. on Wednesday)
+396ms â•‘â•‘Executed virtual command setState (1ms)
+402ms â•‘â•‘Condition #33 evaluated false (4ms)
+403ms â•‘â•‘Condition group #32 evaluated false (state did not change) (5ms)
+411ms â•‘â•‘Condition #43 evaluated false (4ms)
+411ms â•‘â•‘Condition group #42 evaluated false (state did not change) (6ms)
+412ms â•‘â•‘Condition group #41 evaluated false (state did not change) (7ms)
+417ms â•‘â•‘Comparison (enum) active changes_to (string) inactive = false (1ms)
+418ms ║║Cancelling condition #75’s schedules…
+419ms â•‘â•‘Condition #75 evaluated false (5ms)
+420ms â•‘â•‘Condition group #51 evaluated false (state did not change) (5ms)
+425ms â•‘â•‘Condition #15 evaluated false (3ms)
+426ms â•‘â•‘Condition group #14 evaluated false (state did not change) (5ms)
+432ms â•‘â•‘Condition #60 evaluated false (4ms)
+433ms â•‘â•‘Condition group #59 evaluated false (state did not change) (4ms)
+438ms â•‘â•‘Comparison (boolean) false stays (boolean) true = false (1ms)
+440ms â•‘â•‘Cancelling any timed trigger schedules for condition 83
+440ms ║║Cancelling statement #83’s schedules…
+441ms â•‘â•‘Condition #83 evaluated false (6ms)
+442ms â•‘â•‘Condition group #82 evaluated false (state did not change) (8ms)
+448ms â•‘â•‘Comparison (string) motion stays (string) delayoff = false (1ms)
+449ms â•‘â•‘Cancelling any timed trigger schedules for condition 101
+450ms ║║Cancelling statement #101’s schedules…
+451ms â•‘â•‘Condition #101 evaluated false (7ms)
+452ms â•‘â•‘Condition group #100 evaluated false (state did not change) (8ms)
+453ms â•‘â•šExecution stage complete. (366ms)
+454ms â•šEvent processed successfully (454ms)Preformatted text


#2

i just had a quick look at your piston…
I’d say, a lot is happening for a single piston.
Every time a piston is executed, it runs the whole thing top to buttom.
If i were you, I would splite this into 3-4 different pistons.
“Less is more” is the safest way to use webcore.


#3

I agree with @ike2018. I am a fan of small, easy to debug pistons. I would break down your piston into single, specific tasks and get those working properly. It just makes debugging much more simple for me (and those helping you). Then you can consider combining into a larger piston. That’s just how I roll…your mileage may vary.


#4

Thanks for the info, I agree I would like to break it up across pistons, and originally that’s how I had it, but the problem is if I use a global variable they don’t seem to update in time before the next piston runs. Then I read issues where a global variable isn’t updated until after the piston runs. Maybe there is a better way then a global variable? Another problem I have is the switch is a GE dimmer and doesn’t seem to always report its status right away, or as it’s ramping it continually changes the level and triggers the piston. I originally was trying to use the device level to trigger things and that was a mess because the level floats around so much as the device “ramps” on or off. I wish I could find a better DTH for the switch to make that not happen. Are there ways to have a piston “stop” once something happens? For example if the lock part turns it on, can it just stop and not do the rest of the piston or something like that? Also, if the piston turns a light on, is there anyway to get that “automatic” change to not trigger an event? That seems to be the real problem right now, when the motion or lock turns the light on, it is triggering the On event on line 111 that checks if it was from the switch, which evaluates false because it wasn’t from the switch, but that creates the semaphore and ties the whole thing up.


#5

in the piston edit mode click options on the top right and enable show advanced statements. then add a new statement and pick exit in the bottom right corner from the popup window.


#6

You can edit line 112 (lightning bolt) , click on the cog, and change “Subscription method” to “Never Subscribe”. This will remove the lightning bolt. But this may affect the desired function of your piston.