Else if TCP not resetting wait on condition state


#1

1) Give a description of the problem
I’m completely new in WebCoRE and I’m trying to understand some basics here … Wait doesn’t gets reset if condition (motion sensor off) is lost and it’s exected anyway

2) What is the expected behaviour?
If motion detected again within 30 seconds reset wait and don’t execute it

3) What is happening/not happening?
in this case here, after no motion is detected after 30 seconds lights turn off no matter if motion is detected again in the meantime. Wait doesn’t seem to get reset on condition lost.

In the following cases wait does however get reset and light stays on

a) if I move the else if statement outside of the if statement and put it in separate if statement after, so I have 2 if statements one after another, instead of if and else if
b) If I remove condition that any of the lights switch is off to run the if statement (line 21), in which case if statement is actually TRUE again if motion is detected again, which skips the else if statement and in that way wait gets reset.

This makes me think that else if statement might be buggy, but I’m not really sure.
Any help/explanation will be appreciated

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

5) Attach logs after turning logging level to Full

23.3.2022, 23:06:18 +167ms
+1ms ╔Received event [Xiaomi Aqara Motion Sensor].motion = inactive with a delay of 31ms
+37ms ║RunTime Analysis CS > 12ms > PS > 4ms > PE > 21ms > CE
+39ms ║Runtime (39760 bytes) successfully initialized in 4ms (v0.3.114.20220203) (37ms)
+40ms ║╔Execution stage started
+50ms ║║Comparison (integer) 11 is_less_than_or_equal_to (integer) 30 = true (1ms)
+52ms ║║Condition #4 evaluated true (7ms)
+55ms ║║Comparison (enum) inactive changes_to (string) active = false (1ms)
+56ms ║║Cancelling condition #3's schedules...
+57ms ║║Condition #3 evaluated false (5ms)
+58ms ║║Condition group #1 evaluated false (state did not change) (15ms)
+98ms ║║Comparison (enum) off is (string) on = false (2ms)
+100ms ║║Comparison (enum) off is (string) on = false (1ms)
+102ms ║║Comparison (enum) off is (string) on = false (1ms)
+104ms ║║Comparison (enum) off is (string) on = false (1ms)
+106ms ║║Cancelling condition #20's schedules...
+106ms ║║Condition #20 evaluated false (47ms)
+107ms ║║Condition group #18 evaluated false (state did not change) (48ms)
+109ms ║╚Execution stage complete. (69ms)
+110ms ╚Event processed successfully (110ms)
23.3.2022, 23:05:37 +32ms
+0ms ╔Received event [Mitt hjem].time = 1648073138253 with a delay of -1221ms
+47ms ║RunTime Analysis CS > 17ms > PS > 5ms > PE > 25ms > CE
+50ms ║Runtime (39749 bytes) successfully initialized in 5ms (v0.3.114.20220203) (48ms)
+51ms ║╔Execution stage started
+99ms ║║Executed physical command [E27 carport 1].off() (15ms)
+100ms ║║Executed [E27 carport 1].off (17ms)
+257ms ║║Executed physical command [E27 carport 2].off() (154ms)
+258ms ║║Executed [E27 carport 2].off (155ms)
+275ms ║║Executed physical command [E27 carport 3].off() (14ms)
+276ms ║║Executed [E27 carport 3].off (15ms)
+293ms ║║Executed physical command [E27 carport 4].off() (14ms)
+294ms ║║Executed [E27 carport 4].off (16ms)
+297ms ║╚Execution stage complete. (246ms)
+301ms ╚Event processed successfully (301ms)
23.3.2022, 23:05:33 +434ms
+1ms ╔Received event [Xiaomi Aqara Motion Sensor].motion = active with a delay of 84ms
+36ms ║RunTime Analysis CS > 11ms > PS > 5ms > PE > 19ms > CE
+38ms ║Runtime (39757 bytes) successfully initialized in 5ms (v0.3.114.20220203) (36ms)
+39ms ║╔Execution stage started
+49ms ║║Comparison (integer) 11 is_less_than_or_equal_to (integer) 30 = true (1ms)
+50ms ║║Condition #4 evaluated true (8ms)
+53ms ║║Comparison (enum) active changes_to (string) active = true (0ms)
+55ms ║║Cancelling condition #3's schedules...
+56ms ║║Condition #3 evaluated true (4ms)
+92ms ║║Comparison (enum) on is (string) off = false (1ms)
+94ms ║║Comparison (enum) on is (string) off = false (1ms)
+96ms ║║Comparison (enum) on is (string) off = false (1ms)
+98ms ║║Comparison (enum) on is (string) off = false (1ms)
+99ms ║║Cancelling condition #19's schedules...
+100ms ║║Condition #19 evaluated false (44ms)
+101ms ║║Condition group #1 evaluated false (state did not change) (59ms)
+136ms ║║Comparison (enum) on is (string) on = true (1ms)
+137ms ║║Condition #20 evaluated true (35ms)
+141ms ║║Comparison (enum) active is (string) inactive = false (1ms)
+142ms ║║Cancelling condition #12's schedules...
+143ms ║║Condition #12 evaluated false (5ms)
+144ms ║║Cancelling condition #18's schedules...
+145ms ║║Condition group #18 evaluated false (state changed) (43ms)
+147ms ║╚Execution stage complete. (109ms)
+148ms ║Setting up scheduled job for Wed, Mar 23 2022 @ 11:05:38 PM CET (in 4s)
+157ms ╚Event processed successfully (157ms)
23.3.2022, 23:05:08 +117ms
+1ms ╔Received event [Xiaomi Aqara Motion Sensor].motion = inactive with a delay of 38ms
+48ms ║RunTime Analysis CS > 14ms > PS > 9ms > PE > 25ms > CE
+50ms ║Runtime (39758 bytes) successfully initialized in 9ms (v0.3.114.20220203) (48ms)
+51ms ║╔Execution stage started
+63ms ║║Comparison (integer) 4 is_less_than_or_equal_to (integer) 30 = true (2ms)
+64ms ║║Condition #4 evaluated true (9ms)
+68ms ║║Comparison (enum) inactive changes_to (string) active = false (0ms)
+70ms ║║Cancelling condition #3's schedules...
+71ms ║║Condition #3 evaluated false (5ms)
+72ms ║║Cancelling condition #1's schedules...
+73ms ║║Condition group #1 evaluated false (state changed) (17ms)
+112ms ║║Comparison (enum) on is (string) on = true (2ms)
+115ms ║║Cancelling condition #20's schedules...
+116ms ║║Condition #20 evaluated true (42ms)
+123ms ║║Comparison (enum) inactive is (string) inactive = true (2ms)
+124ms ║║Condition #12 evaluated true (7ms)
+125ms ║║Cancelling condition #18's schedules...
+126ms ║║Condition group #18 evaluated true (state changed) (53ms)
+128ms ║║Cancelling statement #13's schedules...
+134ms ║║Executed virtual command [E27 carport 1, E27 carport 2, E27 carport 3, E27 carport 4].wait (0ms)
+136ms ║║Requesting a wake up for Wed, Mar 23 2022 @ 11:05:38 PM CET (in 30.0s)
+140ms ║╚Execution stage complete. (89ms)
+141ms ║Setting up scheduled job for Wed, Mar 23 2022 @ 11:05:38 PM CET (in 29s)
+147ms ╚Event processed successfully (147ms)
23.3.2022, 23:04:23 +110ms
+1ms ╔Received event [Xiaomi Aqara Motion Sensor].motion = active with a delay of 93ms
+47ms ║RunTime Analysis CS > 13ms > PS > 4ms > PE > 29ms > CE
+49ms ║Runtime (39764 bytes) successfully initialized in 4ms (v0.3.114.20220203) (47ms)
+50ms ║╔Execution stage started
+61ms ║║Comparison (integer) 4 is_less_than_or_equal_to (integer) 30 = true (2ms)
+62ms ║║Condition #4 evaluated true (8ms)
+66ms ║║Comparison (enum) active changes_to (string) active = true (1ms)
+67ms ║║Cancelling condition #3's schedules...
+68ms ║║Condition #3 evaluated true (5ms)
+107ms ║║Comparison (enum) off is (string) off = true (2ms)
+109ms ║║Condition #19 evaluated true (40ms)
+110ms ║║Cancelling condition #1's schedules...
+111ms ║║Condition group #1 evaluated true (state changed) (57ms)
+113ms ║║Cancelling statement #8's schedules...
+131ms ║║Executed physical command [E27 carport 1].on() (13ms)
+132ms ║║Executed [E27 carport 1].on (15ms)
+147ms ║║Executed physical command [E27 carport 2].on() (12ms)
+148ms ║║Executed [E27 carport 2].on (13ms)
+162ms ║║Executed physical command [E27 carport 3].on() (11ms)
+163ms ║║Executed [E27 carport 3].on (13ms)
+178ms ║║Executed physical command [E27 carport 4].on() (11ms)
+178ms ║║Executed [E27 carport 4].on (13ms)
+181ms ║╚Execution stage complete. (131ms)
+182ms ╚Event processed successfully (182ms)

