Garage door and Garage Man Door turn on/off lights unless lights were already on


#1

1) Give a description of the problem
This script works with the exception of condition #23 at the top.

2) What is the expected behavior?
I want the light to stay IF they were already on. If I go into the garage, the lights turn on automatically. I want to be able to push the lightswitch on to function as a manual “KEEP ON” feature with the need for the motion sensor.

3) What is happening/not happening?
For testing, I am turning on the lights from the app manually and then open the door. The lights are turning off after the doors close and no motion, even though I turned them on first.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
11/25/2017, 12:41:50 AM +540ms +5ms ╔Starting piston... (v0.2.0fe.20171109) +255ms ║╔Subscribing to devices... +305ms ║║Subscribing to Garage Man Door Sensor.contact... +316ms ║║Subscribing to Garage Door Sensor.contact... +376ms ║║Subscribing to Garage Inside Lights... +377ms ║║Subscribing to Motion Sensor... +378ms ║╚Finished subscribing (131ms) +503ms ║Comparison (time) 2510955 is_between (time) 1511654580000 .. (time) 1511622540000 = true (21ms) +507ms ║Time restriction check passed +518ms ║Comparison (enum) off is_not (string) on = true (4ms) +522ms ║Cancelling condition #23's schedules... +541ms ║Comparison (enum) closed is_any_of (string) closed = true (4ms) +556ms ║Comparison (enum) closed stays (string) closed = true (5ms) +565ms ║Comparison (enum) closed is_any_of (string) closed = true (1ms) +574ms ║Comparison (enum) closed stays (string) closed = true (2ms) +586ms ║Comparison (enum) inactive is_not_any_of (string) active = true (3ms) +617ms ╚Piston successfully started (617ms) 11/25/2017, 12:38:30 AM +186ms +0ms ╔Received event [Home].time = 1511599111465 with a delay of -1280ms +202ms ║RunTime Analysis CS > 29ms > PS > 70ms > PE > 103ms > CE +215ms ║Runtime (42012 bytes) successfully initialized in 70ms (v0.2.0fe.20171109) (214ms) +216ms ║╔Execution stage started +234ms ║║Cancelling condition #17's schedules... +235ms ║║Condition #17 evaluated true (2ms) +253ms ║║Comparison (enum) inactive is_not_any_of (string) active = true (10ms) +255ms ║║Condition #19 evaluated true (18ms) +256ms ║║Cancelling condition #5's schedules... +257ms ║║Condition group #5 evaluated true (state changed) (25ms) +259ms ║║Cancelling statement #6's schedules... +284ms ║║Executed physical command [Garage Inside Lights].off() (20ms) +285ms ║║Executed [Garage Inside Lights].off (22ms) +288ms ║╚Execution stage complete. (71ms) +293ms ╚Event processed successfully (294ms) 11/25/2017, 12:38:16 AM +200ms +1ms ╔Received event [Home].time = 1511599097036 with a delay of -836ms +197ms ║RunTime Analysis CS > 28ms > PS > 67ms > PE > 101ms > CE +207ms ║Runtime (42012 bytes) successfully initialized in 67ms (v0.2.0fe.20171109) (205ms) +208ms ║╔Execution stage started +224ms ║║Cancelling condition #9's schedules... +225ms ║║Condition #9 evaluated true (1ms) +240ms ║║Comparison (enum) closed is_any_of (string) closed = true (8ms) +242ms ║║Cancelling condition #16's schedules... +242ms ║║Condition #16 evaluated true (17ms) +257ms ║║Comparison (enum) closed stays (string) closed = true (6ms) +264ms ║║Adding a timed trigger schedule for condition 17 +267ms ║║Cancelling condition #17's schedules... +268ms ║║Condition #17 evaluated false (24ms) +269ms ║║Condition group #5 evaluated false (state did not change) (46ms) +272ms ║║Condition group #18 evaluated true (state did not change) (0ms) +275ms ║╚Execution stage complete. (67ms) +278ms ║Setting up scheduled job for Sat, Nov 25 2017 @ 12:38:31 AM PST (in 14.989s) +335ms ╚Event processed successfully (335ms) 11/25/2017, 12:38:01 AM +791ms +1ms ╔Received event [Garage Door Sensor].contact = closed with a delay of 116ms +177ms ║RunTime Analysis CS > 20ms > PS > 62ms > PE > 95ms > CE +186ms ║Runtime (42015 bytes) successfully initialized in 62ms (v0.2.0fe.20171109) (184ms) +187ms ║╔Execution stage started +204ms ║║Condition #12 evaluated false (9ms) +210ms ║║Comparison (enum) closed changes_to (string) open = false (0ms) +212ms ║║Cancelling condition #13's schedules... +213ms ║║Condition #13 evaluated false (7ms) +214ms ║║Cancelling condition #11's schedules... +215ms ║║Condition group #11 evaluated false (state changed) (19ms) +216ms ║║Condition group #1 evaluated false (state did not change) (21ms) +226ms ║║Comparison (enum) closed is_any_of (string) closed = true (2ms) +228ms ║║Condition #8 evaluated true (8ms) +238ms ║║Comparison (enum) closed stays (string) closed = true (2ms) +245ms ║║Adding a timed trigger schedule for condition 9 +247ms ║║Cancelling condition #9's schedules... +248ms ║║Condition #9 evaluated false (20ms) +249ms ║║Condition group #5 evaluated false (state did not change) (31ms) +252ms ║║Condition group #18 evaluated true (state did not change) (1ms) +255ms ║╚Execution stage complete. (68ms) +257ms ║Setting up scheduled job for Sat, Nov 25 2017 @ 12:38:17 AM PST (in 14.989s) +294ms ╚Event processed successfully (294ms) 11/25/2017, 12:38:00 AM +135ms +0ms ╔Received event [Home].time = 1511599081468 with a delay of -1334ms +169ms ║RunTime Analysis CS > 28ms > PS > 46ms > PE > 96ms > CE +397ms ║Runtime (42007 bytes) successfully initialized in 46ms (v0.2.0fe.20171109) (396ms) +399ms ║╔Execution stage started +424ms ║║Cancelling condition #9's schedules... +426ms ║║Condition #9 evaluated true (4ms) +448ms ║║Comparison (enum) open is_any_of (string) closed = false (9ms) +450ms ║║Cancelling condition #16's schedules... +452ms ║║Condition #16 evaluated false (23ms) +453ms ║║Condition group #5 evaluated false (state did not change) (33ms) +462ms ║║Condition group #18 evaluated true (state did not change) (5ms) +466ms ║╚Execution stage complete. (67ms) +634ms ╚Event processed successfully (634ms) 11/25/2017, 12:37:45 AM +823ms +1ms ╔Received event [Garage Door Sensor].contact = open with a delay of 86ms +183ms ║RunTime Analysis CS > 15ms > PS > 61ms > PE > 107ms > CE +524ms ║Runtime (42012 bytes) successfully initialized in 61ms (v0.2.0fe.20171109) (522ms) +525ms ║╔Execution stage started +543ms ║║Condition #12 evaluated false (10ms) +549ms ║║Comparison (enum) open changes_to (string) open = true (1ms) +550ms ║║Cancelling condition #13's schedules... +551ms ║║Condition #13 evaluated true (7ms) +552ms ║║Cancelling condition #11's schedules... +553ms ║║Condition group #11 evaluated true (state changed) (21ms) +600ms ║║Comparison (time) 2266377 is_between (time) 1511654580000 .. (time) 1511622540000 = true (9ms) +601ms ║║Time restriction check passed +602ms ║║Condition #22 evaluated true (48ms) +612ms ║║Comparison (enum) on is_not (string) on = false (2ms) +613ms ║║Cancelling condition #23's schedules... +614ms ║║Condition #23 evaluated false (11ms) +615ms ║║Condition group #1 evaluated false (state did not change) (83ms) +627ms ║║Comparison (enum) closed is_any_of (string) closed = true (2ms) +628ms ║║Condition #8 evaluated true (10ms) +639ms ║║Comparison (enum) closed stays (string) closed = true (2ms) +645ms ║║Adding a timed trigger schedule for condition 9 +647ms ║║Cancelling condition #9's schedules... +648ms ║║Condition #9 evaluated false (19ms) +649ms ║║Cancelling condition #5's schedules... +650ms ║║Condition group #5 evaluated false (state changed) (32ms) +653ms ║║Condition group #18 evaluated true (state did not change) (0ms) +656ms ║╚Execution stage complete. (131ms) +658ms ║Setting up scheduled job for Sat, Nov 25 2017 @ 12:38:01 AM PST (in 14.988s) +673ms ╚Event processed successfully (673ms)


