Skip to main content

iRidium API. Routines

Methods and properties for controlling server routines, allowing interaction directly with equipment or through a TimeTable item.

A routine starts automatically when a specified event occurs: equipment data is received or a scheduled event is triggered.

Note
  • Read more about server routines in iRidi Studio here.

  • For instructions on the TimeTable item, follow this link.

Methods​

IR.AddProRoutine()​

Create a server routine.

Syntax: IR.AddProRoutine( name, routine_type, schedule_type);

ParameterValueDescription
name"Routine 1"type: String
Unique server routine name
rowspan="2" routine_typeIR.ROUTINE_TYPE_AUTONOMICtype: Object
Standard server routine
IR.ROUTINE_TYPE_TIMETABLERoutine for working with a Timetable item
rowspan="2" schedule_typeIR.ROUTINE_SERVICE_SCHEDULE_TYPE_WEEKLY_CYCLEtype: Object
Weekly schedule
IR.ROUTINE_SERVICE_SCHEDULE_TYPE_CALENDARCalendar schedule
Output
Object[Object ProRoutinePrototype]type: Object
Server routine object instance

Example

var routine = IR.AddProRoutine("Routine 1", IR.ROUTINE_TYPE_TIMETABLE, IR.ROUTINE_SERVICE_SCHEDULE_TYPE_WEEKLY_CYCLE); // недельное расписание

var routine2 = IR.AddProRoutine("Routine 2", IR.ROUTINE_TYPE_TIMETABLE, IR.ROUTINE_SERVICE_SCHEDULE_TYPE_CALENDAR); // календарное расписание

IR.GetProRoutine()​

Access an existing routine.

Syntax: IR.GetProRoutine( name / ID);

ParameterValueDescription
name"Routine 1"type: String
Server routine name
ID1type: Number
Server routine identifier
Output
Object[Object ProRoutinePrototype]type: Object
Server routine object instance

Example IR.Log("GET ROUTINE: " + IR.GetProRoutine("Routine 1")); // [Object proRoutinePrototype]

IR.GetProRoutines()​

Access all server routines in the project.

Syntax: IR.GetProRoutines()

ParameterValueDescription
Array[[object ProRoutinePrototype],
[object ProRoutinePrototype]]
type: Array
Array of server routine objects

Example IR.Log("GET ROUTINE: " + IR.GetProRoutines()); // [[Object proRoutinePrototype], [Object proRoutinePrototype]]

IR.GetScheduler()​

Access an existing schedule.

Syntax:

IR.GetScheduler(#IR.GetScheduler() | name);

InputValueDescription
name"Schedule 1"type: String
Schedule name
Output
Object-type: Object
schedule object instance

Example var schedule = IR.GetScheduler("Schedule 1");

IR.EditRoutineSettings()​

Change the routine settings.

Syntax: IR.EditRoutineSettings(name);

InputValueDescription
name"Routine 1"type: String
Routine name
Output
Object-type: Object
routine settings window

Example

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 1"), function  () { 
IR.EditRoutineSettings("Routine 1");
IR.Log("EditRoutines");
});

IR.ShowListOfAllRoutines()​

Show all routine settings.

Syntax: IR.ShowListOfAllRoutines();

InputValueDescription
Object-type: Object
settings window for all routines

Example

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 6"), function  () { 
IR.ShowListOfAllRoutines();
IR.Log("ShowList");
});

Server routine properties​

IR.GetProRoutine(name / ID). property

parameterValueDescription
.Name"Routine 1"type: String
Set the routine name
.ID1type: Number
Get the routine ID
.Type1type: Number
Get the routine type
0 - standard server routine
1 - routine for working with Timetable
.Enabledtruetype: Boolean
Enable or disable the routine
.EventsCount2type: Number
Get the number of events used in the routine
.ConditionsCount2type: Number
Get the number of conditions used in the routine
.ActionsCount2type: Number
Get the number of actions used in the routine
.ParametersCount3type: Number
Get the number of routine parameters