#2

For what it’s worth, with thousands of pistons under my belt, I do not use ELSE IF directly.
…although I may structure like this:

IF Trigger changes to A
THEN
   do stuff
ELSE  (executes when Trigger changes away from A)
   IF ConditionB
   THEN
      Do other stuff
   ELSE
      Do default stuff
   END IF
END IF

This method only works if the top level remains the only trigger
(with conditions indented)


For newbies (and typical uses), I’d likely code like you mentioned:

IF motion changes to active
Then
   Do stuff
END IF

IF motion changes to inactive (or stays inactive for X)
Then
   Do other stuff
END IF

#3

Thanks. I’m a long time PLC programmer with an in-depth understaning of SCL programming language and I’m used to cyclical programming, meaning the code always excecutes. I use ELSE IF quite often and it should evaluate the condition only if the above IF condition is NOT fullfilled.

As a part of my self “training” with this simple function I tried with both condition and trigger for turning off the lights after 30 seconds of no motion. What I found out is that trigger (stays inactive for 30s) works great, as it shedules an execution 30s after fullfilment. However condition (was inactive for 30s) doesn’t really work since the piston is NOT execution after 30s since it’s not being scheduled and there is no change in event (motion). This was interesting to learn.

Back to the ELSE IF … Still can’t undersatnd why Wait doesn’t get reset here. Could this be a bug? Now I tried with your suggestion with ELSE and it works, Wait resets. But why? It is identical flowchart.

