CoRE and Piston Rules Engine, first design steps

Problem fixed, coming up in next code push. Fixing the boolean variables too. Also improved the Flash function to return the switch to its original state, it was leaving it off regardless of how the light was before the Flash.

1 Like

That is exactly what I did.
Here is the entire thing…

Group one - This contains the trigger with conditions. Group one needs to be 100% true before and sub groups of group two are evaluated
(Motion changes to active and AND override is off AND pump is less or equal to one and pumping switch is off)

AND

Group two - this group had has multiple sub groups, with each sub group having is individual actions. Group One and one of these sub groups must ask be true before the sub groups individual actions can occur
((Mode is day - do these actions) or (Mode Is night - do these actions) or (Mode is evening - do these actions) or (Mode is late night - do these actions)))

Follow the colors…

Okay. Let’s recap. First off, if you need a sequence (where group two is only evaluated when group 1 is true), use Then-If. This way, the THEN IF statement only gets evaluated if your first group is true.

Secondly, if group two only has Mode conditions, you can get away with Action Restrictions.

IF (Group 1)
THEN
  ►When mode is Day
     Using location
       do this
  ►When mode is Night
     Using location
       do this

etc.

Apologies if this is common knowledge, but where is the link to download this smart app?

1 Like

Read this thread.

2 Likes

Wondering if anyone can help with this…

Piston Mode: Then-If

  If...:
        Any of 
        Motion sensor A 
        OR 
        Motion sensor B 
        is active

  Then If...:
        Home is one of [Home, Away]
        AND
        Lights Manual Override is off

  Individual Action:
  (When true)
        Using Energise scene (it is a philips hue scene, momentary button tile)
        -> Push

        Using Ceiling Lamps...:
        ->Wait 9 minutes
        ->Turn off

        Using Mood Lights...:
        ->Wait 10 minutes
        ->Turn off

Problem: Everytime motion is active, it pushes the energise scene as seen in the ‘Recently’ tab of ‘Energise scene’ momentary button tile. Possible spam pushing the momentary button tile.

If I add additional condition as follows…

  If...:
        Any of 
        Motion sensor A 
        OR 
        Motion sensor B 
        is active

  Then If...:
        Home is one of [Home, Away]
        AND
        Lights Manual Override is off
        AND  <---------------------------(additional condition)
        (Any of 
        Ceiling Lamps
        OR
        Mood Lights
        is off)           

  Individual Action:
  (When true)
        Using Energise scene (it is a philips hue scene, momentary button tile)
        -> Push

        Using Ceiling Lamps...:
        ->Wait 9 minutes
        ->Turn off

        Using Mood Lights...:
        ->Wait 10 minutes
        ->Turn off

Problem: When motion is active again after firing the first time, it does not keep the lights on (every 9 minutes the ceiling lamps light will turn off even if motion is active).

Is there any better way to do it such that it will not spam pushing the energise scene everytime motion is active and yet keep the lights on?

I was using 2 rules in RM previously:

  1. Motion active and lights is off -> Push energise scene
  2. Motion inactive and lights is on -> wait 10 mins then turn off (cancel on truth change)
1 Like

Got it… I’ll try that… Thanks.

Also, with the if-then piston… There are actually five different IF groups… Check out the chart I posted above.

If 1 is true, it does the mode restricted actions.
If 2 is true, makes 1 always false and does its own actions.
The same is true for 3,4,&5.

1 Like

Why did you use an Individual Action?

Move the actions to the THEN following the THEN IF statement.

On the Push Scene action, enable “Execute only on piston state change” - this way, the push will only happen when the piston’s state becomes true, not on any subsequent evaluations, unless the piston goes to false first and then back to true.

I cannot follow the chart. You’d need to PM me the snapshots of the piston so I can understand. But again, use Action restrictions for mode - that will simplify your piston a lot…

Ok, I’ll send all of that to you in a pm… Thanks!

1 Like

Quick question: what should trigger the whole thing? Only motion/no-motion? Can the light being turned off trigger anything? What if there is no motion but the light turns off? Would the first RM rule kick in? Or does it have to be a movement WHILE the light is off?

I’m following bamarayne’s style using Individual Action because I have another Individual Action that is suppose to run when the mode of Home is Night. I am also thinking of adding Fan and Air conditioner rules into this single piston so I would only have a single piston for a room.

The trigger for lights is motion/no-motion only. For fan and air conditioner, the trigger could be motion/no-motion/present/not-present/door open/door closed.

