Got extensive instructions from Poltos on how to make these bindings thing compatible with v2.0.0-
rc23 and higher.
For a binary switch it now is
Code: Select all
this.bindFunc1 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[2].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_2," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc1);
// UserCode module have not stop destructor, so this is commented...
// global.controller.off("ZWave.register", this.bindFunc1);
Unfortunately if I add more sensors, I do get a nasty error message for which I can not find a cause in the code. As a result, the last two of thirteen commands do not work. At a previous edit where I had the two commented lines (//) removed, there was only one of the thirteen sensors not working.
The failing sensors are the ones defined after the line where the error in UDPOR.js is reported.
LOG
Code: Select all
[2014-12-02 22:18:58.429] [I] [core] Executing script: /*** CodeDevice Z-Way HA module ******************************************* ...
[2014-12-02 22:18:58.431] [I] [core] Loading module CustomUserCodeLoader from modules/CustomUserCodeLoader
[2014-12-02 22:18:58.434] [I] [core] Executing script: /*** CustomUserCodeLoader ZAutomation module **************************************** ...
[2014-12-02 22:18:58.463] [I] [core] Instantiating module 15 from class CustomUserCodeLoader
[2014-12-02 22:18:58.466] [I] [core] --- Starting module Load custom JavaScript file
[2014-12-02 22:18:58.526] [I] [core] Executing script: this.bindFunc1 = function(zwayName) { ...
[2014-12-02 22:18:58.533] [I] [core] (node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit. 11
[2014-12-02 22:18:58.637] [E] [core] result: Error: TypeError: undefined is not a function
at AutomationController.EventEmitter.on (automation/lib/eventemitter2.js:391:19)
at automation/storage/UDPOR.js:111:19
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:225:22)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:302:22)
at Array.forEach (native)
at AutomationController.loadModule (automation/classes/AutomationController.js:301:86)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:318:73)
[2014-12-02 22:18:58.685] [I] [core] Notification: error (core): Can not init module CustomUserCodeLoader: Error: Uncaught TypeError: undefined is not a function
[2014-12-02 22:18:58.711] [I] [core] Error: Uncaught TypeError: undefined is not a function
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:225:22)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:302:22)
at Array.forEach (native)
at AutomationController.loadModule (automation/classes/AutomationController.js:301:86)
at AutomationController.<anonymous> (automation/classes/AutomationController.js:318:73)
at Array.forEach (native)
[2014-12-02 22:18:58.712] [I] [core] Loading module ScheduleSun from userModules/ScheduleSun
COMPLETE UDPOR.js CODE
Code: Select all
this.bindFunc1 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[2].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_2," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc1);
// UserCode module have not stop destructor, so this is commented...
// global.controller.off("ZWave.register", this.bindFunc1);
this.bindFunc2 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[3].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_3," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc2);
this.bindFunc3 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[6].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_6," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc3);
this.bindFunc4 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[7].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_7," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc4);
this.bindFunc5 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[21].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_21," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc5);
this.bindFunc6 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[26].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_26," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc6);
this.bindFunc7 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[30].instances[0].SensorBinary.data[1].level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_30_0_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc7);
this.bindFunc8 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[15].instances[1].SensorBinary.data[1].level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_15_1_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc8);
this.bindFunc9 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[15].instances[2].SensorBinary.data[1].level.bind(function()
{
var status = (this.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_15_2_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc9);
this.bindFunc10 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[13].instances[3].SensorMultilevel.data[1].val.bind(function()
{
var status = this.value;
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_13_3_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc10);
this.bindFunc11 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[13].instances[4].SensorMultilevel.data[1].val.bind(function()
{
var status = this.value;
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_13_4_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc11);
this.bindFunc12 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[13].instances[5].SensorMultilevel.data[1].val.bind(function()
{
var status = this.value;
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_13_5_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc12);
this.bindFunc13 = function(zwayName) {
if (zwayName != "zway") return; // you want to bind to default zway instance
global.ZWave[zwayName].zway.devices[13].instances[6].SensorMultilevel.data[1].val.bind(function()
{
var status = this.value;
system("/opt/z-way-server/automation/storage/status.sh", "ZWay_13_6_1," + status ) ;
} );
};
global.controller.on("ZWave.register", this.bindFunc13);