Presence sensor and time based piston help


#1

1) Give a description of the problem
Trying to combine bellow code into one instead of having two.

2) What is the expected behaviour?
While at home using presence do not lock or close garage but after 11:30pm and 6:30am check every 30 minutes and if opened close and lock.

3) What is happening/not happening?
Time based portion works but not presence.

Thanks!


#2

Think you have the overnight scheme figured out with the first part of your piston there. I would add a condition to check if its already closed. That way it wont keep actually working overnight when not needed.

The second part based of your presence sensor will need some work but I’m a bit hazy as to what you are trying to make happen. Can you expand on that more?


#3

Thanks for the reply!

Sorry for not being more clear. This is what I’m trying to accomplish:

  1. When I’m at home with presence sensor (my phone) do NOT lock, turn off or close.
  2. But if time is between 11:30pm and 6:30am IGNORE above presence and check every 30 minutes and lock, turn off and close IF doors/garage are open/unlocked.

#4

The implementation the way you have it written as “every ##” minutes does not have a starting reference besides when the piston was saved. In other words if you saved the piston at 3:37PM, it will start that every 30 minute counter so it would run that piston at 4:07PM, 4:37PM, 5:07PM, etc. If you elected to have the cycle be every 1 hour instead of 30 minutes you can set at how many minutes past the hour so its a accurate trigger. Should you want it at the 30 minutes interval you would just have to make sure you save the piston 30 minutes ahead of when you would want it to start. So if you wanted it to run right at the top of the hour, every time you save that piston, save it at 30 minutes past whatever hour.

I personally like conditions laid out in a flowing manner so instead of using the hour conditions on the timer I added it as a condition to the action. The second condition being whether the door is actually open instead of telling the system to close it every instance.

So see below how I would start with it.

Since this piston does not have the presence sensor controlling the switch in any manner there is no need to include it as a restriction. This would run 10:30PM - 6:30AM regardless of what your presence status is.

So my follow up question is what you do want the presence sensor to do in relation to this switch?


#5

Below is what I was able to test remotely and it looks like it was working. I will do more thorough test when I get home.

So the purpose of the presence sensor in relation to the switch is when I leave the house I forgot to lock door/close garage to do it automatically once it senses I’m not present. Switch was just a basic example while I was trying to find working solution.


#6

The nested timer obviously will give you issues as its even showing a warning. Instead I duplicated the IF block and inverted the times from the evening, and added presence as a condition. See below.


#7

Ok, so I paused my pistion and imported yours. Obviosly I added my lock and garage door (is seen as switch in ST) but when when I leave bedroom light (Switch 3) ON nothing happens after 1 minute mark. Code says it should be turned OFF. Any suggestions?

Edit: correct me if I’m wrong but does it mean everything needs to be turned On and unlocked in order to start OFF and lock procedure?

Here’s the log:

    12/11/2019, 1:02:01 PM +62ms
+1ms	â•”Received event [My home].time = 1576098121976 with a delay of -914ms
+212ms	â•‘RunTime Analysis CS > 72ms > PS > 117ms > PE > 22ms > CE
+214ms	â•‘Runtime (41724 bytes) successfully initialized in 117ms (v0.3.110.20191009) (213ms)
+215ms	â•‘â•”Execution stage started
+235ms	â•‘â•‘Comparison (time) 46921286 is_between (time) 23400000 .. (time) 81000000 = true (8ms)
+236ms	â•‘â•‘Time restriction check passed
+237ms	â•‘â•‘Condition #7 evaluated true (13ms)
+247ms	â•‘â•‘Comparison (enum) not present is (string) not present = true (1ms)
+248ms	â•‘â•‘Condition #8 evaluated true (10ms)
+256ms	â•‘â•‘Comparison (enum) on is (string) on = true (1ms)
+258ms	â•‘â•‘Condition #6 evaluated true (9ms)
+266ms	â•‘â•‘Comparison (enum) unlocked is (string) unlocked = true (1ms)
+268ms	â•‘â•‘Condition #18 evaluated true (9ms)
+277ms	â•‘â•‘Comparison (enum) off is (string) on = false (2ms)
+278ms	â•‘â•‘Condition #19 evaluated false (10ms)
+279ms	â•‘â•‘Condition group #5 evaluated false (state did not change) (55ms)
+294ms	â•‘â•‘Comparison (time) 46921344 is_between (time) 81000000 .. (time) 23400000 = false (9ms)
+296ms	â•‘â•‘Condition #10 evaluated false (14ms)
+297ms	â•‘â•‘Condition group #9 evaluated false (state did not change) (16ms)
+300ms	║╚Execution stage complete. (85ms)
+301ms	â•‘Setting up scheduled job for Wed, Dec 11 2019 @ 1:03:01 PM PST (in 60.613s)
+325ms	╚Event processed successfully (325ms)


