Actions
Schema Actions handle the functions that the devices can carry out.
Actions can manipulate properties, mandate changes in the state of the device, set timings for those states and trigger different activities on the device. In other words, Actions are an interface for operating the entity according to what the entity is supposed to do. These are added, like Properties and Events, to the Thing schema.
volumeChange
and
togglePower
) for a stereo here:{
...
"actions": {
"volumeChange": {
"title": "Change the volume",
"description": "Change the volume of the Sound Stereo System over a set interval",
"input": {
"type": "object",
"properties": {
"level": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"volumeLevelDuration": {
"type": "integer",
"minimum": 0,
"unit": "seconds"
}
}
}
},
"togglePower": {
"title": "Turn On/Off",
"description": "This action turns the stereo on or off, depending on the stereos current state."
}
}
}
As you can see, Actions follow a very similar format to Properties (and indeed, to Events). AnythingDB provides a schema for defining Actions, and metadata keys for describing them in detail.
Metadata Definition | Description | Required? | Type |
---|---|---|---|
title |
Title of the action displayed in the UI | No | string |
description |
Additional content to tell the user what the action is for. | No | string |
input |
Defines the expected format of the action body. | No | object |
togglePower
Action above is like this. However, other
times, actions require parameters in the command. volumeChange
is
like this, where the Action command needs to specify not just that the volume should
change but what it should change to and how long it should take to get to that
volume. These Action command parameters are defined in the input
metadata
key, in the Action description. This input
key follows the same
rules as a property - it can be defined by a primitive type
and
then, based on the type
, further defined by other metadata
keys.
array
- Expects a list of results
boolean
- Expects a true/false
number
- Expects any real number
integer
- Expects any whole number
object
- Expects a JSON object with additional properties defined.Note: Using Object type properties, you can nest properties within properties to create rich structures.
string
- Expects a series of letters and/or numbers
null
- Expects no value
Metadata Definition | Description | Required? | Type |
---|---|---|---|
title |
Title of the action input displayed in a UI | No | string |
description |
Additional content to tell the user what the action input is for. | No | string |
type |
Primitive data type for validation of the input | No | string |
unit |
Provides a reference unit, especially for numbers and integers. | No | string |
readOnly |
Validates that a value should not be written to. | Yes (default is false ) |
boolean |
Metadata Definition | Description | Required? | Type |
---|---|---|---|
minimum |
Minimum value. Used for validation. | No | number |
maximum |
Maximum value. Used for validation. | No | number |
Metadata Definition | Description | Required? | Type |
---|---|---|---|
minimum |
Minimum value. Used for validation. | No | integer |
maximum |
Maximum value. Used for validation. | No | integer |
{
...
"actions": {
"toggleOn": {
"title": "Turn On/Off",
"description": "This action turns the stereo on or off, depending on the stereos current state."
},
"changeGroupId": {
"description": "Removes group id",
"input": {
"maximum": 65535,
"minimum": 0,
"type": "integer"
},
"title": "RemoveGroupId"
},
"volumeChange": {
"title": "Change the volume",
"description": "Change the volume of the Sound Stereo System over a set interval",
"input": {
"type": "object",
"properties": {
"level": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"volumeLevelDuration": {
"type": "integer",
"minimum": 0,
"unit": "seconds"
}
}
}
},
"updateMode": {
"title":"Switch the operating mode",
"description": "This manually changes the operating mode of the asset.",
"input": {
"type":"string"
}
},
"updateAlarmState": {
"title":"Update the current state of the audible alarm",
"description": "This can trigger or disable the alarm",
"input": {
"type":"boolean"
}
}
}
}