Server routine parameters​

Pass the required values to a routine.

.AddParameter()​

Create a parameter.

Syntax: IR.GetProRoutine(routine).AddParameter({Type,Name...});

InputValueDescription
routine"Routine 1"type: String
Server routine name
TypeIR.ROUTINE_PARAMETER_TYPE_STRING / IR.ROUTINE_PARAMETER_TYPE_NUMBER / IR.ROUTINE_PARAMETER_TYPE_COLOR / IR.ROUTINE_PARAMETER_TYPE_SELECTtype: String / Number / RGBA / select
Routine parameter type
Name"numberParam"type: String
Unique parameter name
ROUTINE_PARAMETER_TYPE_NUMBER
MinValue0type: Number
Minimum value
MaxValue100type: Number
Maximum value
ROUTINE_PARAMETER_TYPE_SELECT
SubTypeIR.PT_TEXT / IR.PT_INTEGER / IR.PT_FLOATtype: String / Number
Convert values (Value) to the required type
SubParameterArrayKey: ON/OFF, Value: 1/0type: String
Selection from preset values
Output
Object[object ProRoutineParameterPrototype]type: Object
Parameter object

Example

var routine = IR.GetProRoutine(“Routine 1”); // получение доступа к сценарию
// создание параметров:
if (routine) {
// строковый параметр
var stringParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_STRING,
Name: "String"
});

<!--T:30-->
// числовой параметр
var numberParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_NUMBER,
Name: "Number",
MinValue: 0,
MaxValue: 100
});

<!--T:31-->
// параметр цвета
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color"
});

<!--T:32-->
// параметр выбора
var selectParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_SELECT,
Name: "Select",
SubType: IR.PT_INTEGER,
SubParameterArray: [{
Key: "ON",
Value: "1"
}, {
Key: "OFF",
Value: "2"
}]
});

.GetParameter()​

Access an existing parameter.

Syntax: routine.GetParameter( name / ID)

InputValueDescription
routineIR.GetProRoutine("Routine 1")type: Object
Routine using the parameter
ID1type: Number
Unique parameter identifier
name"Color"type: String
Parameter name
Output
Object[object ProRoutineParameterPrototype]type: Object
Parameter object

Example

// создание параметра
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color",
});

<!--T:37-->
// получение параметра
IR.Log("GET PARAMETER: " + routine.GetParameter("Color"));
//GET PARAMETER: [object ProRoutineParameterPrototype]

.GetParameters()​

Access all parameters used in the routine.

Syntax: routine.GetParameters()

InputValueDescription
routineIR.GetProRoutine("Routine 1")type: Object
Routine using the parameter
Output
Array[[object ProRoutineParameterPrototype], [object ProRoutineParameterPrototype]]type: Array
Parameter array

Example


// получение параметра
IR.Log("GET PARAMETERS: " + routine.GetParameters());
//[[object ProRoutineParameterPrototype], [object ProRoutineParameterPrototype]]

.DeleteParameter()​

Delete the selected parameter.

Syntax: routine.DeleteParameter(Param)

InputValueDescription
routineIR.GetProRoutine("Routine 1")type: Object
Routine using the parameter
Paramroutine.AddParameter({Type: IR.ROUTINE_PARAMETER_TYPE_COLOR, Name: "Color"});type: Object
Selected parameter

Example

//создание параметра
var colorParam = routine.AddParameter({
Type: IR.ROUTINE_PARAMETER_TYPE_COLOR,
Name: "Color"
});

IR.Log("DELETE_PARAMETER RESULT: " + routine.DeleteParameter(colorParam));

Parameter properties​

routine.GetParameter(name / ID).property

parameterValueDescription
.ID1type: Number
Get the parameter ID
.Name"String"type: String
Get the parameter name
.Type1type: Object / Number
Get the parameter type

Server routine events​

The main condition for activating a server routine.

.AddEvent()​

