Page tree
Skip to end of metadata
Go to start of metadata

Actions are the way to configure automated tasks based on time like sunset or sunrise, or based on device attribute states or commands emitted by them. The most typical example is to use this resource to schedule irrigation programs for the garden or to use sunset for lighting. For more details about this resource schema, refer to Action. Please keep in mind that Actions are termed as Automation Rules for Smartenit App end users.

An Action can be described as a container that allows you to use Conditions (rules) and Effects (triggers) in a logical expression.  For example, the conditions and effects for an action for irrigation would look like this:

// Between 6AM and 10AM
var morning_condition = {
	"_id":"507f1f77bcf86cd799439021",
	"name": "Morning",
	"path": "/devices/507f191e810c19729de860ea/time",
	"value": { "#from": "6:00am", "#to": "10:00am"}
};

// Humidity less than 80%
var humidity_condition = {
	"_id":"507f1f77bcf86cd799432011",
	"name": "Humidity lesser than 80%",
	"path": "/devices/507f191e810c19729de860ea/1/RelativeHumidityMeasurement/MeasuredValue",
	"value": { "#lt": "80"}
};
 
// Start the program #2
var start_program_effect = {
	"_id":"507f1f77bcf86cd799435011",
	"name": "Trigger irrigation program",
	"path": "/devices/507f191e810c19729de86012/1/OnOffArray/ProgramOn",
	"parameters": { "ProgramId": 2},
    "delay": 5
};

Once these resources are created, it is possible to construct an action with the next information:

 var action = {
	"name": "Irrigation Wizard",
	"enabled": "true",
	"days": "weekdays",
	"expression": {
		"#if": "${time_window} && ${humidity_cond}",
		"#then": ["${start_program}"]
	},
	"parameters": {
		"time_window": "507f1f77bcf86cd799439021",
		"humidity_cond": "507f1f77bcf86cd799432011",
		"start_program": "507f1f77bcf86cd799435011"
	}
};

 

As shown above, there are special operators that can be used for the condition comparisons. These operators are explained in the next table:

OperatorDescriptionExample
#from

Used mainly for creating range conditions as a time window for a DateTime attribute or a safe operation range for a Voltage attribute. Used alone would be equivalent to the $greater operator.

"#from": "8:05am"
"#from": 122.88
#to

Used mainly for creating range conditions as a time window for a DateTime attribute or a safe operation range for a Voltage attribute. Used alone would be equivalent to the $lesser operator.

"#to": "6:30pm"
"#to": 132.44
#random

Used in conjunction the $from and $to operators in a DateTime attribute will cause the evaluator to mark this comparison as true once during the range. It useful to create a random condition during a time window.

"#random": true
#crontabUsed for DateTime attribute works to create a periodic condition following the crontab format.
"#crontab": "* * * * 1,2,3,4"
"#crontab": "* * 1 * *"
"#crontab": "* * * 1 *"
#gtGreater than the value specified.
"#gt": 122.88
#gteGreater than or equal to the value specified.
"#gte": 122.8
#ltLesser than the value specified.
"#lt": 132.44
#lteLesser than or equal to the value specified.
"#lte": 132.4
#neNot equal to the value specified.
"#ne": 3
#bitmask

Used for bit masking operations, mostly used for getting information from bitmap attributes.

"#bitmask": 3
#regexpUsed for regular expressions comparisons.
"#regexp": "(\bSaving\b|\bOpportunity\b)"
#tzUsed in conjunction with #from and #to, it indicates the client's timezone to parse natural language correctly. The format for this value is "-hh:mm" or "+hh:mm"
"#tz": "-05:00"
#intervalUsed to repeat a condition over time, the format for this value is "d h m" indicating day hour and minute. A value of 0 indicates no preference.
"#interval": "4 5 0"

 

Additionally, any device attribute or command emitted can be used as a valid condition. Following are some other usage examples:

// True at 8:05pm everyday using local TZ
var condition = {
	"name": "Absolute time",
	"enabled": true,
	"path": "/devices/507f191e810c19729de860ea/time",
	"value": "8:05pm"
};

// True between Sunrise to Sunset
var condition1 = {
	"name": "Sunrise to sunset",
	"enabled": true,
	"path": "/devices/507f191e810c19729de860ea/time",
	"value": {
		"#from": "sunrise",
		"#to": "sunset"
	}
};

// True between Sunrise to 3:10pm
var condition2 = {
	"name": "Sunrise to absolute time",
	"enabled": true,
	"path": "/devices/507f191e810c19729de860ea/time",
	"value": {
		"#from": "sunrise",
		"#to": "3:10pm"
	}
};

// Trigger once randomly between 6pm and 830pm
var condition3 = {
	"name": "Random condition",
	"enabled": true,
	"path": "/devices/507f191e810c19729de860ea/time",
	"value": {
		"#from": "6:00pm",
		"#to": "8:30pm",
		"#random": true
	}
};

// Interval with 60secs as period
var condition4 = {
	"name": "Periodic condition",
	"enabled": true,
	"path": "/devices/507f191e810c19729de860ea/time",
	"value": {
		"#period":"60"
	}
};

// Temp > 10.54 && Temp < 23.45 
var condition5 = {
	"name": "Temperature in range",
	"path": "/devices/507f191e810c19729de860ea/1/TemperatureMeasurement/aMeasurementValue",
	"value": {
		"#from": "10.54",
		"#to": "23.45"
	}
};

// Temp > 23.45C && Temp < 10.54C
var condition6 = {
  "name": "Temperature out range",
  "path": "/devices/507f191e810c19729de860ea/1/TemperatureMeasurement/aMeasurementValue",
  "operation": "NotEqual"
  "value": {
	"#lt": "10.54",
	"#gt": "23.45"
  }
};
 
// Instantaneous Demand > 60W
var condition7 = {
  "name": "High Instantaneous Demand",
  "path": "/devices/507f191e810c19729de860ea/1/SimpleMetering/aInstantaneousDemand",
  "value": {
    "#gt": 0.060
  }
};

// Motion sensor detected, bitmask using 0x03 for checking if bit 0 or 1 is set
var condition7 = {
  "name": "Motion sensor detected",
  "path": "/devices/507f191e810c19729de860ea/1/IASZone/ZoneStatusChangeNotification.ZoneStatus",
  "value": {
    "#bitmask": 3
  }
};

// Regular expression condition
var meter_message = {
  "name": "publish message",
  "path": "/devices/507f191e810c19729de860ea/1/Messaging/PublishMessage.Message",
  "value": {
    "#regexp": "(\bSaving\b|\bOpportunity\b)"
  }
};

// Weather in a custom latitude-longitude using pseudo devices
// 1. Create a weather device and set latitude and longitude accordingly
// 2. Configure attribute to read and periodically
// 3. Create action using this condition
var weather_condition = {
  "name": "publish message",
  "path": "/devices/507f191e810c19729de860ea/1/YahooWeather/WindSpeed",
  "value": {
    "#gt": 11.57
  }
};
  • No labels