Project

General

Profile

Javascript » History » Version 10

Torbjorn Carlqvist Admin, 09/01/2021 03:39 PM

1 2 Torbjorn Carlqvist Admin
h1. Javascript guide for DTXr code IDE
2 1 Torbjorn Carlqvist Admin
3 9 Torbjorn Carlqvist Admin
Shows the various commands and events that can be used to build automation scripts.
4 1 Torbjorn Carlqvist Admin
5 10 Torbjorn Carlqvist Admin
[[#Commands]]
6
[[#Events]]
7
8 6 Torbjorn Carlqvist Admin
h2. Commands
9
10
11
h3. *print*  - Prints a message to footer log window as well as the automation.log file
12
13 1 Torbjorn Carlqvist Admin
<pre><code class="javascript">print("hello");</code></pre>
14
15 6 Torbjorn Carlqvist Admin
h3. *readProperty*  - Reads an object property value
16 3 Torbjorn Carlqvist Admin
17 4 Torbjorn Carlqvist Admin
<pre><code class="javascript">
18 8 Torbjorn Carlqvist Admin
19
/***********************************************************************************************
20
 * @param {Number} device - The device id
21
 * @param {Number} objectType - The object type. Both id and enumerated names can be used.
22
 * @param {Number} objectInstance - The object instance. Must be a positive number.
23
 * @param {Number} propertyId - The property id. Both id and enumerated names can be used.
24
 ***********************************************************************************************/
25
26 4 Torbjorn Carlqvist Admin
//Reads a present value from analog input object 0.
27
Controller.readProperty(85343,analogInput,0,presentValue);
28 5 Torbjorn Carlqvist Admin
29
//Use the result to print and in logic
30
res = Controller.readProperty(85343,analogInput,0,presentValue);
31
print(res);
32 1 Torbjorn Carlqvist Admin
if ( res > 0 ){
33
  print("value larger than 0!");
34 6 Torbjorn Carlqvist Admin
}
35
</code></pre>
36
37
h2. Events
38 7 Torbjorn Carlqvist Admin
39 6 Torbjorn Carlqvist Admin
h3. *eventNotificationReceived* - Called when an intrinsic report notification is received.
40
41
<pre><code class="javascript">
42
/***********************************************************************************************
43
 * @param {Number} device - The device that send the event
44
 * @param {Number} objectType - The source object of the event
45
 * @param {Number} objectInstance - The instance of source object
46
 * @param {Number} eventType - The type of event received
47
 * @param {String} fromState - The previous state
48
 * @param {String} toState - The current state after the change
49
 * @param {Object} eventValues - A map of specific values for this particular eventType 
50
 ***********************************************************************************************/
51 1 Torbjorn Carlqvist Admin
function eventNotificationReceived(processIdentifier,initiatingDevice,object,objectType,objectInstance,timeStampUTC,notificationClass,priority,eventType,messageText,notifyType,ackRequired,fromState,toState,eventValues){
52 7 Torbjorn Carlqvist Admin
//Use this event to act on notifications that is set to be subscribed by this device.
53 5 Torbjorn Carlqvist Admin
}
54 4 Torbjorn Carlqvist Admin
</code></pre>