Websockets Documentation

From SecuriWiki
Revision as of 12:16, 12 May 2016 by Securifi (Talk | contribs)

Jump to: navigation, search

Websocket is the protocol for establishing an interaction channel between an external application and Almond. It is also possible to receive event-based notifications. Websocket can be used to control smart devices that are paired with Almond and build smart applications around it.

Authentication

In order to connect to the webserver - first specify a web-interface url, then the portid - 7681 followed by web-interface login password.

<webinterfaceUrl>:<portid>/<Login>/<password>

Example ws://10.10.10.254:7681/root/frank

Device 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

Devicelist

Command to get the list of sensors and other smart devices associated with the almond.

Request

{  
 "mii":"<random key>",
 "cmd":"devicelist"
}

Response

{ 
 "mii":"<random key>","commandtype":"devicelist","data" : {"1":{"devicename":"ContactSwitch #1","friendlydevicetype":"ContactSwitch","devicetype":"12","deviceid":"1","location":"Default","devicevalues":
 {"1":   {"index":"1","name":"STATE","value":"true"},"2":{"index":"2","name":"LOW BATTERY","value":"0"},"3":{"index":"3","name":"TAMPER","value":"true"}}},"2":{"devicename":"BinarySwitch 
 #2","friendlydevicetype":"BinarySwitch","devicetype":"1","deviceid":"2","location":"Default","devicevalues":{"1":{"index":"1","name":"SWITCH BINARY","value":"true"}}}}
}

Setdeviceindex

Command to set the device index value without timeout.

Request

{  
 "mii":"<random key>",
 "cmd":"setdeviceindex",
 "devid":"<device id>",
 "index":"<deviceindex>",
 "value":"<indexvalue>"
}

Response
Success

{ 
 "mii":"<random key>","commandtype":"setdeviceindex","success":"true","data":{"devid":"<deviceid>","index":"<deviceindex>","value":"<indexvalue>"}
}

Failure

{
 "mii":"<random key>","commandtype":"setdeviceindex",:"success":"false"}
}


Example
In the following example, the value of index 1 is set to ‘true’ for device id 2.

{
 "mii":"jdnbc",
 "cmd":"setdeviceindex",
 "devid":"2",
 "index":"1",
 "value":"true",
}

Response

{
 "mii":"jdnbc","commandtype":"setdeviceindex","success":"true","data":{"devid":"2","index":"1","value":"true"}
}

Getdeviceindex

Command to get the value of a device index. Request

{  
 "mii":"<random key>",
 "cmd":"getdeviceindex",
 "devid":"<deviceid>",
 "index":"<deviceindex>"
}

Response
Success

{
 "mii":"<random key>","commandtype":"getdeviceindex","success":"true","data":{"devid":"<deviceid>","index":"<deviceindex>","value":"<indexvalue>"}
}

Failure

{
 "mii":"<random key>","commandtype":"getdeviceindex","success":"false"
}

Example In the following example, value of index 1 is retrieved for device id 2.

{ 
 "mii":"jdnbc", 
 "cmd":"getdeviceindex",
 "devid":"2",
 "index":"1"
}

Response

{
 "mii":"jdnbc","commandtype":"getdeviceindex","success":"true","data":{"devid":"2","index":"1","value":"false"}
}

Editdevicename

Command to edit name and location of a device.
Request

{ 
 "mii":"<random key>",
 "cmd":"editdevicename",
 "devid":"6",
 "name":"newswitchsss",
 "location":"default"
}

Response
Success

{  
 "mii":"<random key>","commandtype":"editdevicename","success":"true"
}

Failure

{  
 "mii":"<random key>","commandtype":"editdevicename","success":"false"
}

Updatealmondmode

Command to change the almond mode.
Request

{
  "mii":"<random key>",
  "cmd":"updatealmondmode",
  "mode":"<mode i.e.  2/3>",
  "emailid":"<email id>"
}

Response
Success

{
 "mii":"<random key>","commandtype":"updatealmondmode","success":"true","data":{"mode":"2","emailid":"swetha.reddy@securifi.com"}
}


Failure

{
 "mii":"<random key>","commandtype":"updatealmondmode","success":"false"
} 


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:

{“CommandType":"RuleList","MobileInternalIndex":"123"}


Response:

{"CommandType":"RuleList" ,"Rules":[{"ID":"1","Name":"12346","Valid":"1","Triggers":[{"Type":"EventTrigger","EventType":"AlmondModeUpdated","ID":"1","Grouping":"AND","Condition":"eq","Validation":"true","Value":"home"},
{ "Type":"DeviceTrigger","ID":"1","Index":"1","Grouping":"AND","Validation":"true","Condition":"eq","Value":"false"}],"Results":[{"Type":"EventResult","EventType":"AlmondModeUpdated","ID":"1","PreDelay":"0",
"Validation":"true","Value":"away"},{"Type":"DeviceResult","ID":"2","Index":"1","PreDelay":"0","Validation":"true","Value":"false"}]}]}


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"}

Clients Commands

Note: mii (MobileInternalIndex) 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

ClientList

Command to get clientlist.
Request

{  
 "MobileInternalIndex":"<random key>",
 "CommandType":"ClientList"
}

Response

{  
 "MobileInternalIndex":"<random key>",
 "CommandType":"ClientList",
 "Success":"true",
 "Clients":[  
   {  
     "ID":"1",
     "Name":"iphone_4s",
     "Connection":"wireless",
     "MAC":"other",
     "Type":"other",
     "LastKnownIP":"10.2.2.11",
     "Active":"false",
     "UseAsPresence":"true",
     "LastActiveEpoch":"1433920922",
      "Wait":"6"
   },
   {  
     "ID":"2",
     "Name":"buildserver.lan",
     "Connection":"wired",
     "MAC":"d8:50:e6:54:1b:9c",
     "Type":"other",
     "LastKnownIP":"10.10.10.1",
     "Active":"true",
     "UseAsPresence":"false",
     "LastActiveEpoch":"1433920922",
      "Wait":"6"
   }
 ]
}

Note - Success Tag in response:
If the Almond is in AP mode or Range Extender mode then Success tag will be set to ‘false’.

UpdateClient

Command to Update the data of a client.
ID - Clientid
Name - name of the client
Connection - wired/wireless

Type - pc
       laptop
       tablet  
       smartphone
       ipod
       ipad
       iphone
       mac
       printer
       router_switch
       hub
       tv
       chromecast
       appleTV
       android_stick
       camera
       nest
       other

Use As Presence - true/false
Request

{  
 "MobileInternalIndex":"<random key>",
 "CommandType":"UpdateClient",
 "Clients":{  
   "ID":"2",
   "Name":"device1",
   "Connection":"wired",
   "MAC":"00:17:88:0a:04:41",
   "Type":"tv",
   "LastKnownIP":"10.2.2.11",
   "Active":"false",
   "UseAsPresence":"false",
    "Wait":"6"
 }
}

Response
Success

{
 "CommandType":"UpdateClient",
 "MobileInternalIndex":"324",
 "Success":"true",
 "ReasonCode":"0"
}

Faliure

{
 "CommandType":"UpdateClient",
 "MobileInternalIndex":"324",
 "Success":"false",
 "ReasonCode":"0"
}

Remove client

command to remove a client.
Request

{  
 "MobileInternalIndex":"<random key>",
 "CommandType":"RemoveClient",
 "Clients":{  
   "ID":"1",
   "MAC":"1c:75:08:32:2a:6d"
 }
}

Response
Success

{
 "CommandType":"RemoveClient", 
 "MobileInternalIndex":"324",
 "Success":"true",
 "ReasonCode":"0" 
}

Failure

{
 "CommandType":"RemoveClient",
 "MobileInternalIndex":"324",
 "Success":"false",
 "ReasonCode":"0"
}

Removeallclients

Command to remove all clients
Request

{  
 "MobileInternalIndex":"<random key>",
 "CommandType":"RemoveAllClients",
}

Response
Success

{
 "CommandType":"RemoveAllClients",
 "MobileInternalIndex":"324",
 "Success":"true",
 "ReasonCode":"0"
}

Failure

{
 "CommandType":"RemoveAllClients",
 "MobileInternalIndex":"324",
 "Success":"false",
 "ReasonCode":"0"
}


ScenesCommands

Note:mii(MobileInternalIndex) 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

SceneList

Command to retrieve the list of existing Scenes.
Request

{ 
 "MobileInternalIndex":"<random key>",
 "CommandType":"DynamicSceneList"
}

Response
Note: Active :- Indicates the state of Scene

{  
 "MobileInternalIndex":"<random key>",
 "CommandType":"DynamicSceneList",
 "Scenes":[  
   {  
     "ID":"1",
     "Name":"Scene1",
      "LastActiveEpoch":"1433740885",
      "Active":"false",
     "SceneEntryList":[  
       {  
         "DeviceID":"2",
         "Index":"2",
         "Value":"true",
         "Valid":"false"
       },
       {  
         "DeviceID":"1",
         "Index":"2",
         "Value":"true",
         "Valid":"false"
       }
     ]
   },
   {  
     "ID":"2",
     "Name":"Scene2",
      "LastActiveEpoch":"0",
      "Active":"false",
     "SceneEntryList":[  
       {  
         "DeviceID":"6",
         "Index":"1",
         "Value":"true",
         "Valid":"false"
       },
       {  
         "DeviceID":"7",
         "Index":"1",
         "Value":"true",
         "Valid":"false"
       }
     ]
   }
 ]
}

AddScene

Command to add a new Scene.
Request

{  
 "CommandType":"AddScene",
 "MobileInternalIndex":"324",
 "Scenes":{  
   "Name":"My_created_scene",
   "SceneEntryList":[  
     {  
       "DeviceID":"1",
       "Index":"1",
       "Value":"false"
     },
     {  
       "DeviceID":"2",
       "Index":"2",
       "Value":"false"
     }
   ]
 }
} 

Response

{"CommandType":"AddScene","MobileInternalIndex":"324","Success":"true","Reason":"0"}

UpdateScene

Command to update an existing Scene
Request

{  
 "CommandType":"UpdateScene",
 "MobileInternalIndex":"324",
 "Scenes":{  
   "ID":"15",
   "Name":"My_created_scene",
   "SceneEntryList":[  
     {  
       "DeviceID":"1",
       "Index":"1",
       "Value":"false"
     },
     {  
       "DeviceID":"2",
       "Index":"2",
       "Value":"false"
     }
   ]
 }
}

Response

{"CommandType":"UpdateScene","MobileInternalIndex":"324","Success":"true","Reason":"0"}

ActivateScene

Command to activate a Scene
Request

{  
 "CommandType":"ActivateScene",
 "MobileInternalIndex":"324",
 "Scenes":{  
   "ID":"11"
 }
}

Response

{"CommandType":"ActivateScene","MobileInternalIndex":"324","Success":"true","Reason":"0"}


RemoveScene

Command to remove a Scene
Request

{  
 "CommandType":"RemoveScene",
 "MobileInternalIndex":"324",
 "Scenes":{  
   "ID":"11"
 }
}

Response

{"CommandType":"RemoveScene","MobileInternalIndex":"324","Success":"true","Reason":"0"} 

RemoveAllScenes

Command to remove all Scenes
Request

{  
 "CommandType":"RemoveAllScenes",
 "MobileInternalIndex":"324"
}

Response

{"CommandType":"RemoveAllScenes","MobileInternalIndex":"324","Success":"true","Reason":"0"}

Notification and Event Updates

SensorUpdate

When any index value is changed the following update will be received.

{"commandtype":"SensorUpdate","data":{"<device id>":{"<index id>":{"index":"<index id>","name":"<index name>","value":"<index value>"}}}}

Example

{"commandtype":"SensorUpdate","data":{"25":{"3":{"index":"3","name":"TAMPER","value":"false"}}}}

DeviceAdded

When a new device is added the following update will be received.

{"commandtype":"DeviceAdded","data":{"<device id>":{"devicename":"<device name>","friendlydevicetype":"<friendly device type name >","devicetype":"<device type id >","deviceid":"<device id >","location":"
<location>","devicevalues":{"1":{"index":"<index num>","name":"<index name >","value":"<index val>"},"2":{"index":"<index num>","name":"<index name>","value":"<index val>"},"3":{"index":"<index num>","name":"<index
name>","value":"<index val>"}}}}}

Example:

{"commandtype":"DeviceAdded","data":{"27":{"devicename":"ContactSwitch #27","friendlydevicetype":"ContactSwitch","devicetype":"12","deviceid":"27","location":"Default","devicevalues":{"1": 
{"index":"1","name":"STATE","value":"true"},"2":{"index":"2","name":"LOW BATTERY","value":"0"},"3":{"index":"3","name":"TAMPER","value":"true"}}}}}

DeviceRemoved

When a device is removed the following update will be received

{"commandtype":"DeviceRemoved","data":{"<device id>":{"devtype":"<device type>"}}}

Example

{"commandtype":"DeviceRemoved","data":{"25":{"devtype":"12"}}}

DeviceRemoveAll

When all the devices are removed the following update will be received.

{"commandtype":"DeviceRemoveAll"}

DeviceUpdated

If any device type or index are changed the following update will be received.

{"commandtype":"DeviceUpdated","data":{"<device id>":{"devicename":"<device name>","friendlydevicetype":"<friendly device type name >","devicetype":"<device type id >","deviceid":"<device id >","location":"
 <location>","devicevalues":{"1":{"index":"<index num>","name":"<index name >","value":"<index val>"},"2":{"index":"<index num>","name":"<index name>","value":"<index val>"},"3":{"index":"<index num>","name":"<index  
 name>","value":"<index val>"}}}}}

Example

{"commandtype":"DeviceUpdated","data":{"27":{"devicename":"ContactSwitch #27","friendlydevicetype":"ContactSwitch","devicetype":"12","deviceid":"27","location":"Default","devicevalues":{"1":
{"index":"1","name":"STATE","value":"true"},"2":{"index":"2","name":"LOW BATTERY","value":"0"},"3":{"index":"3","name":"TAMPER","value":"true"}}}}}

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"}

AlmondModeUpdated

{"commandtype":"AlmondModeUpdated","data":{"<almond mode >":{"emailid":"<email id>"}}}

Example

{"commandtype":"AlmondModeUpdated","data":{"2":{"emailid":"swetha.reddy@securifi.com"}}}

DynamicClientAdded

When a new client is added this update is received.

{  
 "CommandType":"DynamicClientAdded",
 "Clients":{  
   "ID":"1",
   "Name":"my phone",
   "Connection":"wired",
   "MAC":"c4:43:6d:c9:ef:05",
   "Type":"tv",
   "LastKnownIP":"10.10.10.55",
   "Active":"false",
   "UseAsPresence":"true",
    "Wait":"6"
 }
}

DynamicClientJoined

When a client joined network this update is received.

{  
 "CommandType":"DynamicClientJoined",
 "Clients":{  
   "ID":"1",
   "Name":"my phone",
   "Connection":"wired",
   "MAC":"c4:43:6d:c9:ef:05",
   "Type":"tv",
   "LastKnownIP":"10.10.10.55",
   "Active":"false",
   "UseAsPresence":"true",
    "Wait":"6"
 }
} 


DynamicClientLeft

When a client leaves the network, following update is received.

{  
 "CommandType":"DynamicClientLeft",
 "Clients":{  
   "ID":"1",
   "Name":"my phone",
   "Connection":"wired",
   "MAC":"c4:43:6d:c9:ef:05",
   "Type":"tv",
   "LastKnownIP":"10.10.10.55",
   "Active":"false",
   "UseAsPresence":"true",
    "Wait":"6"
 }
}

DynamicClientUpdated

When a name change or any changes done to a client this update is received.

{  
 "CommandType":"DynamicClientUpdated",
 "Clients":{  
   "ID":"1",
   "Name":"my phone",
   "Connection":"wired",
   "MAC":"c4:43:6d:c9:ef:05",
   "Type":"tv",
   "LastKnownIP":"10.10.10.55",
   "Active":"false",
   "UseAsPresence":"true",
    "Wait":"6"
 }
}

DynamicClientRemoved

When a client is removed this update is received

{"CommandType":"DynamicClientRemoved","ID":"1","MAC":"c4:43:6d:c9:ef:05"}

DynamicAllClientsRemoved

When all the clients are removed this update is received

{"CommandType":"DynamicAllClientsRemoved"}

DynamicSceneAdded

when a new scene is added this update is received.
{  
 "CommandType":"DynamicSceneAdded",
 "Scenes":{  
   "ID":"1",
   "Name":"My_created_scene",
   "LastActiveEpoch":"8295685751190847488",
   "Active":"false",
   "SceneEntryList":[  
    {"DeviceID":"1","Index":"1","Value":"false","Valid":"true"},
    {"DeviceID":"1","Index":"2","Value":"false","Valid":"false"}
    ]
 }
}

DynamicSceneUpdated

when any changes are made to existing scene this update is received.

{  
 "CommandType":"DynamicSceneUpdated",
 "Scenes":{  
   "ID":"1",
   "Name":"My_created_scene",
   "LastActiveEpoch":"8295685751190847488",
   "Active":"false",
   "SceneEntryList":[  
     {"DeviceID":"2","Index":"1","Value":"false","Valid":"true"},
     {"DeviceID":"4","Index":"1","Value":"78","Valid":"false"}
    ]
 }
}

DynamicSceneActivated

when any scene is activated this update is received.

{  
 "CommandType":"DynamicSceneActivated",
 "Scenes":{  
   "ID":"1",
   "LastActiveEpoch":"8295685751190847488",
   "Active":"true",
}  }

DynamicSceneRemoved

when any scene is removed this update is received.

{  
 "CommandType":"DynamicSceneRemoved",
 "Scenes":{  
   "ID":"1"
 }
}

DynamicAllScenesRemoved

when all scenes are removed this update is received.

{"CommandType":"DynamicAllScenesRemoved"}