Changelog
Contents
Rules Commands
Note: mii is a random key that is generated by the client and should be used for matching the received response to the corresponding request. Maximum string length of mii is 32 characters. A unique mii should be used for each request.
Ruleslist
Command to get the list of existing rules.
Request:
{ "mii":"<random key>", "cmd":"ruleslist" }
Response:
{ "mii":"<random key>","commandtype":"ruleslist" ,"data" :{"2":{"ruleid":"2","name":"r1","valid":"1","triggers":{"1": {"triggerid":"1","triggertype":"EventTrigger","eventtype":"AlmondModeUpdated","eventid":"1","groupingtype":"AND","condition":"eq","validation":"true","value":"home"}},"results":{"1": {"resultid":"1","resulttype":"DeviceResult","deviceid":"6","deviceindex":"1","predelay":"2","validation":"true","value":"false"}}},"3":{"ruleid":"3","name":"r2","valid":"1","triggers":{"1": {"triggerid":"1","triggertype":"TimeTrigger","range":"0","hour":"5","minutes":"3","dayofmonth":"*","dayofweek":"1,2,3,4,5","monthofyear":"*","groupingyear":"AND","validaion":"true"},"2": {"triggerid":"2","triggertype":"EventTrigger","eventtype":"AlmondModeUpdated","eventid":"1","groupingtype":"AND","condition":"eq","validation":"true","value":"home"},"3": {"triggerid":"3","triggertype":"DeviceTrigger","deviceid":"6","deviceindex":"1","groupingtype":"AND","condition":"eq","validation":"true","value":"false"}},"results":{"1": {"resultid":"1","resulttype":"DeviceResult","deviceid":"20","deviceindex":"3","predelay":"0","validation":"true","value":"0"}}}} }
Createrule
Command to create a new rule.
Request
{ "mii":"<random key>", "cmd":"createrule", "rulename":"<name of rule>" }
Response
Success
{ "mii":"<random key>","commandtype":"createrule","success":"true","data":{"ruleid":"<ruleid>","rulename":"<name of rule>"} }
Failure
{ "mii":"<random key>","commandtype":"createrule","success":"false" }
Example
In the following example, a new rule with rule name ‘myrule’ is created.
{ "mii":"kjvfjk", "cmd":"createrule", "rulename":"myrule" }
Response
{ "mii":"kjvfjk","commandtype":"createrule","success":"true","data":{"ruleid":"4","rulename":"myrule"} }
Removerule
Command to remove an existing rule.
Request
{ "mii":"<random key>", "cmd":"removerule", "ruleid":"1" }
Response
Success
{ "mii":"<random key>","commandtype":"removerule.","success":"true","data":{"ruleid":"<ruleid>","rulename":"<name of rule>"} }
Failure
1 - { "mii":"<random key>","commandtype":"removerule.","success":"false","data":{"ruleid":"<ruleid>"}} 2 - { "mii":"<random key>","commandtype":"removerule.","success":"false"}
Example
In the following example, the rule with ruleid=1 is removed.
{ "mii":"dhbdc", "cmd":"removerule", "ruleid":"1" }
Response
{ "mii":"dhbdc","commandtype":"removerule.","success":"true","data":{"ruleid":"1","rulename":"myrule"} }
Addtrigger
Rule are actuated by triggers. Whenever the trigger conditions are all true the related rule is triggered. Commands described in the following section can be used to to add different types of triggers to rules.
DeviceTrigger
Command to add a device trigger in a rule.
Request
{ "mii":"<random key>", "cmd":"addtrigger", "ruleid":"<ruleid>", "triggertype":"<type of trigger>", "deviceid":"<device id>", "deviceindex":"<device index>", "indexvalue":"<index value>", "grouping":"<grouping i.e. AND/OR>", "condition":"<condition type ie.eq/le/ge/lt/gt>", "duration":"
Response
Success
{ "mii":"<random key>", "commandtype":"addtrigger.","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - { "mii":"<random key>", "commandtype":"addtrigger.","success":"false","data":{"ruleid":"<ruleid>"}} 2 - { "mii":"<random key>", "commandtype":"addtrigger.","success":"false"}
Example
In the following example, a Device with device id=1, device index=1 and indexvalue=’true’ is added as a trigger for rule with ruleid=1.
{ "mii":"idcidf", "cmd":"addtrigger", "ruleid":"1", "triggertype":"DeviceTrigger", "deviceid":"1", "deviceindex":"1", "indexvalue":"true", "grouping":"AND", "condition":"eq", "duration":"50" }
Response
{ "mii":"idcidf", "commandtype":"addtrigger.","success":"true","data":{"ruleid":"1"} }
EventTrigger
Command to add an event based trigger in a rule
Request
{ "mii":"<random key>", "cmd":"addtrigger", "ruleid":"<ruleid>", "triggertype":"<type of trigger>", "eventid":"<event id>", "eventtype":"<event type>", "eventval":"<event value>", "grouping":"< AND/OR>", "condition":"<condition type ie.eq/le/ge/lt/gt>", "duration":"<time in sec>" }
Response
Success
{ "mii":"<random key>", "commandtype":"addtrigger.","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>", "commandtype":"addtrigger.","success":"false","data":{"ruleid":"<ruleid>"}} 2 - {"mii":"<random key>", "commandtype":"addtrigger.","success":"false"}
Example
In the following example, an event with event id 1, eventtype as AlmondModeUpdated and eventvalue as home is added as a trigger to rule with ruleid 2.
{ "mii":"udfh", "cmd":"addtrigger", "ruleid":"2", "triggertype":"EventTrigger", "eventid":"1", "eventtype":"AlmondModeUpdated", "eventval":"home", "grouping":"AND", "condition":"eq", "duration":"50" }
Response
{ "mii":"udfh", "CommandType":"addtrigger.","success":"true","data":{"ruleid":"2"} }
TimeTrigger
Command to add a time based trigger.
Request
{ "mii":"<random key>", "cmd":"addtrigger", "ruleid":"<ruleid>", "triggertype":"<type of trigger>", "hours":"<hours>", "mins":"<minutes>", "dayofmonth":"<1-31,*>", "monthofyear":"<0-11,*>", "dayofweek":"<0-6,*>", "grouping":"< AND/OR>", "range":"<time in min>" }
Response
Success
{ "mii":"<random key>","commandtype":"addtrigger.","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"addtrigger.","success":"false","data":{"ruleid":"<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"addtrigger.","success":"false"}
Example
In the following example, a timetrigger with hours=1 ,min=10 and range=50 is added to the rule with ruleid=2.
{ "mii":"jdfvg", "cmd":"addtrigger", "ruleid":"2", "triggertype":"TimeTrigger", "hours":"1", "mins":"10", "dayofmonth":"*", "monthofyear":"*", "dayofweek":"1,2,3", "grouping":"AND", "range":"50" }
Response
{ "mii":"jdfvg","CommandType":"addtrigger.","success":"true","data":{"ruleid":"2"} }
Removetrigger
Command to remove a trigger in a rule.
Request
{ "mii":"<random key>", "cmd":"removetrigger", "ruleid":"<ruleid>", "triggerid":"<triggerid>" }
Response
Success
{ "mii":"<random key>", "commandtype":"removetrigger.","success":"true","data":{"ruleid":"<ruleid>" ,"triggerid":"<triggerid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"removetrigger.""success":"false","data":{"ruleid":"<ruleid>" ,"triggerid":"<triggerid>"}} 2 - {"mii":"<random key>","commandtype":"removetrigger.","success":"false"}
Example
In the following example, a trigger with triggerid 1 is removed from ruleid 2.
{ "mii":"yvgedc", "cmd":"removetrigger", "ruleid":"2", "triggerid":"1" }
Response
{ "mii":"yvgedc","commandtype":"removetrigger.","success":"true","data":{"ruleid":"2" ,"triggerid":"1"} }
Removealltriggers
Command to remove all triggers in a rule.
Request
{ "mii":"<random key>", "cmd":"removealltriggers", "ruleid":"<ruleid>" }
Response
Success
{ "mii":"<random key>","commandtype":"removealltriggers.","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"removealltriggers.","success":"false","data":{"ruleID":"<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"removealltriggers.","success":"false"}
Example
In the following command, all triggers from ruleid 1 are removed
{ "mii":"dfnc", "cmd":"removealltriggers", "ruleid":"1" }
Response
{ "mii":"dfnc","commandtype":"removealltriggers.","success":"true","data":{"ruleid":"1"} }
Addresult
Results are the actions performed when a rule is triggered. Following set of commands can be used to add different types of results to a rule.
DeviceResult
Command to add DeviceResult to a rule.
Request
{ "mii":"<random key>", "cmd":"addresult", "ruleid":"<ruleid>", "resulttype":"<type of result>", "deviceid":"<device id>", "deviceindex":"<device index>", "indexvalue":"<index value>", "predelay":"<time in sec>" }
Response
Success
{ "mii":"<random key>","commandtype":"addresult ","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"addresult ","success":"false","data":{"ruleid":"<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"addresult ","success":"false"}
Example
In the following example, a DeviceResult is added to rule with ruleid=2.
{ "mii":"rteyuwio#$%^", "cmd":"addresult", "ruleid":"2", "resulttype":"DeviceResult", "deviceid":"2", "deviceindex":"1", "indexvalue":"true", "predelay":"10" }
Response
{ "mii":"teyuwio#$%^","commandtype":"addresult ","success":"true","data":{"ruleid":"2"} }
EventResult
Command to add an EventResult to a rule.
Request
{ "mii":"<random key>", "cmd":"addresult", "ruleid":"<ruleid>", "resulttype":"<type of result>", "eventid":"<event id>", "eventtype":"<event type>", "eventval":"<event value>", "predelay":"<time in sec>" }
Response
Success
{ "mii":"<random key>","commandtype":"addresult ","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"addresult ","success":"false","data":{"ruleid":"<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"addresult ","success":"false"}
Example
In the following example, an EventResult is added to a rule with ruleid=2.
{ "mii":"ertyulkjhgf", "cmd":"addresult", "ruleid":"2", "resulttype":"EventResult", "eventid":"1", "eventtype":"AlmondModeUpdated", "eventval":"home", "predelay":"10" }
Response
{ "mii":"ertyulkjhgf","commandtype":"addresult ","success":"true","data":{"ruleid":"2"} }
SceneResult
Command to add SceneResult to rule.
Request
{ "mii":"<random key>", "cmd":"addresult", "ruleid":"<ruleid>", "resulttype":"SceneResult", "sceneid":"<sceneid>", "predelay":"<time in sec>" }
Response
Success
{ "mii":"<random key>","commandtype":"addresult ","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"addresult ","success":"false","data":{"ruleid":"<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"addresult ","success":"false"}
NetworkResult
Command to add NetworkResult to rule.
Request
{ "mii":"<random key>", "cmd":"addresult", "ruleid":"<ruleid>", "resulttype":"NetworkResult", "networkid":"1", "networkvalue":"reboot", "predelay":"<time in sec>" }
Response
Success
{ "mii":"<random key>","commandtype":"addresult ","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"addresult ","success":"false","data":{"ruleid":"<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"addresult ","success":"false"}
Removeresult
Command to remove result in a rule.
Request
{ "mii":"<random key>", "cmd":"removeresult", "ruleid":"<ruleid>", "resultid":"<resultid>" }
Response
Success
{ "mii":"<random key>","commandtype":"removeresult","success":"true","data":{"ruleid":"<ruleid>", "resultid":"<resultid>"} }
Failure
1-{"mii":"<random key>","commandtype":"removeresult","success":"false","data":{"ruleid":"<ruleid>","resultid":"<resultid>"}} 2 - {"mii":"dfnc","commandtype":"removeresult","success":"false"}
Example
In the following example, a result with resultid=2 is removed from rule with ruleid=2
{ "mii":"87984651", "cmd":"removeresult", "ruleid":"2", "resultid":"2" }
Response
{ "mii":"87984651","commandtype":"removeresult","success":"true","data":{"ruleid":"2", "Result":"2"} }
Removeallresults
Command to remove all results in a rule.
Request
{ "mii":"<random key>", "cmd":"removeallresults", "ruleid":"<ruleid>" }
Response Success
{ "mii":"<random key>","commandtype":"removeallresults","success":"true","data":{"ruleid":"<ruleid>"} }
Failure
{"mii":"<random key>","commandtype":"removeallresults","success":"false","data":{"ruleid":"<ruleid>"}} {"mii":"<random key>","commandtype":"removeallresults","success":"false"}
Example
In the following example, all results are removed from rule with ruleid=2.
{ "mii":"teoncwsi", "cmd":"removeallresults", "ruleid":"2" }
Response
{ "mii":"teoncwsi","commandtype":"removeallresults","success":"true","data":{"ruleid":"2"} }
Validaterule
Command to enable or disable a rule.
Request
{ "mii":"<random key>", "cmd":"validaterule", "ruleid":"<ruleid>", "value":"<value>" }
Response
Success
If rule is valid
{ "mii":"<random key>","commandtype":"validaterule","success":"true","data":{"value":"true","ruleid":"<ruleid>"} }
If rule is invalid
{ "mii":"<random key>","commandtype":"validaterule","success":"true","data":{"value":"false","ruleid":"<ruleid>"} }
Failure
{"mii":"<random key>","commandtype":"validaterule","success":"false","data":{"ruleid":"<ruleid>"}}} {"mii":"<random key>","commandtype":"validaterule","success":"false"}
Setpredelay
When a rule is triggered, the action can be delayed by adding a ‘predelay’ to the result in the rule. ‘Setpredelay’ command can be used to specify a predelay for a particular resultid in a rule.
Request
{ "mii":"<random key>", "cmd":"setpredelay", "ruleid":"<ruleid>", "resultid":"<resultid>" }
Response
Success
{ "mii":"<random key>","commandtype":"setpredelay","success":"true","data":{"ruleid":”<ruleid>"} }
Failure
1 - {"mii":"<random key>","commandtype":"setpredelay","success":"false","data":{"ruleid":”<ruleid>"}} 2 - {"mii":"<random key>","commandtype":"setpredelay","success":"false"}
Setrulename
Command to change the name of an existing rule.
Request
{ "mii":"<random key>", "cmd":"setrulename", "ruleid":"<ruleid>", "rulename":"<name of rule>" }
Response
Success
{ "mii":"<random key>","commandtype":"setrulename","success":"true","data":{"ruleid":"<ruleid>","rulename":"<nameof rule>} }
Failure
1-{"mii":"<random key>","commandtype":"setrulename","success":"false","data":{"ruleid":"<ruleid>,"rulename":"<name of rule>"}} 2 - {"mii":"<random key>","commandtype":"setrulename","success":"false"}
Example
In the following example, a new name is set to the rule with ruleid=2.
{ "mii":"uopup", "cmd":"setrulename", "ruleid":"2", "rulename":"newname" }
Response
{ "mii":"uopup","commandtype":"setrulename","success":"true","data":{"ruleid":"2","rulename":"newname}} }
Deleteallrules
Command to delete all rules.
Request
{ "mii":"<random key>", "cmd":"deleteallrules", }
Response
{"mii":"<random key>","commandtype":"deleteallrules","success":"true"}
Newrule
command to create a new rule.
Request
{ "mii":"<random key>", "cmd":"newrule", "rulename":"<rulename>", "triggers":"<num of triggers>", "trigger":{ "1":{ "triggertype":"<type of trigger>", "deviceid":"<device id>", "deviceindex":"<device index>", "indexvalue":"<index value>", "grouping":"< AND/OR>", "condition":"<condition type ie.eq/le/ge/lt/gt>", "duration":"<time in sec>" }, "2":{ "triggertype":"<type of trigger>", "eventid":"<event id>", "eventtype":"<event type>", "eventval":"<event value>", "grouping":"<AND/OR>", "condition":"<condition type ie.eq/le/ge/lt/gt>", "duration":"<time in sec>" } }, "results":"<num of results>", "result":{ "1":{ "resulttype":"<type of result>", "deviceid":"<device id>", "deviceindex":"<device index>", "indexvalue":"<index value>", "predelay":"<time in sec>" }, "2":{ "resulttype":"<type of result>", "eventid":"<event id>", "eventtype":"<event type>", "eventval":"<event value>", "predelay":"<time in sec>" } } }
Response
Success
{"mii":"<random key>","commandtype":"newrule","success":"true"}
Failure
{"mii":"<random key>","commandtype":"newrule","success":"false"}
Example
Following example demonstrates creating new rule with name “myrule”. It has 2 triggers, 1st trigger is DeviceTrigger and 2nd is EventTrigger and it has 2 results, 1st result is DeviceResult and 2nd is EventResult.
{ "mii":"87y68gdr", "cmd":"newrule", "rulename":"myrule", "triggers":"2", "trigger":{ "1":{ "triggertype":"DeviceTrigger", "deviceid":"6", "deviceindex":"1", "indexvalue":"true", "grouping":"AND", "condition":"eq" }, "2":{ "triggertype":"EventTrigger", "eventid":"1", "eventtype":"AlmondModeUpdated", "eventval":"home", "grouping":"AND", "condition":"eq" } }, "results":"2", "result":{ "1":{ "resulttype":"DeviceResult", "deviceid":"6", "deviceindex":"1", "indexvalue":"false", "predelay":"2" }, "2":{ "resulttype":"EventResult", "eventid":"1", "eventtype":"AlmondModeUpdated", "eventval":"away", "predelay":"2" } } }
Response
{"mii":"87y68gdr","commandtype":"newrule","success":"true"}
Editrule
Command to edit existing rule.
Request
{ "mii":"<random key>", "cmd":"editrule", "ruleid":"<rule id>", "rulename":"<rule name>", "triggers":"<num of triggers>", "trigger":{ "1":{ "triggertype":"<type of trigger>", "deviceid":"<device id>", "deviceindex":"<device index>", "indexvalue":"<index value>", "grouping":"<AND/OR>", "condition":"<condition type ie.eq/le/ge/lt/gt>" "duration":"<time in sec>" }, "2":{ "triggertype":"<type of trigger>", "eventid":"<event id>", "eventtype":"<event type>", "eventval":"<event value>", "grouping":"<AND/OR>", "condition":"<condition type ie.eq/le/ge/lt/gt>" "duration":"<time in sec>" } }, "results":"<num of results>", "result":{ "1":{ "resulttype":"<type of result>", "deviceid":"<device id>", "deviceindex":"<device index>", "indexvalue":"<index value>", "predelay":"<time in sec>" }, "2":{ "resulttype":"<type of event>", "eventid":"<event id>", "eventtype":"<event type>", "eventval":"<event value>", "predelay":"<time in sec>" } } }
Response
Success
{"<random key>":"dfnc","commandtype":"editrule","success":"true"}
Failure
{"mii":"<random key>","commandtype":"editrule","success":"false"}
Example
Following example demonstrates editing rule with ruleid=1, and name “changingrulename”. It has 2 triggers, 1st trigger is DeviceTrigger and 2nd is EventTrigger and it has 2 results, 1st result is DeviceResult and 2nd is EventResult.
{ "mii":"dhcb", "cmd":"editrule", "ruleid":"1", "rulename":"changingrulename", "triggers":"2", "trigger":{ "1":{ "triggertype":"DeviceTrigger", "deviceid":"7", "deviceindex":"1", "indexvalue":"true", "grouping":"AND", "condition":"eq" }, "2":{ "triggertype":"EventTrigger", "eventid":"1", "eventtype":"AlmondModeUpdated", "eventval":"home", "grouping":"AND", "condition":"eq" } }, "results":"2", "result":{ "1":{ "resulttype":"DeviceResult", "deviceid":"6", "deviceindex":"1", "indexvalue":"false", "predelay":"2" }, "2":{ "resulttype":"EventResult", "eventid":"1", "eventtype":"AlmondModeUpdated", "eventval":"away", "predelay":"2" } } }
Response
{"mii":"dhcb","commandtype":"editrule","success":"true"}
Notification and Event Updates
RuleAdded
When a new rule is added the following update is received.
{"commandtype":"RuleAdded","ruleid":"<ruleid>"}
Example
{"commandtype":"RuleAdded","ruleid":"1"}
RuleRemoved
When a rule is removed the following update is received.
{"commandtype":"RuleRemoved","ruleid":"<ruleid>"}
Example
{"commandtype":"RuleRemoved","ruleid":"1"}
RuleUpdated
When a rule is updated the following update is received.
{"commandtype":"RuleUpdated","ruleid":"<ruleid>"}
Example
{"commandtype":"RuleUpdated","ruleid":"1"}
RuleRemoveAll
When all the rules are removed the following update is received.
{"commandtype":"RuleRemoveAll"}