Syntax: routine.AddEvent({Type, ParametersValues...})

ParameterValueDescription
routineIR.GetProRoutine("Routine 1")type: Object
Server routine object
TypeIR.ROUTINE_SERVICE_TYPE_TOKENtype: Object
Token activation
IR.ROUTINE_SERVICE_TYPE_SCHEDULEtype: Object
Schedule activation
IR.ROUTINE_SERVICE_TYPE_TOKEN
Token"Server.Tags.Virtual 1"type: String
Token reference
OperationIR.ROUTINE_COMPARE_EQUAL (==)
IR.ROUTINE_COMPARE_NOT_EQUAL (!=)
IR.ROUTINE_COMPARE_LESS (<)
IR.ROUTINE_COMPARE_MORE (>)
IR.ROUTINE_COMPARE_EQUAL_LESS (<=)
IR.ROUTINE_COMPARE_EQUAL_MORE (>=)
type: Object
Comparison operators for values
Value"50"type: String
Value for checking the condition
IR.ROUTINE_SERVICE_TYPE_SCHEDULE
ScheduleID1type: Number
Schedule identifier
ScheduleEventID1type: Number
Event identifier
ValueIR.SCHEDULE_EVENT_STATE_STARTtype: Object
Start event
IR.SCHEDULE_EVENT_STATE_FINISHtype: Object
Finish event
ParametersValues [{ParameterID: 1, Value: "1"},
{ParameterID: 2, Value: "0"}]
type: {Number, String}
Contains a list of objects with values

Example

var event = routine.AddEvent({ // Создание события
Type: IR.ROUTINE_SERVICE_TYPE_SCHEDULE, // Указание типа события
ScheduleID: 0, // Идентификатор расписания
ScheduleEventID: 0, // Идентификатор события расписания
Value: IR.SCHEDULE_EVENT_STATE_START, // Активация по старту события
ParametersValues: [{
ParameterID: stringParam.ID, // Идентификатор строкового параметра
Value: "Hello, world!" // Значение параметра
}, {
ParameterID: numberParam.ID, // Идентификатор числового параметра
Value: "50" // Значение параметра
}, {
ParameterID: colorParam.ID, // Идентификатор RGBA параметра
Value: 0xFF00FFFF.toString() // Значение параметра (в строковом виде)
}, {
ParameterID: selectParam.ID, // Идентификатор параметра выбора
Value: "ON" // Значение параметра
}]
});
Important
  • If the event type and routine type differ, the event will not be created!
  • If the routine type is ROUTINE_TYPE_TIMETABLE and no parameters have been created, the event will not be created!
  • If the token is specified incorrectly, the event will not be created!
  • If the routine type is ROUTINE_TYPE_TIMETABLE, all ParametersValues must be specified according to the number of parameters; otherwise, the event will not be created!

.GetEvent()​

Access an existing event.

Syntax: routine.GetEvent( ID)

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
ID1type: Number
Event identifier.
Output
Object[object ProRoutineServicePrototype]type: Object
Event object.

Example IR.Log("GET EVENT: " + routine.GetEvent(1)); //[object ProRoutineServicePrototype]

.GetEvents()​

Access the event array.

Syntax: routine.GetEvents()

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
Output
Array[[object ProRoutineServicePrototype],
[object ProRoutineServicePrototype]]
type: Array
Event array.

Example

IR.Log("GET EVENTS: " + routine.GetEvents()); 
//[[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]]

.DeleteEvent()​

Delete an event.

Syntax: routine.DeleteEvent(еvent)

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
eventroutine.GetEvent(0)type: Object
Event object.

Example

// Удаление события
IR.Log("DELETE_EVENT RESULT: " + routine.DeleteEvent(event)); //true/false

Event properties​

routine.GetEvent(ID).property

parameterValueDescription
.Operation3type: Number
Set the comparison type.
.ID1type: Number
Get the event ID.
.Type4type: Number
Get the event type.
.Value1type: Number
Set the value to send.
type: String
(ROUTINE_SERVICE_TYPE_TOKEN).
.TokenServer.Channels.Modbus TCP.Channel 1type: String
Get the token name.

