How do I structure if/then pistons? Presence sensor question


#1

1) Give a description of the problem
My tests are failing now that I’ve added conditions to a piston

2) What is the expected behavior?
The ecobee switch to home when either me or my wife are present. Switches to away when we are both gone (anytime), and switches to night when either of us are here and it’s between 9PM and 430AM

3) What is happening/not happening?
The test is failing even though it worked fine when i just had the one piston to set it to home when either of us are home

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


5) Attach any logs (From ST IDE and by turning logging level to Full)
3/16/2019, 10:30:56 AM +987ms
+0ms ╔Received event [Home].test = 1552750256986 with a delay of 0ms
+48ms ║RunTime Analysis CS > 15ms > PS > 8ms > PE > 25ms > CE
+51ms ║Runtime (40160 bytes) successfully initialized in 8ms (v0.3.10a.20190223) (49ms)
+53ms ║╔Execution stage started
+74ms ║║Condition #2 evaluated false (13ms)
+76ms ║║Condition group #1 evaluated false (state did not change) (16ms)
+93ms ║║Condition #6 evaluated false (15ms)
+96ms ║║Condition group #5 evaluated false (state did not change) (18ms)
+119ms ║║Comparison (time) 37857087 is_between (time) 72060000 … (time) 14460000 = false (13ms)
+122ms ║║Condition #11 evaluated false (22ms)
+123ms ║║Condition group #9 evaluated false (state did not change) (25ms)
+127ms ║╚Execution stage complete. (74ms)
+129ms ╚Event processed successfully (129ms)


#2

I don’t have freetime to examine your code right now, but be aware that the TEST button should not be used to test this piston. (The piston triggers when either Presence Sensor 1 or 2 changes)


Also, if you ever happen to arrive home between 8:00:00 and 8:00:59 PM, then nothing will happen. Likewise, if you ever come home between 4:00:00 and 4:00:59 AM, your time will match both your first and your last block.


#3

Also, I believe (not sure) that both presence sensors would have to change to “not present” at or near the same time to execute the with.


#4

Agree with all the comments above. First thing with if/then is to avoid using else unless it is a very simple condition or the else can be executed unexpectedly. Note that your time condition will never be triggered (no lightning bolt). I suggest you combine your firs and last condition like this:

if any of presence sensor 1 or presence sensor 2' presence changes                    <--trigger
then
  if all of presence sensor 1 and presence sensor 2 presence are not present.       <--condition
  then
    'away'
  else
    if time is between 8 PM and 4 AM        <--condition
    then
      'night'
    else
      'home'
    endif
  endif
endif

This gets you down to a single trigger and then conditions to determine the right action. This should do what you want without the potential conflicts.


#5

:+1:


#6

I have to say reading your posts and others on this forum has really helped me understand how webcore works and better programming techniques for this platform. Thank you for all you do here.


#7

Now i think I have the structure down, but my presence sensors aren’t very rapid at showing me away from home. I went and shopped at walmart and my “send push notification to my phone” didn’t happen (but an IFTTT with my garage door worked!). Any tips on how to fix that? Do I need to erase the “work” location I added to the smartthings app or do I need to set up “Home” as a global variable?


#8

Thanks for your kind words @guxdude, that means a lot.

This is by far the best online community I have ever been a part of.
There is so much innovation and respect for others here.
It seems only right for me to give back whenever I can.


#9

Presence sensors on the phone are notoriously flaky but they usually show away as soon as you get outside the nominal range. I once had my phone get ‘stuck’ when’re it always showed me home in SmartThings. The only way I was able to resolve it was to remove my phone and re-add it. A bit of a pain, though, since then you have to re-add to Webcore and fix any pistons where it is referenced. I have started trying to use more variables for just this reason to make it easier to fix when I have to re-add or replace something.