#8

In the piston before taking a green screen shot can you please enable trace? Its the button to the left of the red delete when viewing a piston before editing. This will tell us where each condition is in the logs you post. Once trace is enabled repost green screenshot with corresponding logs please.

The way that you have this written right now you are correct. I would work on this one IF block at a time with one condition at a time. Obviously time and presence are easy but from there add 1 switch’s condition at a time and test. What is unknown to me about your specifics is what the different combinations of possibilities exist. So could you ever have an instance where Switch 1 is on but also locked but switch 3 is on? Because that would prevent the first IF block from running.

Edit: also I would separate out commands that dont apply to a device. For example you have Switch 1, Switch 3, and Lock 1, locking and then turning off. If Switch 3 doesn’t have that lock capability it will throw an error. Group actions in different “with” based on capability/action. So it could be with Lock 1, lock, and then With Switch 1, Switch 3, Turn off.


#9

Ok, thanks for the explanation. I will start back from simple light switch condition at a time and work my way up by adding others.
In the mean time here’s the log with trace enabled:

12/11/2019, 2:14:01 PM +73ms
+0ms â•”Received event [My home].time = 1576102441976 with a delay of -904ms
+360ms â•‘RunTime Analysis CS > 44ms > PS > 282ms > PE > 34ms > CE
+362ms â•‘Runtime (41724 bytes) successfully initialized in 282ms (v0.3.110.20191009) (361ms)
+363ms â•‘â•”Execution stage started
+381ms â•‘â•‘Comparison (time) 51241445 is_between (time) 23400000 .. (time) 81000000 = true (7ms)
+382ms â•‘â•‘Time restriction check passed
+383ms â•‘â•‘Condition #7 evaluated true (11ms)
+391ms â•‘â•‘Comparison (enum) not present is (string) not present = true (1ms)
+392ms â•‘â•‘Condition #8 evaluated true (8ms)
+400ms â•‘â•‘Comparison (enum) on is (string) on = true (2ms)
+401ms â•‘â•‘Condition #6 evaluated true (8ms)
+408ms â•‘â•‘Comparison (enum) unlocked is (string) unlocked = true (1ms)
+410ms â•‘â•‘Condition #18 evaluated true (7ms)
+418ms â•‘â•‘Comparison (enum) off is (string) on = false (1ms)
+419ms â•‘â•‘Condition #19 evaluated false (9ms)
+420ms â•‘â•‘Condition group #5 evaluated false (state did not change) (49ms)
+431ms â•‘â•‘Comparison (time) 51241496 is_between (time) 81000000 .. (time) 23400000 = false (7ms)
+433ms â•‘â•‘Condition #10 evaluated false (10ms)
+434ms â•‘â•‘Condition group #9 evaluated false (state did not change) (11ms)
+436ms ║╚Execution stage complete. (73ms)
+437ms â•‘Setting up scheduled job for Wed, Dec 11 2019 @ 2:15:01 PM PST (in 60.466s)
+448ms ╚Event processed successfully (448ms)

#10

Go back to your piston and look to turn on the trace, and then take the green screenshot and logs. It will add numbers to the piston that correspond with the logs.

See here for the blue button. Might have to open and save a piston for it to show instead of the copy window.

your green screenshot should look like this with the trace enabled.


#11

Ok, here we go:

12/11/2019, 3:46:37 PM +140ms
+0ms â•”Received event [My home].time = 1576107998297 with a delay of -1157ms
+122ms â•‘RunTime Analysis CS > 36ms > PS > 65ms > PE > 20ms > CE
+124ms â•‘Runtime (41725 bytes) successfully initialized in 65ms (v0.3.110.20191009) (123ms)
+125ms â•‘â•”Execution stage started
+143ms â•‘â•‘Comparison (time) 56797274 is_between (time) 23400000 .. (time) 81000000 = true (7ms)
+144ms â•‘â•‘Time restriction check passed
+146ms â•‘â•‘Condition #7 evaluated true (12ms)
+155ms â•‘â•‘Comparison (enum) not present is (string) not present = true (1ms)
+156ms â•‘â•‘Condition #8 evaluated true (9ms)
+164ms â•‘â•‘Comparison (enum) off is (string) on = false (1ms)
+165ms â•‘â•‘Condition #6 evaluated false (8ms)
+167ms â•‘â•‘Condition group #5 evaluated false (state did not change) (32ms)
+178ms â•‘â•‘Comparison (time) 56797309 is_between (time) 81000000 .. (time) 23400000 = false (7ms)
+180ms â•‘â•‘Condition #10 evaluated false (10ms)
+181ms â•‘â•‘Condition group #9 evaluated false (state did not change) (11ms)
+183ms ║╚Execution stage complete. (58ms)
+185ms â•‘Setting up scheduled job for Wed, Dec 11 2019 @ 3:47:38 PM PST (in 60.973s)
+194ms ╚Event processed successfully (194ms)


