Correcting bulbs that should not be on


#1

1) Give a description of the problem
This piston is to correct zigbee bulbs after a hub reboot, or any other switch/bulb that’s on when it shouldn’t be.

2) What is the expected behavior?
These are closet lights: If the door is open, the bulb should be on. Otherwise the bulb should be off. This piston should correct the bulbs if they are mistakenly on for whatever reason.

3) What is happening/not happening?
It will get overwhelmed when attempting to turn off too many at a time and will keep trying multiple times. Sometimes it never succeeds. If it can’t turn off the light after 5 tries, it should give up and stop sending notifications…

**4) Post a Green Snapshot of the piston!


(set to 10 seconds for testing purposes only)


#2

add these to the current piston:

define
   int[] retries
end define

change the with block to the following:

if retries[$currentEventDevice] < 5
   with $currentEventDevice (set TSP to allow multiple)
      set retries[$currentEventDevice] = retries[$currentEventDevice] + 1
      send SMS notification
      wait 5 seconds
      turn off
   end if
end if

add this to the end of the piston for ALL of the light bulbs and dimmer in the or condition of the if:

if white bulb 8 changes to off
   or
   white bulb 15 changes to off
   or
   ...
   with location
      set retries[$currentEventDevice] = 0
   end with
end if

#3

Thank you. I’m confused about: retries[$currentEventDevice]. Do I set that as an expression? If so, should the [ be { ?


#4

change the define for retries to Number list (integer) instead of Number (integer), that will allow you to compare and set the retries variable with an index.

so, all use of retries should be with retries[$currentEventDevice], lines 67, 72 & 94


#5

Ah I see, thanks. Doing a little testing. This thing goes haywire with the notifications… It’s definitely not waiting 5 seconds between each try. It works without fail with 1 light only. But if they all need fixing (like after a hub reboot), it may not work.


(set to 5 seconds for testing)


#6

thats why we set the TSP for the with block to allow multiple. :slight_smile:


#7

line 72 should be:

  set retries[$currentEventDevice] = retries[$currentEventDevice] + 1

you will have to use expression for the part after the =


#8

tagging @ady624 because the snapshot looks funky when the index name is long like here it is $currentEventDevice

thanks!


#9

do you really need all those notifications? :slight_smile: may be just log to console instead?


#10

Ah okay, that definitely does it. I had the 5-second test time the same as the 5-second notification delay, so I was getting duplicates. Changed it to 5minutes on, and 10-seconds in between attempts. I think slowing it down will minimize the failed attempts.

And yeah, just to the console instead. :smiley:

THANKS!


#11

actually, its not retrying for the same bulb anymore - is it? because the if conditions is stays on for 5 minutes - that will only happen once for each light after it changes to on.


#12

Errrm… lemme get back to you in 5mins.


#13

OK :slight_smile:

if you want to retry on each bulb till it turns off with a 10 second wait in between and a maximum of 5 retries, change that if to a while block:

then
    set retries[$currentEventDevice] = 0
    while [$currentEventDevice : switch] is on
          and
          retries[$currentEventDevice] is less than 5
       with $currentEventDevice
       ...
       end with
    end while
end if

#14

Not having good luck with the while… Only two of the bulbs turned off…


#15

probably not the while :slight_smile:

is the piston getting triggered when ALL of those lights are staying on for 5 mins?

an easy way to check that is to log to console $currentEventDevice, $currentEventAttribute, $currentEventValue at the top of the piston. that will tell you what data the piston is getting called or not called with.

EDIT: in a log to console you would have to use expression like this:

$currentEventDevice “^” $currentEventAttribute “^” $currentEventValue

where “^” is just a separator to make the output more readable.


#16

So, this is using the while loop. Here I’ve turned on 3 lights: Bedroom Closet 1, Mini-Closet Light, and Hallway Closet #1 in rapid sequence while the doors are shut. It successfully turned off Mini-Closet Light, and gave up on the rest:

9/26/2017, 4:46:10 PM +434ms
+1ms ╔Received event [We’re Home].time = 1506458770841 with a delay of -409ms
+656ms ╚Event processed successfully (657ms)
9/26/2017, 4:46:04 PM +924ms
+1ms ╔Received event [Mini-Closet Light].switch = off with a delay of 136ms
+862ms ║Piston waited at a semaphore for 521ms
+881ms ║Mini-Closet Light
+889ms ║switch
+897ms ║off
+1090ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:46:10 PM EDT (in 4.828s), with 1 more job pending
+1148ms ╚Event processed successfully (1148ms)
9/26/2017, 4:46:03 PM +274ms
+1ms ╔Received event [We’re Home].time = 1506458763988 with a delay of -714ms
+464ms ║Mini-Closet Light stayed on after the door was closed. Attempting to turn off now.
+1893ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:46:13 PM EDT (in 8.582s)
+1962ms ╚Event processed successfully (1962ms)
9/26/2017, 4:45:53 PM +516ms
+1ms ╔Received event [We’re Home].time = 1506458754704 with a delay of -1188ms
+464ms ║Mini-Closet Light stayed on after the door was closed. Attempting to turn off now.
+1352ms ║Mini-Closet Light stayed on after the door was closed. Attempting to turn off now.
+1511ms ║Mini-Closet Light stayed on after the door was closed. Attempting to turn off now.
+1531ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:46:03 PM EDT (in 8.942s), with 2 more jobs pending
+1599ms ╚Event processed successfully (1599ms)
9/26/2017, 4:45:49 PM +295ms
+2ms ╔Received event [Mini-Closet Light].switch = on with a delay of 223ms
+369ms ║Mini-Closet Light
+378ms ║switch
+386ms ║on
+606ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:45:54 PM EDT (in 4.804s), with 2 more jobs pending
+676ms ╚Event processed successfully (675ms)
9/26/2017, 4:45:44 PM +561ms
+1ms ╔Received event [We’re Home].time = 1506458745346 with a delay of -785ms
+520ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1019ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1038ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:45:55 PM EDT (in 9.491s), with 1 more job pending
+1100ms ╚Event processed successfully (1100ms)
9/26/2017, 4:45:40 PM +74ms
+2ms ╔Received event [Hall Closet #1 Light].switch = on with a delay of 208ms
+1333ms ║Piston waited at a semaphore for 808ms
+1352ms ║Hall Closet #1 Light
+1360ms ║switch
+1368ms ║on
+1583ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:45:45 PM EDT (in 3.691s), with 1 more job pending
+1642ms ╚Event processed successfully (1642ms)
9/26/2017, 4:45:39 PM +874ms
+1ms ╔Received event [Bedroom Closet 1].switch = on with a delay of 547ms
+429ms ║Bedroom Closet 1
+440ms ║switch
+451ms ║on
+702ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:45:45 PM EDT (in 4.771s), with 1 more job pending
+768ms ╚Event processed successfully (768ms)


#17

Another try: Success with only the Bedroom Light.

9/26/2017, 4:56:49 PM +416ms
+1ms ╔Received event [We’re Home].time = 1506459410522 with a delay of -1107ms
+1378ms ╚Event processed successfully (1378ms)
9/26/2017, 4:56:45 PM +169ms
+1ms ╔Received event [Bedroom Closet 1].switch = off with a delay of 584ms
+335ms ║Bedroom Closet 1^switch^off
+488ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:50 PM EDT (in 4.866s), with 1 more job pending
+557ms ╚Event processed successfully (556ms)
9/26/2017, 4:56:39 PM +502ms
+1ms ╔Received event [We’re Home].time = 1506459399993 with a delay of -492ms
+498ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1457ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1621ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1644ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:50 PM EDT (in 8.863s), with 2 more jobs pending
+1761ms ╚Event processed successfully (1761ms)
9/26/2017, 4:56:29 PM +500ms
+0ms ╔Received event [We’re Home].time = 1506459390661 with a delay of -1162ms
+485ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1301ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1444ms ║Bedroom Closet 1 stayed on after the door was closed. Attempting to turn off now.
+1463ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:39 PM EDT (in 9.031s), with 2 more jobs pending
+1526ms ╚Event processed successfully (1527ms)
9/26/2017, 4:56:25 PM +255ms
+4ms ╔Received event [Bedroom Closet 1].switch = on with a delay of 781ms
+387ms ║Bedroom Closet 1^switch^on
+578ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:30 PM EDT (in 4.829s), with 2 more jobs pending
+697ms ╚Event processed successfully (697ms)
9/26/2017, 4:56:21 PM +691ms
+1ms ╔Received event [We’re Home].time = 1506459382533 with a delay of -843ms
+530ms ║Hall Closet #1 Light stayed on after the door was closed. Attempting to turn off now.
+558ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:29 PM EDT (in 7.495s), with 1 more job pending
+623ms ╚Event processed successfully (623ms)
9/26/2017, 4:56:17 PM +157ms
+1ms ╔Received event [Hall Closet #1 Light].switch = on with a delay of 130ms
+362ms ║Hall Closet #1 Light^switch^on
+2567ms ║Mini-Closet Light stayed on after the door was closed. Attempting to turn off now.
+2597ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:22 PM EDT (in 2.78s), with 1 more job pending
+2671ms ╚Event processed successfully (2670ms)
9/26/2017, 4:56:14 PM +177ms
+2ms ╔Received event [Mini-Closet Light].switch = on with a delay of 157ms
+359ms ║Mini-Closet Light^switch^on
+556ms ║Setting up scheduled job for Tue, Sep 26 2017 @ 4:56:19 PM EDT (in 4.838s)
+641ms ╚Event processed successfully (640ms)


#18

on the with please set TCP to never and please retry.


#19

i just tried with 3 lights and doing them near simultaneously. for one of the lights, the piston never seemed to receive the stay on event. that light could be any one of the three in consecutive tests.

do you need the wait 10 seconds statement? what if we remove that and disable command optimization?


#20

the 10 seconds may not be necessary, I was just trying to slow things down a bit. What do you mean disable command optimization?

I also do wonder if it will receive the stay on events after recovering from a power loss, but I guess we’ll see…