#2

You are going to need a variable to determine the method your switch was turned on. Since most of the time we can’t capture that we physically turned on the light we have to work the inverse. So we capture when the light wasn’t turned on from the switch.

When the garage doors open or there is motion and the switch is off then set a boolean variable to true. Now in your code for turning the light off you check to make sure that variable is true along with your other conditions. This will then prevent the light from turning off if it wasn’t turned on by the contacts opening or motion. When the light does get turned off. Make sure to reset the variable.


#3

C1arkbar, thanks for your reply! I understand the variable and values related to physica devices but is there somewhere that explains how to use open variable and expressions? Would the variable exist outside of this Piston, or would be in this same Piston?


#4

https://wiki.webcore.co/Variable

https://wiki.webcore.co/Expressions

Not sure I understand much of what you are asking


#5

Variables defined in your piston are only available within that piston.

Global variables, defined on the far right of your edit screen, area available to all pistons.


#6

I am saying that I don’t understand how to create variables and expression. I saw one example of an Expression somewhere that looked like an Excel formula.


#7

Ok to create a variable
Across the top bar of the piston editing window you should see several buttons on the left side. Select the x2 button. This will add a define section into the script window. You define all your variables in this section. Typically you leave the variables blank/not set in this section. Anything defined in this section will be set as that with each run of that piston even if it is changed later on in the script.

