Scripts – new version of the scripts API (version 4)
Starting with version v4.4.5, the intraHouse system has changed the command system for scripts.
In this case, the previous command system remains operational. All old scripts will continue to work.
In new scenarios, it is recommended to use the new command system.

Note:
For the script to work with the new command system, add the following line in the script header: * @version 4 

/**
* @name Light by motion sensor 
* @desc Turn on the light on the motion sensor
* @version 4
*/

Command syntax in the intraHouse system

For devices

1.1.1 Dynamic properties of the device (Read):

1.1.2 Static device properties (Read):

1.2.1 Device status (Read):

1.2.2 Changeable device properties (Read):

1.2.3 Device parameters (Read):

1.3.1 Device Control with Auto Off (Write):

1.3.2Device Control without Auto Off (Write):

1.3.3 Changing parameters (Write):

1.3.4 Saving/Restoring parameters (Read/Write):

Для сценариев

Системные

2.1 Script Properties and Methods (Read/Write):

2.2 Properties and methods for working with timers (Read/Write):

2.3 Event listener methods (Write):

3.1 Informing (Write):

3.2 Logging (Write):

3.3 Running the plugin command (Write):

3.4 Group operations with devices (Write):

3.5 Date, Time (Read):

3.6 Global variables (Read/Write):

1. Properties and methods of devices

1.1 Device Properties

1.1.1 Dynamic properties of devices

x.value

Number || String

Read

Current value

Purpose:

For all devices

Examples:

temp.value,
dimmer.value,
lamp.value,
motion.value

x.setpoint

Number

Read

Setpoint

Purpose:

For analog sensors and actuators

Example:

if (temp.value > temp.setpoint)

x.error

Number || String

Read

Error

Purpose:

For all devices

Can be setting
– by the plugin,
– by the system (if the range of acceptable values is specified)
– by the script

x.auto

Boolean

Read

AUTO flag

Purpose:

For actuators only

x.blk

Boolean

Read

sensor block flag

Purpose:

Only for sensors

1.1.2 Static device properties set via Project Manager (PM)

x.id

String

Read

Device id

x.name

String

Read

Device name

x.placeName

String

Read

Level name

x.zoneName

String

Read

Zone name

x.fullName

String

Read

The full name of the device, including if available level and zone.

x.stateName

String

Read

Device status name.

1.2 Device methods

1.2.1 Methods for determining the current state of the device.

x.isOn()

Boolean

Read

Is On?

Example:

if (Vent1.isOn()) Lamp1.on()
Turn On Lamp1 if Vent1 is On

x.isOff()

Boolean

Read

Is Off?

x.isError()

Boolean

Read

Error?

x.isNoError()

Boolean

Read

No error?

1.2.2 Methods for tracking property changes

x.isChanged()

Boolean

Read

True if the base value (value) has changed since the last time the script was called

x.isChanged(property name)

Boolean

Read

True if the property value has changed since the last script call

1.2.3 The parameters of any device can be obtained using the function:

x.getParam(property name)

Number || String || Boolean

Read

These can be static and dynamic properties, as well as properties added by a script or plugin.
For static properties, the list is wider than 1.1.2, as it includes properties available in the device table PM

Examples:

temp.getParam(‘type’),
temp.getParam(‘name’),
temp.getParam(‘t1’)

1.3 Devices control

1.3.1 Methods to control the device with Auto Off

x.on()

Write

Turn on device x

Example:

Lamp1.on()
Turn on lamp1

x.off()

Write

Turn off the device x

Example:

Vent2.off()
Turn off the fan Vent2

x.toggle()

Write

Switch device x

Example:

Lamp2.toggle()
Switch lamp2.
If the Lamp2 was in the “on” state, it will switch to the “off” state.

x.setValue()

Number

Write

Set the value to device x

Example:

Dimm1.setValue(40)
Set the brightness of the lamp Dimm1 to 40

1.3.2 Device control without Auto Off
For actuators having an automatic mode - actions with saving the Auto parameter:

x.turnOnSaveAuto()

Write

Turn on device x, save Auto parameter

Example:

Lamp1.turnOnSaveAuto()
Turn on lamp1, the Auto parameter does not turn off

x.turnOffSaveAuto()

Write

Turn off the device x, save the parameter Auto

Example:

Lamp1.turnOffSaveAuto()
Turn off the lamp Lamp1, Auto parameter does not turn off

x.toggleSaveAuto()

Write

Switch device x, save Auto parameter

Example:

Lamp1.toggleSaveAuto()
Toggle lamp Lamp1, Auto parameter does not switch off

