Webcore not executing the piston properly


#1

I have a few IF statements in my piston. But it seems that webcore is executing one part of one IF statement and then jumping to another.

I want the light to turn to 100% brightness for 1 min when doorbell is rung and then back to 5% for the 1st IF condition. But it turns off as it executes another IF condition.

Light turns off instead of switching to 5%.


#2

If you enable the advanced functions, there is an exit command which will stop the piston when it is executed. So you could add that to the first IF so the rest doesn’t run if that is true.


#3

A couple things I noticed but not sure that they are affecting execution . . .

Your third IF statement will only test true if the dimmer is off, so the ELSE statement to turn the dimmer off doesn’t seem necessary as that statement will only run if the dimmer is already off.

What is the purpose of the Presence Sensor in the WITH’s for statements 1 and 2?


#4

I didnt have it initially but earlier, before the dimmer 1 would turn off after 30 secs, the motion would change to inactive and rest of the IF block would not execute leaving the dimmer 1 ON.

I thought I would have to include it to send me push notifications.


#5

I could not find the exit command. Are you talking about ‘task cancellation policy’?


#6

In edit piston mode:

  • Open the menu (top right)
  • Click “Show advanced statements”

Then in your piston you should get a statement called “Exit”. This interrupts the piston execution and exits immediately.


#7

Found it. I am asked for a piston value. What should that be?

Also my issue was that the piston would jump from one IF to another IF without completing the 1st IF. How does adding an exit change this? I want the piston to choose one IF according to condition and just execute that one and not mix and match between the IF blocks.


#8

For you piston turn off “automatic piston state” and then for the exit condition you can use an expression and just put in a string like “exiting due to…”


#9

I think that allows you to set a value (i.e. True/False) so that another piston can trigger from it, I just use false.

The piston isn’t jumping between IF statements, it is executing them in order. The reason it turns the light off is that the last IF statement finishes faster than the timeout set in the first IF statement. If you set the timeout in the last IF statement to 1 minute and 30 seconds you’d see the light dim before it turned off.

Now I am not sure if the first IF timeout is respected or if the third IFs timeout over writes it. You could turn on logging to see what is happening.


#10

I though to convert the ELSE to an IF. I think this should fix it. What do you think?


#11

The problem is you have a WAIT command nested inside a condition statement that will no longer be true after the wait period passes. Here is what happens:

Motion is detected or a button is pushed.
Push notification is sent and lights are set to 100%
Your piston sets a wake-up timer for 1 minute in the future.

1 minute later, your piston wakes up and evaluates your IF condition. A button push or change in motion will not have been detected, so your IF condition evaluates FALSE now… so your piston skips any commands in the “THEN” section. If you had commands in the “ELSE” section, it would execute those.

The easiest way to change this is to change your task cancellation policy on that section. Click on your WITH statement, then the gear cog at the bottom to expand settings. Change your Task Cancellation Policy to “never cancel tasks”. You’ll see there the default webCoRE setting is to cancel pending tasks if the condition of an IF statement changes.

Repeat this activity for your WITH statements that have WAITS nested in conditions that will change. Looks like your piston has 3 of them in total.

Hope this helps!


Bathroom light level based on Mode night/home
Do X after motion sensor goes inactive
Ring and light problem
My Crazy SHM View
#12

Thanks. I thought it was understood that the entire WITH section is to be executed even if there is a WAIT command.