Server routine conditions​

Additional conditions for activating server routines. A routine activates only when an event occurs and all listed conditions are met.

.AddCondition()​

Create a condition.

Syntax: routine.AddCondition({Type,...})

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
TypeIR.ROUTINE_SERVICE_TYPE_TOKENtype: Object
Token activation.
TypeIR.ROUTINE_SERVICE_TYPE_SCHEDULESchedule activation.
ROUTINE_SERVICE_TYPE_SCHEDULE
ScheduleID1type: Number
Schedule identifier.
ScheduleEventID1type: Number
Event identifier.
ValueIR.SCHEDULE_EVENT_STATE_UNKNOWNtype: Object
Schedule inactive.
ValueIR.SCHEDULE_EVENT_STATE_STARTSchedule active.
ROUTINE_SERVICE_TYPE_TOKEN
Token"Server.Tags.Virtual 1"type: String
Token.
OperationIR.ROUTINE_COMPARE_EQUAL(==),
IR.ROUTINE_COMPARE_NOT_EQUAL(!=),
IR.ROUTINE_COMPARE_LESS,
IR.ROUTINE_COMPARE_MORE(>),
IR.ROUTINE_COMPARE_EQUAL_LESS,
IR.ROUTINE_COMPARE_EQUAL_MORE(>=)
type: Object
Comparison operators.
Value"50"type: String
Token value.

Example

var condition = routine.AddCondition({   //Создание условия
Type: IR.ROUTINE_SERVICE_TYPE_TOKEN, //Выбор типа
Value: "1", //Значение токена
Token: "Modbus TCP.Channel", //Имя токена
Operation: IR.ROUTINE_COMPARE_EQUAL //Условный оператор
});

.GetCondition()​

Access an existing condition.

Syntax: routine.GetCondition(ID)

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
ID1type: Number
Condition identifier.
Output
Object[object ProRoutineServicePrototype]type: Object
Condition object.

Example IR.Log("GET CONDITION: " + routine.GetCondition(1)); //[object ProRoutineServicePrototype]

.GetConditions()​

Access the array of existing conditions.

Syntax: routine.GetConditions()

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
Output
Array[[object ProRoutineServicePrototype],
[object ProRoutineServicePrototype]]
type: Array
Condition array.

Example

IR.Log("GET CONDITIONS: " + routine.GetConditions()); 
// [[object ProRoutineServicePrototype], [object ProRoutineServicePrototype]]

.DeleteCondition()​

Delete a condition.

Syntax: routine.DeleteCondition(condition)

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
conditionroutine.GetCondition(1)type: Object
Condition object.

Example IR.Log("DELETE CONDITION RESULT: " + routine.DeleteCondition(condition)); // true/false

Condition properties​

routine.GetCondition(ID).property

parameterValueDescription
.Operation1type: Number
Set the comparison type.
.ID1type: Number
Get the condition ID.
.Type6type: Number
Get the condition type.
.Value1type: Number
Set the value to send.
type: String
(ROUTINE_SERVICE_TYPE_TOKEN)
.TokenServer.Channels.Modbus TCP.Channel 1type: String
Get the token name.

Server routine actions​

Actions performed when the routine activates.

.AddAction()​

Create an action.

Syntax:

routine.AddAction({Type, Value...})

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
TypeIR.ACTION_TYPE_SEND_NUMBER,
IR.ACTION_TYPE_SEND_TEXT,
IR.ACTION_TYPE_SEND_TAG,
IR.ACTION_TYPE_SEND_DATA,
IR.ACTION_TYPE_DELAY,
IR.ACTION_TYPE_NUMBER_TO_TAG,
IR.ACTION_TYPE_TEXT_TO_TAG,
IR.ACTION_TYPE_TAG_TO_TAG
type: Object
Action type.
ValueACTION_TYPE_SEND_NUMBER,
ACTION_TYPE_SEND_TEXT,
ACTION_TYPE_NUMBER_TO_TAG,
ACTION_TYPE_TEXT_TO_TAG,
ACTION_TYPE_DELAY(ms)
Example: “50”;
ACTION_TYPE_SEND_TAG,
ACTION_TYPE_TAG_TO_TAG
Example: "Server.Tags.Virtual 1";
ACTION_TYPE_SEND_DATA
Example: "01, 02, 03, 04, AA, BB"
type: String
Values to send.
Channel"AV & Custom Systems (HTTP).AV Control Command"type: String
Name of the channel to receive the value.
Used only in:
IR.ACTION_TYPE_SEND_NUMBER,
IR.ACTION_TYPE_SEND_TEXT,
IR.ACTION_TYPE_SEND_TAG,
IR.ACTION_TYPE_SEND_DATA
Tag"Server.Tags.Virtual 1"Type: String
Name of the token to receive the values.
Used only in:
IR.ACTION_TYPE_NUMBER_TO_TAG,
IR.ACTION_TYPE_TEXT_TO_TAG,
IR.ACTION_TYPE_TAG_TO_TAG

Example

var numberAction = routine.AddAction({   //Создание действия
Type: IR.ACTION_TYPE_NUMBER_TO_NUMBER, //Тип данных
Channel: "Modbus TCP.Channel 1", //Имя канала
Value: "1" //Отправляемое значение
});


var colorAction = routine.AddAction({ //Создание действия
Type: IR.ACTION_TYPE_NUMBER_TO_TAG, //Тип данных
Tag: "Server.Tags.Virtual 1", //Имя тэга
Value: "1" //Отправляемое значение
});
Note
  • Create an action for a Timetable item using parameters:
InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
TypeIR.ACTION_TYPE_SEND_TAGtype: Object
Action type.
Value"Routines." + routine.Name + "." + parameter.Nametype: String
routine - routine object,
parameter - selected parameter object.
Channel"AV & Custom Systems (HTTP).AV Control Command"type: String
Name of the channel to receive the value.
Tag"Server.Tags.Virtual 1"Type: String
Name of the token to receive the values.

Example

var colorAction = routine.AddAction({   //Создание действия
Type: IR.ACTION_TYPE_SEND_TAG, //Тип данных
Channel: "AV & Custom Systems (TCP).Command 1", //Имя канала
Value: "Routines." + routine.Name + "." + colorParam.Name //Отправляемое значение
});

.GetAction()​

Access an existing action.

Syntax:

routine.GetAction(ID)

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
ID0type: Number
Action identifier.
Output
Object[object ProRoutineActionPrototype]type: Object
Action object.

Example IR.Log("GET ACTION: " + routine.GetAction(0)); //[object ProRoutineActionPrototype]

.GetActions()​

Access the action array.

Syntax:

routine.GetActions()

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
Output
Array[[object ProRoutineActionPrototype],
[object ProRoutineActionPrototype]]
type: Array
Array of action objects.

Example

IR.Log("GET ACTIONS: " + routine.GetActions()); 
//[[object ProRoutineActionPrototype], [object ProRoutineActionPrototype]]

.DeleteAction()​

Delete an action

Syntax:

routine.DeleteAction(action)

InputValueDescription
routineIR.GetProRoutine(“Routine 1”)type: Object
Server routine object.
actionroutine.GetAction(0)type: Object
Action object.

Example IR.Log("DELETE ACTION RESULT: " + routine.DeleteAction(colorAction)); // true/false

Action properties​

routine.GetAction(ID). property

parameterValueDescription
.Channel"AV & Custom Systems (TCP).AV Control Command"type: String
Set the channel name.
.ID1type: Number
Get the action ID.
.Type11type: Number
Get the action type.
.Value1type: Number
Set the value.
.Tag"Server.Tags.Virtual 1"type: String
Set the tag name.