1.3.3 Methods for changing parameters and settings

x.setSetpoint()

Number

Write

Set the value of the setpoint

Example:

Temp1.setSetpoint(20)
Set the value of the setpoint – 20

x.setAuto()

Boolean

Write

Set Auto

Examples:

Lamp1.setAuto(True)
Put Lamp1 into automatic mode

Lamp1.setAuto(False)
Disable automatic mode at the Lamp1

x.setBlk()

Boolean

Write

Block/Unblock sensor

Examples:

SensorW1.setBlk(True)
Block sensor leakage SensorW1

SensorW1.setBlk(False)
Unblock sensor leakage SensorW1

x.setParam("parameter name", value)

Write

To work with additional device parameters

In scripts, any device can be set with additional parameters that can be configured in the user interface in the device properties window. To work with these parameters from the script, you can use the x.setParam function

Examples:

Lamp1.setParam(“TimeWithoutMotion”,15)
Set the lamp1 operation time with no movement = 15 sec.

1.3.4 Methods of saving and restoring parameters

x.save(parameter name)

String

Write

Save parameter

x.restore(parameter name)

String

Read

Restore parameter

Example:

When arming disable automatic device mode.
When disarmed, restore if installed.

if (guard.isChanged()) {
switch (guard.value) {
case 1: vent.save(‘auto’); break;
case 0: vent.restore(‘auto’); break;
}
}

2. Properties and methods of the script

2.1 Script-related properties and methods

this.exit()

Write

Script completion

this.__laststart

Timestamp

Read

Last run time of this script.

this.__qstarts

Number

Read

Total number of script launches after server reboot

Read more:  About scripts

2.2 Properties and methods for working with timers

2.2.1 Timer states

this.timer

Object

Read

Timer state

After creating at least one timer, the script has a property – this.timer object, which will contain the names of the timers and their status:
‘off’ – swithed off
‘on’ – is running
‘done’- finished

Timer states can be used in conditional expressions.

Example:

if (this.timer.T1 == ‘on’)

2.2.2 Announcement and start of the timer:

this.startTimer(,

Write

Example:

this.startTimer(‘T1’, 5.5, ‘turnAllOff’)

2.2.3 Stop (reset) timer

this.stopTimer()

Write

Example:

this.stopTimer(‘T1’)

2.2.4 Announcement without launch. The timer stays off.

this.addTimer()

Write

Used when the timer is checked in a conditional expression before the startTimer command is executed.

2.3 Event Listeners

2.3.1 Register a listener

this.addListener(, )

Write

2.3.2 Remove listener

this.removeListener(, )

Write

It is rarely used, since at the end of the script the timers and scripts are deleted automatically.

Read more: About scripts

3. Script methods for performing system actions

3.1 Informing

Information - sending messages through various channels - email, sms, telegram, ...

this.info(communication channel, to whom, the message)

Write

Examples:

this.info(‘teleram’, ‘admin’, ‘Something went wrong!’)
this.info(’email’, ‘electro’, ‘Meter reading ‘+Meter1.value)

3.2 Logging

this.log('User log entry')

Write

this.syslog('Write to the system log ')

Write

3.3 Running the plugin command

this.pluginCommand({unit:'megad1', command:{...}})

Write

The ‘command’ structure is determined by the plugin to which the command is sent.

3.4 Group operations with devices

this.doAll(filter, action)

Write

Examples:

this.doAll({place:1, subs:1}, ‘on’)
this.doAll({place:1, subs:1}, ‘setAuto’)
this.doAll({place:1, subs:1, prop:’auto’}, ‘save’)
this.doAll({place:1, subs:1, prop:’auto’}, ‘restore’)

3.5 Getting the time specified by name (sunset, sunrise, next hour border)

this.getSysTime(name, date)

Timestamp

Read

name – ‘sunrise’ || ‘sunset’ || ‘hourly’
date – Date object or string ( ‘today’ || ‘tomorrow’) or date in timestamp format
(if not defined, then ‘today’)

Examples:

this.getSysTime(‘sunset’) – will return sunset time today
this.getSysTime(‘sunrise’,’tomorrow’) – will return the time of sunrise tomorrow
this.getSysTime(‘sunrise’, new Date(2018,11,31)) – will return to sunrise time December 31, 2018

3.6 Global Variables

The global object is available in any script:

global.set('name',value)

Write

global.get('name')

Read

global.remove('name')

Write

Example:

global.set(‘Armed’, true); // Armed

In another script:
if (global.get(‘Armed’)) {.. }

or check when running the script:
startOnChange(motion, global.get(‘Armed’))