Jump to content
RESET Forums (homeservershow.com)

Rule Machine for SmartThings


Recommended Posts

I've stumbled across something pretty cool in the SmartThings community.  I dare call it a forum because it needs some help in that regard.  It's called Rule Machine.  I've always wanted a way to do two or more qualificatilons then do an action.  Like IFTTT but with an extra "This."  If This and This, then do an action.  Rule machine looks like it will do it.

 

https://community.smartthings.com/t/release-rule-machine/28730

 

Now, if we could only get ST or the Rule Machine owner to embrace a forum where different questions can be asked and we can categorize discussions!  Right now, the support/announcment thread of Rule Machine is 546 comments long. 

 

 

 

Rule Machine

Rule Machine is a generalized rule engine for SmartThings. It allows you to predicate actions to be taken in SmartThings by a logical rule based on specified conditions of your system.

What are rules?

A rule is a method of specifying certain conditions and their truth relationships in order to cause some action to take place in SmartThings. For example, one person posed this case:

Suppose my presence or my wife’s presence is home, there is motion in the bedroom, it’s between 8 PM and 11 PM, and the temperature is below 65 — if those conditions are met, turn on the electric blanket.

In order for this action to take place in SmartThings, based on those conditions, a SmartApp will need to evaluate those conditions, and if they are met, cause the action. Rule Machine is a SmartApp that allows you to specify the conditions, the rule they must meet, and the desired action to take place.

What are conditions?

Rule Machine allows a wide range of possible conditions to be specified. In particular, the following capabilities in a SmartThings system can be tested. Each condition is one such test. The supported capabilities and states to be tested are the following:

Acceleration:    active / inactive
Battery: = != < > <= >= relative to a number
Certain time:    at a specified time, including sunrise / sunset with offset
Contact:    open / closed
Days of week:     [Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]
Dimmer level:     = != < > <= >= relative to a number
Energy meter:     = != < > <= >= relative to a number
Humidity:     = != < > <= >= relative to a number
Illuminance:     = != < > <= >= relative to a number
Lock:     locked / unlocked
Mode:     [ any of your location’s modes ]
Motion:     active / inactive
Power meter:     = != < > <= >= relative to a number
Presence:    present / not present
Switch:     on / off
Temperature:     = != < > <= >= relative to a number
Time of day:    between two times, including sunrise / sunset with offsets
Valve: open / closed
Water sensor: dry / wet

For each device capability, one or more devices can be selected, and the device state required for the condition to be met is selected. When multiple devices are selected, the condition may apply for ANY (default) or ALL of the devices. For example, the conditions for the electric blanket case are,

my presence or my wife’s presence is present (ANY)

bedroom motion is active

time of day is between 8:00 PM and 11:00 PM

bedroom temperature is < 65

Limitation: a rule may only have at most one each of Days of week, Mode, Certain Time, or Time of day as conditions. If you need logic for two different Time of day periods, that would have to be done in two separate rules.

How is a rule defined?

A rule is a logical expression built up using the conditions and the two logical operators AND and OR, along with parenthesized sub-rules, each of which is itself a logical expression. A logical expression defines the logical relationship between the various conditions. In order to decide if the end action should be taken or not, Rule Machine evaluates the truth of the defined rule. In the electric blanket case, we have a very simple rule:

my presence or my wife’s presence is present AND

bedroom motion is active AND

time of day is between 8:00 PM and 11:00 PM AND

bedroom temperature is < 65

There can be more complex rules than this. Suppose we want the same basic rule, but want it to apply if either bedroom motion is active or the bedroom door is closed. We would add the additional condition of “bedroom door is closed”. That rule would be this:

my presence or my wife’s presence is present AND

(bedroom motion is active OR bedroom door is closed) AND

time of day is between 8:00 PM and 11:00 PM AND

bedroom temperature is < 65

In this example, we have used parentheses to group two conditions into a sub-rule: (bedroom motion is active ORbedroom door is closed). Rule Machine allows arbitrarily complex rules to be defined, with parentheses used to group conditions into sub-rules. To use this feature of sub-rules in parentheses, you must first turn on the "Advanced Rule input" option, found under More Options at the bottom of the main page. It allows nested sub-rules to any depth, and it allows any number of conditions. To help you see exactly the rule you are building, Rule Machine displays the partial rule at each step as you define it. See screen shots in a following post.

Rule Machine is a fully generalized rule engine. The logical expression can be described as a sequence of terms, separated by operators, where each term is either a condition or a parenthesized sub-rule (available with Advanced Rule input enabled, under More Options), and the operators are AND and OR. There is no need in Rule Machine for a NOT operator, because each condition can be stated in the negative. The evaluation of a rule or sub-rule is strictly left to right. If at any point in the evaluation, the truth value preceding an AND operator is false, the sub-rule or the rule itself is false without further evaluation. Similarly, if the truth value preceding an ORoperator is true, the sub-rule or the rule itself is true without further evaluation. For those familiar with coding, there is no operator precedence. Each rule or sub-rule may have as many terms as desired.

Rule Evaluation

Once Rule Machine is installed with conditions, rule, and actions, what happens next? Whenever something happens in SmartThings that could affect the conditions, Rule Machine evaluates the rule to see if it is true orfalse. If it becomes true, then it will take some selected actions; if it becomes false, it can take some other selected actions. In the case of the electric blanket, the rule would be evaluated whenever any of the following things happen:

the state of my presence or my wife’s presence changes

the bedroom motion goes active or inactive

the bedroom door is opened or closed

the time becomes 8:00 PM, or becomes 11:00 PM

the bedroom temperature is reported

Since our rule for this case involves all of these possible events, any of those events might be the one that changes the evaluation outcome from false to true. If that happens, Rule Machine will turn on the electric blanket.

Rule Machine only acts on the change of state from false to true, or true to false. It may evaluate the rule many times, depending on what sort of events are subscribed to, but only a truth change causes action.

The evaluation of a rule is strictly from left to right. If at any point in the evaluation, the truth value preceding an ANDoperator is false, the rule is false without any further evaluation. Similarly, if the truth value preceding an ORoperator is true, the rule is true without any further evaluation. You must take this into consideration as you define your rule.

Actions

When the rule proves true, after previously false, Rule Machine will do the actions selected on the Actions for True page. When the rule proves false, after previously true, Rule Machine will do the actions on the Actions for False page. The actions supported are the following:

Switches to turn on

Switches to turn off

Switches to turn on/off after a delay

Switches to turn on/off after a delay, pending cancellation from rule state reversal

Dimmers to level A

Dimmers to level B

Locks to lock

Locks to unlock

Valves to open

Valves to close

Thermostats to set

Change mode

Run Routine

Send message

Delay the rule taking effect

 

Link to post
Share on other sites

There is a small section where smartapp discussions are.  It would be nice if you could make popular topics like Rule Machine, or even give all Community Based Smart Apps their own section in which to manage posts.  Even give them mod rights to their section.  But I'm a forums guy and that's a forums thing.  Here is a better link:

 

https://community.smartthings.com/c/projects-stories/created-smart-apps

Link to post
Share on other sites
schoondoggy

I had been patiently waiting for the release of Rule Machine.

I don't want to build this up too much, but this might fulfill some of the automations I have wanted to do.

Link to post
Share on other sites
JimBo1489090435

This is why I use the ISY, if others did true full automation that would have me consider it.

 

Sent from my Nexus 7 using Tapatalk

Link to post
Share on other sites

I played with it this weekend and setup an Alexa control for my Christmas lights. I needs a few more features, like being able to control hue color, but it works really well. I've commented on the Smarttthings forum post about it.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...