The functions in this script work great.
I want to set the state of my Code_Devices at startup. For that I added this code:
Code: Select all
var portDevices =
[
"Code_Device_switchBinary_22",
"Code_Device_switchBinary_24",
"Code_Device_switchBinary_25",
"Code_Device_switchBinary_26",
"Code_Device_switchBinary_27",
"Code_Device_switchBinary_28",
"Code_Device_switchBinary_29",
"Code_Device_switchBinary_30"
];
console.log("Retrieve port states:");
for (var i in portDevices) {
vDev = controller.devices.get(portDevices[i]);
var portState = getPortState(i+1);
console.log("Set "+portDevices[i]+" to "+portState);
vDev.set('metrics:level', portState);
}
Than I get next error in the log-file:
Code: Select all
[2015-07-29 08:09:06.735] [I] [core] Retrieve port states:
[2015-07-29 08:09:07.528] [I] [core] Executing: python /opt/homeControl/port.py get 01 Result: -off-
[2015-07-29 08:09:07.529] [I] [core] Set Code_Device_switchBinary_22 to off
[2015-07-29 08:09:07.658] [E] [core] result: Error: TypeError: Cannot read property 'set' of null
at automation/myCode.js:28:6
at automation/modules/CustomUserCodeLoader/index.js:39:13
at Array.forEach (native)
at CustomUserCodeLoader.init (automation/modules/CustomUserCodeLoader/index.js:34:33)
at AutomationController.instantiateModule (automation/classes/AutomationController.js:300:22)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:392:18)
at Array.forEach (native)
at AutomationController.loadModule (automation/classes/AutomationController.js:391:8)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:409:14)
at Array.forEach (native)
[2015-07-29 08:09:07.720] [I] [core] Notification: error (core): Cannot instantiate module: CustomUserCodeLoader: Error: Uncaught TypeError: Cannot read property 'set' of null
[2015-07-29 08:09:07.756] [I] [core] Error: Uncaught TypeError: Cannot read property 'set' of null
at Error (native)
at automation/modules/CustomUserCodeLoader/index.js:39:13
at Array.forEach (native)
at CustomUserCodeLoader.init (automation/modules/CustomUserCodeLoader/index.js:34:33)
at AutomationController.instantiateModule (automation/classes/AutomationController.js:300:22)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:392:18)
at Array.forEach (native)
at AutomationController.loadModule (automation/classes/AutomationController.js:391:8)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:409:14)
at Array.forEach (native)
[2015-07-29 08:09:07.758] [I] [core] Loading module MultilineSensor from modules/MultilineSensor
[2015-07-29 08:09:07.764] [I] [core] Executing script: /*** MultilineSensor Z-Way HA module ******************************************* ...
[2015-07-29 08:09:07.769] [I] [core] Loading module CodeDevice from modules/CodeDevice
[2015-07-29 08:09:07.775] [I] [core] Executing script: /*** CodeDevice Z-Way HA module ******************************************* ...
[2015-07-29 08:09:07.799] [I] [core] Instantiating module 22 from class CodeDevice
[2015-07-29 08:09:07.809] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:07.843] [I] [core] Creating device switchBinary Code_Device_switchBinary_22
[2015-07-29 08:09:07.989] [I] [core] Instantiating module 24 from class CodeDevice
[2015-07-29 08:09:07.991] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.016] [I] [core] Creating device switchBinary Code_Device_switchBinary_24
[2015-07-29 08:09:08.078] [I] [core] Instantiating module 25 from class CodeDevice
[2015-07-29 08:09:08.079] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.127] [I] [core] Creating device switchBinary Code_Device_switchBinary_25
[2015-07-29 08:09:08.159] [I] [core] Instantiating module 26 from class CodeDevice
[2015-07-29 08:09:08.160] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.179] [I] [core] Creating device switchBinary Code_Device_switchBinary_26
[2015-07-29 08:09:08.213] [I] [core] Instantiating module 27 from class CodeDevice
[2015-07-29 08:09:08.213] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.233] [I] [core] Creating device switchBinary Code_Device_switchBinary_27
[2015-07-29 08:09:08.265] [I] [core] Instantiating module 28 from class CodeDevice
[2015-07-29 08:09:08.265] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.285] [I] [core] Creating device switchBinary Code_Device_switchBinary_28
[2015-07-29 08:09:08.316] [I] [core] Instantiating module 29 from class CodeDevice
[2015-07-29 08:09:08.317] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.337] [I] [core] Creating device switchBinary Code_Device_switchBinary_29
[2015-07-29 08:09:08.371] [I] [core] Instantiating module 30 from class CodeDevice
[2015-07-29 08:09:08.371] [I] [core] --- Starting module Code Device
[2015-07-29 08:09:08.391] [I] [core] Creating device switchBinary Code_Device_switchBinary_30
[2015-07-29 08:09:08.424] [I] [core] Instantiating module 31 from class CodeDevice
[2015-07-29 08:09:08.454] [I] [core] --- Starting module Code Device
How can I fix this?