#12

So the log shows that it saw Switch 1 as false (OFF) and thus it evaluated the first IF as false.

Since it also saw the time in the second IF block as false (condition 10 in the piston/logs) it did not take action in that block either.

So we are to the question of Switch 1 and what it is and what its OFF/ON positions mean.


#13

Thanks for pointing this out!
I think I solved it by changing “if switch is off” to “is any of off or on” and during test last night it worked! This morning before leaving home I left light and door unlocked and sure enough after 10 minutes light was off and door was locked.

Do you see any issues with this type of approach?


#14

In reality this would nullify that switch as a condition since if wont stop or start the action from running either way. Does the piston not work if you remove it all together as a condition? Same with your switch 5.

Edit: Also again, coming back to separating actions. I would separate out commands that dont apply to a device. For example you have Switch 5, Switch 3, and Lock 1, locking and then turning off. If Switch 3 doesn’t have that lock capability it will throw an error. Group actions in different “with” based on capability/action. So it could be “with Lock 1, lock”, and then another “With Switch 1, Switch 3, Turn off”


#15

Since I’m new to all this I never thought even after looking at it 100 times that what I was putting as a condition is useless in my case :man_facepalming:

Now I have removed it and so far remotely it works! I will test more when I get home.

I have separated it now and this is how it looks:


#16

No worries, cant tell you how many times I have (and still do) the same thing!

Looks good! Just for myself I would add the conditions to prevent these from running if the objective has already been met. No need to lock the door every X minutes if it’s already locked. Reduces wear and tear on the hardware as well as programming load. So for example place a condition in both such as “and Lock 1 is unlocked”


#17

I feel not that dumb now :slight_smile:

Great idea! I think I placed this new condition at the correct spot but it looks like since its already locked it does not want to turn off switch 3 and 5 when they are left ON?

12/13/2019, 10:21:54 AM +95ms
+0ms	â•”Received event [My home].time = 1576261315250 with a delay of -1155ms
+137ms	â•‘RunTime Analysis CS > 44ms > PS > 51ms > PE > 41ms > CE
+139ms	â•‘Runtime (40523 bytes) successfully initialized in 51ms (v0.3.110.20191009) (138ms)
+140ms	â•‘â•”Execution stage started
+161ms	â•‘â•‘Comparison (time) 37314247 is_between (time) 23400000 .. (time) 84600000 = true (8ms)
+162ms	â•‘â•‘Time restriction check passed
+164ms	â•‘â•‘Condition #7 evaluated true (13ms)
+173ms	â•‘â•‘Comparison (enum) not present is (string) not present = true (2ms)
+174ms	â•‘â•‘Condition #8 evaluated true (9ms)
+184ms	â•‘â•‘Comparison (enum) locked is_not (string) locked = false (2ms)
+186ms	â•‘â•‘Condition #18 evaluated false (10ms)
+187ms	â•‘â•‘Condition group #5 evaluated false (state did not change) (36ms)
+206ms	â•‘â•‘Comparison (time) 37314286 is_between (time) 84600000 .. (time) 23400000 = false (11ms)
+209ms	â•‘â•‘Condition #10 evaluated false (17ms)
+210ms	â•‘â•‘Condition group #9 evaluated false (state did not change) (19ms)
+215ms	║╚Execution stage complete. (75ms)
+217ms	â•‘Setting up scheduled job for Fri, Dec 13 2019 @ 10:22:55 AM PST (in 60.939s)
+230ms	╚Event processed successfully (229ms)


#18

You are correct. So lets remove it from the IF as a condition and instead lets place these as restrictions on each with. When editing a piston, in the top left click the 3rd from the left button which should enable “Show restrictions”.

restr

Now it adds a “only when” restriction above each “with”. So lets place the restriction here. “only when lock 1 is unlocked” “with lock 1, lock”. rinse and repeat for all other withs.


#19

I think we have a winner here! So far it works and it should work with my presence sensor but will confirm when I get home.

Thank you again for your patience and with me! I did learn few things with this project.

I will try to help new members where ever I can.


#20

Great!! Personally have been helped by a number of people here which makes this a great community! Just trying to give back!

Enjoy!