Automate Aurora and Exterior Lights


#1

1) Give a description of the problem
If someone approaches my front door, I want to turn on my outdoor lights for 3 minutes (and then off) and change the scene of my Nanoleaf Aurora to “Alert” (rapidly blinking colorful lights) for 5 seconds (and then return it to its prior state).
The outdoor lights should only turn on if it is dark outside (15 minutes past sunset to 15 minutes before sunrise) and only if Smartthings is not in “Party” mode (where the outdoor lights will be on manually and stay on).

I had issues with Arlo not recording when integrated with Smartthings, so I’m using IFTTT/Stringify with Arlo to make a web request into webcore.

2) What is the expected behavior?
I set up two pistons.
The “main” piston triggers the nanoleaf and the outdoor lights (per the above conditions).
The “helper” piston detects the gate and triggers the “main” piston. When the Arlo detects motion, it also triggers the “main” piston.

3) What is happening/not happening?
a) For some reason, my outdoor lights turn on around sunrise and stay on even though there was no trigger.
b) Also, I can’t figure out how to call the changeScene Aurora function from webcore.
It is in the device handler, but doesn’t show up for the device:
def changeScene(String scene) {
sendEvent(name: "scene", value: scene, isStateChange: true)
return createPutRequest("effects", "{\"select\" : \"${scene}\"}")
}

4) Post a Green Snapshot of the pistonimage
2017-10-21-piston
**5) Attach any logs
(Manually switch off): 2017-10-20 7:34:20AM DEVICE switch off Outdoor Lights switch is off
(Unknown turn on): 2017-10-20 6:45:00AM APP_COMMAND on Outdoor Lights for 3 Minutes sent on command to Outdoor Lights
(Unknown turn on): 2017-10-20 6:44:59AM DEVICE switch on Outdoor Lights switch is on


#2

Okay, I’m starting to realize that my piston is getting executed at the sunrise/sunset boundaries and when the location mode changes (hence the lightning bolts). This was not my intent: I only wanted the piston to be executed when manually called (by the other piston or by my IFTTT event).

However, it seems like a bug that the light is getting left on at sunrise. Why is the “wait 3 minutes” and “turn off” not happening?

Also, I got the changeScene function that I added as a command to show up by removing and re-adding the device from webcore. Before that, my changes to the device handler (at least in terms of exposing the function) didn’t take effect.


#3

In the piston settings change the subscription method to none. This will make your piston only executable from outside triggers like you want.

It’s hard to tell what is happening without giving us all the logs. Copy/paste an entire set where the lights are coming on but not going off.

You might be able to resolve this issue by click on the with for switch 1 and changing the TCP to never.


#4

Here’s the log. I removed the Aurora’s “physical commands” to help with clarity.

The first execution of the script turns on the light, and then there are 3 more execution for some reason.

As a side note, I messed up the “async” part of the Aurora flashing. The flashing on/off happens all at once (instead of spread out at 500ms on/offs). I intended for the “async” to happen so that the Aurora to begin flashing at the same time as the outdoor lights coming on, so I think I need to structure the groups of actions differently.

Anyway, here are the logs:

10/24/2017, 7:05:04 AM +64ms
+1ms	╔Received event [Home].time = 1508850304745 with a delay of -681ms
+106ms	║RunTime Analysis CS > 14ms > PS > 48ms > PE > 44ms > CE
+117ms	║Runtime (38130 bytes) successfully initialized in 48ms (v0.2.0fa.20171011) (116ms)
+118ms	║╔Execution stage started
+130ms	║╚Execution stage complete. (11ms)
+131ms	║Setting up scheduled job for Tue, Oct 24 2017 @ 6:35:00 PM  (in 41395.805s)
+148ms	╚Event processed successfully (148ms)
10/24/2017, 7:04:59 AM +83ms
+1ms	╔Received event [Home].time = 1508850300000 with a delay of -917ms
+106ms	║RunTime Analysis CS > 21ms > PS > 47ms > PE > 38ms > CE
+122ms	║Runtime (38125 bytes) successfully initialized in 47ms (v0.2.0fa.20171011) (120ms)
+123ms	║╔Execution stage started
+129ms	║║Cancelling statement #9's schedules...
+560ms	║║Executed virtual command [Aurora].flash (425ms)
+562ms	║║Requesting a wake up for Tue, Oct 24 2017 @ 7:05:04 AM  (in 5.1s)
+589ms	║║Comparison (time) 25499649 is_between (time) 1508890800000 .. (time) 1508851200000 = false (6ms)
+590ms	║║Cancelling condition #11's schedules...
+591ms	║║Condition #11 evaluated false (25ms)
+592ms	║║Cancelling statement #11's schedules...
+599ms	║║Requesting time schedule wake up at Tue, Oct 24 2017 @ 6:35:00 PM 
+601ms	║║Cancelling condition #6's schedules...
+602ms	║║Condition group #6 evaluated false (state changed) (37ms)
+605ms	║╚Execution stage complete. (483ms)
+607ms	║Setting up scheduled job for Tue, Oct 24 2017 @ 7:05:04 AM (in 5.056s), with 1 more job pending
+734ms	╚Event processed successfully (733ms)
10/24/2017, 7:04:05 AM +199ms
+1ms	╔Received event [Home].time = 1508850245049 with a delay of 149ms
+102ms	║RunTime Analysis CS > 15ms > PS > 56ms > PE > 32ms > CE
+113ms	║Runtime (38124 bytes) successfully initialized in 56ms (v0.2.0fa.20171011) (110ms)
+113ms	║╔Execution stage started
+123ms	║╚Execution stage complete. (10ms)
+125ms	║Setting up scheduled job for Tue, Oct 24 2017 @ 7:05:00 AM  (in 54.677s), with 1 more job pending
+139ms	╚Event processed successfully (139ms)
10/24/2017, 7:03:59 AM +288ms
+1ms	╔Received event [Home].time = 1508850240000 with a delay of -712ms
+199ms	║RunTime Analysis CS > 20ms > PS > 140ms > PE > 38ms > CE
+212ms	║Runtime (38127 bytes) successfully initialized in 140ms (v0.2.0fa.20171011) (210ms)
+213ms	║╔Execution stage started
+219ms	║║Cancelling statement #9's schedules...
+659ms	║║Executed virtual command [Aurora].flash (435ms)
+660ms	║║Requesting a wake up for Tue, Oct 24 2017 @ 7:04:05 AM  (in 5.1s)
+689ms	║║Comparison (time) 25439952 is_between (time) 1508890800000 .. (time) 1508851200000 = true (6ms)
+690ms	║║Time restriction check passed
+691ms	║║Condition #11 evaluated true (27ms)
+692ms	║║Cancelling statement #11's schedules...
+698ms	║║Requesting time schedule wake up at Tue, Oct 24 2017 @ 7:05:00 AM 
+703ms	║║Comparison (string) :291234…aaf9: is_not (string) :f4abcd…5542: = true (1ms)
+705ms	║║Condition #14 evaluated true (4ms)
+706ms	║║Condition group #6 evaluated true (state did not change) (41ms)
+708ms	║║Cancelling statement #7's schedules...
+735ms	║║Executed physical command [Outdoor Lights].on() (24ms)
+735ms	║║Executed [Outdoor Lights].on (25ms)
+738ms	║║Executed virtual command [Outdoor Lights].wait (0ms)
+739ms	║║Requesting a wake up for Tue, Oct 24 2017 @ 7:07:00 AM  (in 180.0s)
+744ms	║╚Execution stage complete. (531ms)
+746ms	║Setting up scheduled job for Tue, Oct 24 2017 @ 7:04:05 AM  (in 5.016s), with 2 more jobs pending
+931ms	╚Event processed successfully (930ms)

#5

To explain the multiple executions in the log. Any time you have a command that will take more than 3 seconds to execute then the piston will schedule a wake up for that time. So the wait 5 seconds schedules a wake up as well as the 3 minutes.

Have you removed the subscriptions so this only executes from the outside source?


#6

@c1arkbar I haven’t made that change yet… I think I need to do some more reading on schedule cancellation/reentrancy/etc, but things are starting to make sense.

I think you’re right about the Task Cancellation Policy:
The default option is “Cancel tasks on condition state change”, so if the light is turned on right before the “sunrise - 15min” threshold and then the three minute timer puts the “turn off” after the threshold, I think it gets cancelled.

Thanks for you help.


#7

Sure thing. If you need more help we are all here


#8

For #3, take a look at the DTH again. It was updated a couple days ago to expose changeScene().


#9

@crl Thanks for the heads up.
I actually updated the device handler myself using the “displayTemp” function from the Nanoleaf API. This function does exactly what I wanted (display a different scene for some amount of seconds and then go back to whatever it was doing beforehand).

    return createPutRequest("effects", "{\"write\" : {\"command\":\"displayTemp\", \"duration\":5, \"animName\":\"Alert\"}}")

Basically, I have a scene that I designed from the nanoleaf app that I named “Alert.” That scene of wildly flashing colors gets displayed for 5 seconds when my function is called.

Edit: I guess it wasn’t exactly what I initially asked for (blinking on and off), but I decided I liked the effect better. To do what I initially asked for, you would still use displayTemp, but would need to provide a palette (with two colors: the alert color & black), transition time, animType, etc.


#10

@dpryan Good stuff! That would be good to merge into @Edward_Niedziejko’s version of the DTH.