I tested againwith the use 2 IF’s instead and works like a charm as well!

Here is the code with the ELSE solution which works fine. Do you have any clue why ELSE IF doesn’t seem to work? Am I missing something here.

P.S. changed lux activation temporarily just to get it activated now during the daylight


#4

Me neither. As far as I can see you are using the default TCP and the ‘else if’ condition group has been evaluated and changed state since the scheduled task was created. It isn’t clear why the task wasn’t cancelled.

As you say it up is logically the same as the version that does work so we aren’t imagining things.


#5

Thanks for the confirmation. Looks to me that the ELSE IF function is really buggy! Any place I can escalate this further?

I’m aware that with coming transfer to ST Edge and loss of Groovy and subsequently webCoRE there might not be much interest in pursing this further however.

I only started with webCoRE 2 days ago and I love it, I would like to write my own code instead of inserting on boxes but it’s fun anyway.

Too bad it is being discontinued with the loss of Groovy. Will there be any subsitutions, alternatives or maybe even rebuilt webCoRE for Edge, once Groovy will get burried?


#6

SmartThings are moving towards the ‘Rules API’ as a Rules Engine capable of hub and cloud based execution. They have always acknowledged webcoRE as representative of the level of capabilities they want to achieve though it has to be said that the public API has been progressing at a surprisingly slow rate, and although the mobile app has access to some undocumented features for use with Routines, none of those look particularly game changing.

Back in October 2019 ST demonstrated a proof of concept of webCoRE reimagined as a front end for the Rules API. The idea was that the community would take this forward. However the community seems to have largely got the impression that ST would be doing this so nothing happened, and the Rules API has barely progressed anyway, with what there is seeming to be diverging from webCoRE’s way of doing things. So unless someone has been doing a lot of work on the quiet, that seems to be a dead end.

It should be possible for webCoRE to continue on Hubitat, if developer support in ongoing, though I suppose there might be a question mark over the third party hosting side of things.


#7

If you run this on Hubitat and have issues, let me know and we can investigate if this issue is there.


#8

It works wonderfully… If placed on separate lines. IE:

IF TriggerA
Then 
   X
Else
   IF ConditionB
   Then 
      Y
   Else 
      Z
   END IF
END IF

Note: Only A can be a trigger in this example.


#9

I don’t have Hubitat


#10

I know, I published the code … but the question is why? ELSE IF is obviously buggy


#11

It is good to have programming background, but we should not expect all languages to work identically.
(it’s better to approach with a clean slate, IMO)


#12

I agree, but I can’t come to other conclusion that ELSE IF is not working properly, or better to say TCP of ELSE IF function. @orangebucket agrees here

Doesn’t really matter since there are bunch of other ways of acheiving the same goal. This was more for my understanding


#13

You may be right. I do not have the free time to go thru your logs at the moment.


Personally, I like the compartmentalization of having my ELSE IF on two separate lines

It allows for the block(s) to be copied or dragged easily, as well as disabling/enabling individual blocks (great during testing or saving previous iterations),…

IMO, these are huge timesavers!
(which is why I never pursued single line ELSE IFs)


#14

If you can give me a small reproducer of it failing, that will help.

My simple test shows else if working, but perhaps there a second order thing you think is not working?

On ST, you need to be careful in if statements of putting conditions before triggers (with OR), as some of the condition optimizations are not doing the right thing when you mix. That said it is not obvious to me that the error is happening here.

else if effectively nests trigger comparisons, but again in this example I don’t see it…


#15

Ok, I have a thought

there is a subtle difference in

in the two forms shown

the else if version, the controlling statement # is still the original if

vs in the other example, each if is its own controlling statement…

controlling statements matter for TEP and TCP of course…


#16

I never noticed this before… Excellent sleuthing!!


#17

I’m trying out a fix on HE for this…


#18

I’ve never found it helpful that the piston can show statement numbers that the log doesn’t use, and vice versa. It means you can never be sure what the absence of a number tells you.

I was trying to decide if the behaviour we are seeing is by accident or design. I think it is broken regardless.


#19

I think it is broken and I have a fix in the works so others can help me determine correct operation.

Ian recently added a couple more statement/condition prints to the UI, and I’ve updated HE to more clearly show for wakeup requests and cancels, what is the wakeup (statement controls, and start point), or for cancels what is being canceled.


#20

Thanks for clarification! I did several more pistons today and I’m loving it!

ST automations are sooo lame compared to webCoRE, I hope it won’t be gone!