Expressions are a different beast. You work with these by changing the value field in a dialogue window to expression. These add a whole new level to evaluating things.


#8

I am 100% sure I did this wrong, but I wanted to take stab at it to see if I could get some direction. I created variables you explained in your original reply, but when I was creating those variables there was no option to define the state of the variables. In other-words, for a physical device I was able to choose that it was a contact but not the state of the contact.


#9

Pseudo code. Try doing this. For testing do not add your time restrictions in.

Define
Boolean autoOn /* not set */
End define

Execute
(
If motion changes to active
OR
contact changes to open
)
and
switch is not on
Then
Turn on light
Set variable autoOn = true
End if
(
If motion changes to inactive
OR
if contact changes to closed
)
And
autoOn is true
Then
Wait xx time
Turn off light
End if


#10

OK this works except when I turn the switch on manually, I want it to stay on even when the sensor closes. What am I doing wrong?


#11

Doesn’t look like you’re ever setting autoOn to false, so it never differs between a light turned on manually.

Couple minutes I’ll post a reworked version (if I understand what you’re trying to do correctly).


#12

See if this gets you closer to what you’re trying to accomplish?

If this is going down the wrong path, let me know.


#13

Thanks! That looks much better. I will test it in the morning so I don’t wake up my wife opening and closing the garage door multiple times this late at night :slight_smile:


#14

You missed the part about the switch not being on and not setting the variable back to off


#15

Thanks to michicago I have this working but now I need to add in a bit more complexity (at least complex for me).

The sensor I am using in the piston is a contact sensor, and I need to add in another contact sensor. Basically if either sensor opens and the light is off turn it on. Then when they are both closed, turn it off. I can’t wrap my head around having two.

Todd


#16

Select both contacts in the first statement. Make sure the orange button that appears says any.

If contact 1 or contact 2 changes to open

In your closing statement you need to do a little more changing. When the orange button appears change any to all. Also change changes to to are. Click the settings cog in the bottom right corner and change the subscription to always

if contact 1 and contact 2 are closed

Note now that you have an and between the two and we have the condition of are closed now.

On the last statement you just need to select the second contact sensor and make sure the orange button is all