State
State is an unstructured form of global data which is uniquely identifiable.
State Types
{
organizationId: string,
id: string,
value: string,
updatedUtc: datetime,
changedUtc: datetime,
createdUtc: datetime
}
State values are strings, but can be converted to other data types using other built-in functions
such as parseInt()
or parseFloat()
.
setState
This function is not available in read-only mode.
Sets a new State value.
setState(stateId, value)
Parameters
Name | Type | Description |
---|---|---|
stateId | string | The identifier of the State to retrieve. |
value | string | A new or updated State value. |
Returns The newly created or updated State.
Example
var state = setState('office-light', 'off');
This function will either create or update an existing State.
deleteState
This function is not available in read-only mode.
Deletes a State with a given identifier.
deleteState(stateId)
Parameters
Name | Type | Description |
---|---|---|
stateId | string | The identifier of the State to delete. |
Example
deleteState('office-temp');
This performs a hard delete and will not be recoverable afterwards. Delete with caution.
deleteStates
This function is not available in read-only mode.
Deletes multiple States with a given collection of identifiers.
deleteStates([stateIds])
Parameters
Name | Type | Description |
---|---|---|
stateIds | string[] | The identifiers of the State to delete. |
Example
deleteStates(['office-temp', 'office-humidity']);
This performs a hard delete and will not be recoverable afterwards. Delete with caution.
stateExists
Checks whether a State with an identifier exists.
stateExists(stateId)
Parameters
Name | Type | Description |
---|---|---|
stateId | string | The identifier of the State to check. |
Returns
A boolean
on whether the State exists.
Example
var exists = stateExists('office-device');
if (exists) {
// The State for a device exists
}
getState
Gets a State by its identifier.
getState(stateId)
Parameters
Name | Type | Description |
---|---|---|
stateId | string | The identifier of the State to retrieve. |
Returns
The State with the specified stateId
identifier.
Example
var state = getState('office-light');
if (state.value == 'on') {
// The office light is currently on
}
getStates
Gets a collection of States by their identifiers.
getStates([stateIds])
Parameters
Name | Type | Description |
---|---|---|
stateIds | string[] | The identifiers of the States to retrieve. |
Returns
A map of States with the specified stateIds
identifiers.
Example
var states = getStates(['office-light1', 'office-light2']);
if (states['office-light1'].value == 'on'
|| states['office-light2'].value == 'on') {
// Both office lights are on
}