Difference between revisions of "Piston"

From webCoRE Wiki - Web-enabled Community's own Rule Engine
Jump to: navigation, search
Line 13: Line 13:
 
A statement is the main building block of a piston script. There are two kinds of statements: ''executive'' and ''decisional''.
 
A statement is the main building block of a piston script. There are two kinds of statements: ''executive'' and ''decisional''.
  
===Executive statements===
+
====Executive statements====
 
Executive statements are the statements that ''execute'' things, they can turn lights on, they can control devices in general.
 
Executive statements are the statements that ''execute'' things, they can turn lights on, they can control devices in general.
 
* [[Action]] - Construct for executing an action
 
* [[Action]] - Construct for executing an action
  
===Decisional statements===
+
====Decisional statements====
 
In contrast with the executive statements, the ''decisional'' statements cannot control devices, but can decide and alter the execution path based on input from devices by controlling the logical flow of the execution.
 
In contrast with the executive statements, the ''decisional'' statements cannot control devices, but can decide and alter the execution path based on input from devices by controlling the logical flow of the execution.
  

Revision as of 13:42, 26 April 2017

Pistons are the constituent block of webCoRE. You can create as many pistons as you need and each will follow their script to implement the automation you need. In essence, a piston is an organized collection of basic elements, each element having its own role in the structure. The basic elements that work together are described below:


Anatomy

Section

A section groups together elements that share a role together. There are four types of sections in a piston:

  • The settings section
  • The define section
  • The function section
  • The execute section

Statement

A statement is the main building block of a piston script. There are two kinds of statements: executive and decisional.

Executive statements

Executive statements are the statements that execute things, they can turn lights on, they can control devices in general.

  • Action - Construct for executing an action

Decisional statements

In contrast with the executive statements, the decisional statements cannot control devices, but can decide and alter the execution path based on input from devices by controlling the logical flow of the execution.

Condition

Most decisional statements rely on conditions to alter the execution logical flow. A condition is a collection of one or more comparisons (described below). It returns a boolean (true/false) value that is then used by the statement to direct the flow.

Condition Group

A condition group is a collection of conditions, grouped together with a logical operator (and, or, xor, etc.)

Restriction

Effectively a downsized condition, not able to subscribe to events or execute statements on true/false evaluations (an advanced feature of conditions)

Restriction Group

A restriction group is a collection of restrictions, grouped together with a logical operator (and, or, xor, etc.)

Comparison

A comparison is a logical operation that involves one operator and one to three operands. The operator is applied to the operands and the result is returned as a boolean (true/false) value. It is the core evaluation block of webCoRE. When a comparison is performed, all the operands are evaluated and then compared using the operator.

Operator

An operator is a mathematical symbol or conditional construction that determines the type of operation to be performed. Some mathematical operators are + (addition), - (subtraction), % (modulus), & (logical AND), | (logical OR), etc. Some logical operators include is/is equal (equality), is less than, is greater than, is different than, etc.

Operand

An operand is a generic term for a value that is used in a comparison. webCoRE defines several types of operands:

  • Physical Device
A physical device operand represents one or more devices paired with an attribute. When evaluated, the attribute of the selected device is returned
  • Virtual Device
A virtual device operand represents the current state/value of a virtual device. Generally, virtual devices are entities that do not exist physically. Examples of virtual devices are Time, Location Mode, Smart Home Status, IFTTT, AskAlexa macros, EchoSistant profiles, etc.
  • Variable
A variable operand points to a variable whose value is then returned as part of the evaluation.
  • Value
A value operand is the most basic of operands, usually consisting of a constant string, integer, time, depending on the operand data type. Values are capable of containing expressions, simply include them inside curly brackets { }. Examples of values are 'on', 'Away', 'Everybody left', 77.0, 'The location mode is {$locationMode}'
An expression operand is the most advanced of operands, allowing for more complicated calculations to be performed. They allow mathematical operations, logical operations, functions, concatenation, etc. Some examples of expressions are 1 + 2, $hour * 60 + $minute, [$currentEventDevice:switch].
  • Argument
An argument operand is a way of retrieving data that has been passed to the piston through the various execution channels. For example, an IFTTT trigger can pass data to a piston, and that data can be read via the argument operands.

Expression

An expression is a complex mathematical construction that allows more advanced use of resources available to pistons. You can use an expression to calculate data based on input, such as finding out the dew point, or the average of a set of values, or the minimum value, or write a string in a desired format, etc.