When I am using RM, I have set it up as a rule so I believe when the lights turn off, it will trigger the first RM rule, but if there is no movement(nobody is in the room), the light should not turn on.

1 Like

Follow the colors in this chart…

There are five IF statements… Each different. #2-4 each perform their own individual actions while also affecting statement #1 (This is the left column)

When statement 1 is true it then goes to column 3. So, when statement one is true and one of column 3 is true at the same time, column 3’s actions occur.

Statement 1 is never true when any of 2-5 are true.

This setup is working exactly… But, I had to add the condition “override switch is off” to each off the groups in column 3. Statement one is not performing as expected, it is ignoring the AND in the group and evaluating column 3 even if there is a false in statement one.

But, with the addition off the condition in column three, it all works as expected.

Questions?

2 Likes

There is no relation in the piston between 1st condition in the IF statement and the first condition in the THEN IF statement. The IF statement is evaluated as a whole, and if the result is true (you have 1 OR 2 OR 3 OR 4 OR 5 there, so many chances for that to turn true on you), then and only then it executes the THEN (regardless of which of the 5 conditions was true, in your case). I understand you are not using the THEN statement, you are only using individual actions.

Structure is
IF (condition) <<< this is the IF statement
THEN <<< actions for when the IF statement is true
THEN IF <<< this is the THEN IF statement
THEN <<< actions for when the THEN-IF statement is true
ELSE <<< actions for when either the IF statement or the THEN-IF statement is false.

Too many THENs I guess. My understanding is both THENs and the ELSE are empty in your case, you’re using individual actions on groups, right? I’ve made the statements you’re using bold.

Perhaps you want to rename the columns 2 and 4 to “individual actions” and column 3 to THEN IF

I would make the IF statement have a condition (override switch is off) AND a condition group. That condition group can then have the 5 OR’d conditions you have in column 1. #2-#4 have individual actions, but they won’t care about the override switch, as they look at only their individual group.

You know what’s missing? Piston restrictions >>> the override switch should be there, just like it is in RM, right? So that can completely disable the piston… Mode, SHM status, Disable switch and Variable restrictions… that’s what’s missing…

Do you think with this tool, you’ll ever need to start over with your whole system? I think rebuilding one of these pistons will give you that adrenaline rush…You’re hub is grateful for @ady624 s work. He’ll finally take a break from being stripped down…:slight_smile:

1 Like

But I don’t want to disable the piston, only parts of the piston, at different times.

I’ve also got it working now using a simple piston.

I’m going to write out the entire logic flow with all events and scenarios… That’s a book, give me a minute.

2 Likes

I’m building this piston using a modular thought process. Then I can make changes, remove, add, modify, without having to rebuild the entire thing.

2 Likes

That’s the way to go! And an excellent way of testing CoRE. Hats off to you for the effort…

2 Likes

I just tested this out.

[CODE]
IF
Time is between sunset and sunrise
AND
Front Door Contact is one of [open, closed]
AND
Back Door Contact is one of [open, closed]
AND
Back Garage Door is one of [open, closed]

THEN
Using Front Door
Set Level to 50%
Turn on
Using Back Door
Set level to 20%
Turn on

THEN IF
Front Door Contact is open
>>>when true>>>
Using Front Door
Set level to 100%
OR
Front Door Contact is closed
>>>when true>>>
Using Front Door
Set level to 50%
OR
Back Door Contact is open
>>>when true>>>
Using Back Door
Set level to 100%
OR
Back Door Contact is closed
>>>when true>>>
Using Back Door
Set level to 20%
OR
Back Garage Door Contact is open
>>>when true>>>
Using Outside Back Garage
Turn on
OR
Back Garage Door Contact is closed
>>>when true>>>
Using Outside Back Garage
Turn off

THEN
(leave empty)

ELSE
Using Front Door and Back Door
Turn off
[/CODE]

Everything works as expected expect for

[CODE]
Front Door Contact is open
>>>when true>>>
Using Front Door
Set level to 100%

Back Door Contact is open
        >>>when true>>> 
          Using Back Door
            Set level to 100%

[/CODE]

If I manually set those lights to 100%, while the doors are open, then close them they will dim back to their specified value, but if they are at the dimmed values and I open the door they do not go to 100%. I have another condition for back garage door that’s just a simple on/off switch. It works correctly on open and close. Not sure why to two conditional to set lights to 100% when doors opened do not work? I also have no other smartapps associated with the contacts or lights of for those.

1 Like

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.