CoRE and Piston Rules Engine, first design steps

OR

( Time is between 6:00pm and midnight
AND Each of the presence sensors present
AND 'Goodnight Switch' did not change in last 60 minutes)

-> when TRUE {set mode Home Evening}

This would work if i could select more than 60 minutes

This OR section needs to be false as if we’ve gone to bed before midnight and switched on the goodnight routine manually then if this section was true it would set mode back to home evening…thats if i’m understanding it correctly, which is a big if :wink:

And-If and Or-If have two completely independent condition sets. They both get evaluated and their actions executed when their true state is found. What you want is Then-If. This only evaluates the secondary IF the evaluation of the first one is true. Also, you won’t be able to use triggers in your secondary. Else-If does the opposite of Then-If, in the way that it only evaluates the secondary IF the primary is false.

Try with a Then-If.

Ok, I’ll try that. I’m not using triggers in the secondary, only conditions. The only actual trigger in the entire scenario is in the primary IF.

This is what I want.

A and (B or C or C or ((E or F)and G) or H)

see i would use it differently in a single piston

IF
( ( ( condition one) AND (condition two) ) AND (condition 3) ) THEN … this will result in what you want to do … first two must be true and then you add the 3rd one … if this is what you want to do …

Note: In order to give individual actions flexibility, I have not implemented any condition optimization mechanism between conditions. Normally, when you say (A AND B AND C) and A is false, B and C won’t be looked at anymore as they don’t have a way to alter the final result, which will obviously be false, because A is false. To allow individual actions to run, I am still evaluating each and every of the A, B, and C conditions. However, I am not doing that when you include 10 devices in one condition. When I find the first device that determines the final result, I stop looking at the others. But that’s within one single condition - it saves time not evaluating the current value of each device, especially when you’re using a list of many many devices in one condition.

Hi all,
Firstly let me apologise for my laziness.
I’ve been going through this post looking for the GitHub links to both codes and have given up.
Would someone be so kind as to post the GitHub links to both codes and also a link to the user guide (if it exists).
Thanks in anticipation.

The github link is here. Recommended install method is by adding the github repository into your IDE. Go to SmartApps, click on Settings, add a new repository: ady624 / CoRE / master. You can then Update from Repo and publish it. There is only one app, acting as both the parent and the child.

The process is also explained here.

1 Like

And this is why I can’t get it to work. I need all of the conditions of group A to be true and ask if the conditions of group B to be true before group B actions will occur

I can have an option for that. Disable optimizations :slight_smile: Then you’re code will work as expected. But be aware with OR… OR will stop at the first condition that is true, nothing after that will execute. Then you’ll have some individual actions executing and some not. And you’ll be confused :slight_smile: Unless you think like a programmer who knows the latter ANDs won’t be evaluated when one is found false, or the latter ORs won’t be evaluated when one is found true. And most people don’t think that way :slight_smile:

@ady624

I was making a change in a piston that is an And-If. I’ve sheath set up 7 groups. Now it gives Mr a red banner and says I’m not authorized when I attempt to open the piston.

Any way to get that back? Or am I stuck deleting it in the IDE and starting over?

What error to you get in the IDE? I may be able to fix it. Just another bug…

Thanks for the quick response. Must admit I thought there was two different codes. Also as for github integration, if only it was possible. I am in the UK and have raised a ticket into ST about the lack of integration and there seems to be no way STo are going to do it. Just vaige promises that it will be looked at in the future.
But I digress.

Is there a user guide?

Not yet, unfortunatelly.

I understand that, but that severely limits you to basically one Or statement.

It would serve my purpose of were evaluated and only the one that evaluated to true performes it’s actions.

EdIt
I think I read that wrong. I WANT it to stop evaluating at the first true evaluation. Each our statement is unique, therefore only one will evaluate true.

Please make that an option.

LogsClear
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:08 AM: error java.lang.ClassCastException
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:1, c:Turn on, p:] with command Turn on
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:1, c:Set level, p:[[i:0, t:number, d:10]]] with command Set level
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:1, c:Set level, p:[[i:0, t:number, d:50]]] with command Set level
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:4, c:Turn off, p:] with command Turn off
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:3, c:● Wait, p:[[i:0, t:number, d:3], [i:1, t:enum, d:minutes]]] with command Wait
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:4, c:Turn off, p:] with command Turn off
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:1, c:Set level, p:[[i:0, t:number, d:100]]] with command Set level
02c8c2e2-5ce1-4549-bb70-7e4e66d17507 9:54:07 AM: trace Task [i:2, c:Turn on, p:] with command Turn

I was talking about conditions within a condition set. Either the primary or the secondary. The And-If and Or-If are designed to evaluate both primary and secondary at the same time for the very same reason, give a chance to both to execute things on their truth evaluation.

IF
 (Condition A)
THEN 
 (Actions 1)

AND IF
 (Condition B)
THEN
 (Actions 2)

ELSE
 (Actions 3)

A is true >>> actions 1
B is true >>> actions 2
A and B both true >>> nothing
any of A or B not true >>> actions 3

Truth table:

Cond A Cond B Actions executed:
false false 3
true false 1 and 3
false true 2 and 3
true true 1 and 2

Ok, what I need is this…

A is true → nothing
B is true → nothing
A and B true → actions for B

I would need a fourth set of actions for that :slight_smile: Can be done, but it’s currently riding on other things.

You can achieve (A AND B) THEN if you use Or-If and negate both conditions for A and B.

What you want is really Then-If.

A is true > Actions A, evaluate B
A is false > Actions C (for the ELSE branch)

only when A is true, do these:
B is true > Actions B (at this point A and B are both true)
B is false > Actions C (for the ELSE branch)

Yes! This!

Now if I could just get back into that piston! Argh! ! !