Filter Not working as expected


#1

1) Give a description of the problem
I enabled a filter (“only when”) and it is not working as I expected it to

2) What is the expected behavior?
I have a global variable and I only want to evaluate the if statement when the global variable has a particular value

3) What is happening/not happening?
The global variable has the particular value but the event trigger is not being seen by the if statement. The piston is not running at all when the motion happens

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
I checked logs for one of the motion sensors and there was motion and its lux level was less than the global LuxValue.


#2

This is because all three lines are vague conditions…
You don’t have any precise triggers in your first block…


The way this is usually approached is something like this:

IF
    Any of Motion 3 or 4's motion CHANGES TO active        <-- Trigger
    and
    Illuminance is less than X                             <-- Condition
    and
    {@FloodMode} is equal to 2                             <-- Condition
Then
    Turn on lights
END IF

IF 
    All of Motion 3 & 4's motion stays inactive for 2 min  <-- Trigger
Then
    Turn off lights
END IF

#3

@WCmore Thank you. I was able to get things working as I wanted (at least with my minimal testing so far). Here is what I ended up with. (edited to include the updated code - first try had the original code)

Is the “only when” construct more or less efficient than adding another condition to the if statement?


#4

I’ll be honest… I don’t use conditions exclusively to activate a piston… I use one trigger, followed by as many conditions as I want. The logic is, I don’t want my piston running thru the code top to bottom unless my single trigger fires. At that point in time, I want the conditions checked.

This seems the most efficient method to me…


#5

That makes sense. I was thinking that maybe the “only when” construct somehow would subscribe/unsubscribe to trigger devices dynamically, but that actually seems unlikely.

In a similar vein, would you generally separate the three triggers I have in this piston into three separate pistons instead of leaving them all in one? There is no particular reason they need to be in the same piston and I already have other pistons that manage @FloodMode and do a daily reset of the mode to make sure the lights don’t get left in an deactivated state.


#6

My general rule of thumb is one trigger per piston… But I will occasionally use two if they are the opposites from the same device.

In your case, I would use one piston for Switch 19 “changes to on” and “changes to off”…
and a second piston for when the Motions “changes to active” and “stays inactive for X minutes”.


#7

Thank you for the feedback. I did what you suggested and made a separate piston to handle the on/off switch. At least for now, I am just using the reporting delay from the motion sensor to handle the off delay. I debated having WebCore do the delay but then I would need to set the motion sensor reporting delay to something really small because the WebCore delay would only start after all of the motion sensors go inactive.

Here is the ‘final’ piston to handle the motion from detection.


#8

Lookin’ good, Bruce… and welcome to the forums!!