SharpTools Rule Engine

Since getting my ST hub a few months ago, I been trying to work solely within the ST app & never used webCoRE/ifft, but I’ve run into several situations that made me have to create diff automations between SHM, Smart lighting, & main automaton settings just to create 1 thing! too complicated because there simply isn’t an option to include all the variables in 1 Spot.

So this video is very helpful for me to be able to jump right in & create anything I want in one swoop, rather than jumping into 3 diff automation setting menus inside of ST app. Thx for this!

2 Likes

Nice start, ‘if - then’ is easy, but could you also add an ‘else’? For example I want either of two motions to start a task, but how do I end if both are inactive?

@Dan_Fox You can specify actions in both THEN and ELSE paths. See the example below for your scenario. I added two motion senors as triggers, so either one will kick off the rule.

Then I use an IF_Condition to check the 1st motion sensor’s status, and take different actions. As you can see, I can also add a nested IF_Condition in the case of both them are in active status. Let me know if you need any help.

I would probably set it up something like:

Triggers: 
   motion1 == active
   motion1 != active
   motion2 == active
   motion2 != active

IF motion1 == active OR motion2 == active
   THEN doMyCoolThing()
   ELSE turnTheLightsOff()

So basically have triggers for anytime either of the the motion sensors change state (either to active or to not active).

Then the IF condition in the flow could be to make sure either sensor is active before doing your main action in the THEN. And if neither of the sensors were active, then both of them must be inactive, right? In that case, you could run your ‘end’ action there.

(Another approach would be to use multiple IF conditions in a row with different conditions if that’s more intuitive to you or better meets your needs)

One thing to keep in mind is that all triggers are effectively OR’ed together since they are always events.

IF conditions are used to check the state of one or more things. So even if something wasn’t part of the event that triggered the rule, the rule will figure out what current state the item(s) are in so it can evaluate the IF condition.

By default, IF conditions are AND’ed together (eg. when ALL of the conditions are met), but you can change the IF condition to OR (eg. when ANY of the conditions are met).

ok. what am i missing?

I basically when daddy AND mommy is “not present”.

Maybe it should be placed as an if condition but dont i need a trigger? still learning the RE.
Thanks

It looks like the flow in your screenshot will run resumeProgram on the thermostat and change the mode to Away when either of you leave.


Think of triggers as events which kick off the evaluation of the “Flow” in the rule. They are effectively OR’ed together as only one event can happen at a moment in time.

So if you goal is to run resumeProgram on the thermostat and change the mode to Away when both of you are gone, you’ll just need to add an IF condition that makes sure you are both away.

Triggers:
  Daddy presence is 'not present'
  Mommy presence is 'not present'

Flow:
   IF 
      Mommy presence is 'not present'
      AND Daddy presence is 'not present'
   THEN
      Thermostat to execute command 'resumeProgram'
      Barrett to change Mode to 'Away'

PS. We have plans to change the language to make this a bit more apparent. (eg. “Daddy changes to not present”) And perhaps we should add a little -or- between each trigger so that’s more obvious that as well.

Updated. Thank you.

Why do we even need the trigger section. The IF section should act as a trigger because it contradicts the Trigger section.

Just confusing to me.

There are cases where you want a different item to trigger the evaluation of the rule than you have in your conditions… or you don’t want the condition to act as a trigger at all.

For example, every night at 9 PM, SharpTools.io checks to see if my front door is locked and my garage is closed. If not, it sends me an SMS. In that case, the trigger is time even though the condition is the security of the doors. If the condition was implied to be the trigger, then that rule would only run when the state of either of the doors change rather than at my specified time.

Trigger:
   9 PM every night

Flow:
   IF
      Front door lock is 'unlocked'
   THEN
      Send SMS to Josh 'The front door is still unlocked'

   IF
      Garage Door is 'open'
   THEN
      Send SMS to Josh 'The garage door is still open'

Similarly, you might have a different device or location property (SHM / Mode) act as a trigger and a different item for the condition. For example, you might setup a rule where anytime the mode changes to ‘away’, the system checks if you are present in a condition and takes a different action based on that.

Trigger
   Mode changes to Away'

Flow:
   IF 
      Josh presence is 'present'
   THEN
      Delay 60 seconds
      Set SHM to 'Armed'
   ELSE
      Set SHM to 'Armed'
1 Like

makes sense! thanks.

I meant to ask or suggest… It would be nice if you could offer a way to share Rules. for example, I am going to steal This one.
Trigger:
9 PM every night

Flow:
IF
Front door lock is ‘unlocked’
THEN
Send SMS to Josh ‘The front door is still unlocked’

IF
Garage Door is ‘open’
THEN
Send SMS to Josh ‘The garage door is still open’

It would be nice to be able to import it an replace the specifics to mine. You can do this in webcore. Just a thought…
Thanks!

It’s high on the hitlist along with simplifying the rule creation process (there are too many dropdowns currently)!

Glad your thinking about it.

I am still high on being able to choose multiple items in a dropdown… :slight_smile: It is a large reason I havent moved more over. I have the attention span of a gnat… lol

Product is looking awesome!

Tried coping your lock/garage one above. image
says error creating timing schedule.
How do you get yours to say 9pm every night when mine says 2200 and repeat daily.

Really feel like the newb!!

Hm. That is an unexpected result. Can you try opening up that rule again and resaving it? @James is looking into the server logs to see if anything seems out of the ordinary. :slight_smile:

My apologies - I was just generalizing the rule structure. You’re right that the proper text would be something like Trigger rule at 21:00 and repeat daily. The upcoming development release displays the time in your locale and will default to repeat ‘daily’ now.

Here’s what my actual rule in production looks like (I also have a Pushbullet message that goes out just below the SMS action which isn’t pictured in the screenshot).


Tried again. This rule was one I had before that I changed. I am going to create a “new” rule to do this and see if I get the same error. I will attempt to save again for your benefit of seeing the logs.

EDIT. I cancelled out and went back in and it was saved accurately… Not sure what happened.

No worries. I liked your rule structure… :slight_smile:

Is there a place I can see logs of rules etc?

If you save that same rule again (after having cancelled and reopened it), does it save successfully?

Out of curiosity, what kind of structure did the old rule have? Trying to see if I can recreate it. :slight_smile:

User facing rule execution logs are on the hit list.

1 Like

Yes.

One that didnt work… lol… I think the trigger was the garage doors. and i changed to time base trigger.

1 Like

@Tommy, thanks for reporting the issue. We found the bug and got it fixed (will be included in the next release). This only happens when a rule has a device event, but then replaced with the timer event.

2 Likes

For the trigger part, may I know if it can be “AND” Condition as well to have multiple trigger condition are met then execute the flow.

e.g. When motion sensor is activated and the time is between sunset and sunrise. --> then execute the flow.

1 Like

Hi @Jason_Chan, welcome to the community. Trigger conditions can only be OR. But you can add an If_condition as the first activity in the flow and the desired actions in the Then path. See the screenshot below for your scenario. The rule will be triggered whenever there’s a motion, but the first thing it does is to evaluate the time condition (between sunset and sunrise) to determine if it should continue to execute the action(s) defined. The trick here is to add “before sunrise” and “after sunset” conditions and change the If_condition logic from “any” (default) to “all” to get you the “between sunset and sunrise” condition. :wink:

2 Likes

5 posts were split to a new topic: Only Allow Rule to Run Once a Day