Release Candidate 21 binding problems

Discussions about RaZberry - Z-Wave board for Raspberry computer
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Release Candidate 21 binding problems

Post by pz1 »

FYI
My bindings are no longer working with v2.0.0-rc21

CODE

Code: Select all

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 ) ;
} );
LOG

Code: Select all

[2014-11-24 11:18:06.686] [I] [core] Loading module CustomUserCodeLoader from modules/CustomUserCodeLoader
[2014-11-24 11:18:06.690] [I] [core] Executing script:   /*** CustomUserCodeLoader ZAutomation module **************************************** ...
[2014-11-24 11:18:06.700] [I] [core] Instantiating module 15 from class CustomUserCodeLoader
[2014-11-24 11:18:06.704] [I] [core] --- Starting module Load custom JavaScript file
[2014-11-24 11:18:06.747] [I] [core] Executing script: zway.devices[2].instances[0].SwitchBinary.data.level.bind(function()  ...
[2014-11-24 11:18:06.844] [E] [core] result: Error: ReferenceError: zway is not defined
    at automation/storage/UDPSendStatusOR.js:1:1
    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-11-24 11:18:06.903] [I] [core] Notification: error (core): Can not init module CustomUserCodeLoader: Error: Uncaught ReferenceError: zway is not defined
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Release Canditate 21 binding problems

Post by pofs »

This may happen if your usercode module starts before ZWave binding (so zway object is not defined yet).

We're now considering creating binding-specific usercode, so it is guaranteed to load only when binding is started, and unload when it is stopped. I'll post an update when it will be clear.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Release Candidate 21 binding problems

Post by pz1 »

Thanks for the explanation. I'll stay on rc20 for a while to better test robustness of the UDP connector.
Since 29-12-2016 I am no longer a moderator for this forum
User avatar
PoltoS
Posts: 7579
Joined: 26 Jan 2011 19:36

Re: Release Candidate 21 binding problems

Post by PoltoS »

Pieter, we have released rc24. We are trying to get closer and closer to a final release. We will appreciate any feedback on this RC. You can contact me directly for faster feedback.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Release Candidate 21 binding problems

Post by pz1 »

I'll give it a run later today
Since 29-12-2016 I am no longer a moderator for this forum
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Release Candidate 21 binding problems

Post by pz1 »

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);
Since 29-12-2016 I am no longer a moderator for this forum
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Release Candidate 21 binding problems

Post by pofs »

Why don't you use just one handler for ZWave.register, and then perform all that binds inside it? It would be much more readable.

Code: Select all

this.bindFunc1 = function(zwayName) {
  if (zwayName != "zway") return; // you want to bind to default zway instance
  
  var devices = global.ZWave[zwayName].zway.devices;

  devices[2].SwitchBinary.data.level.bind(function()
  {
      var status = (this.value) ? "on" : "off";
      system("/opt/z-way-server/automation/storage/status.sh", "ZWay_2," + status ) ;
  });

  devices[3].SwitchBinary.data.level.bind(function()
  {
      var status = (this.value) ? "on" : "off";
      system("/opt/z-way-server/automation/storage/status.sh", "ZWay_3," + status ) ;
  });

  devices[6].SwitchBinary.data.level.bind(function()
  {
      var status = (this.value) ? "on" : "off";
      system("/opt/z-way-server/automation/storage/status.sh", "ZWay_6," + status ) ;
  });

  devices[7].SwitchBinary.data.level.bind(function()
  {
      var status = (this.value) ? "on" : "off";
      system("/opt/z-way-server/automation/storage/status.sh", "ZWay_7," + status ) ;
  });

  devices[21].SwitchBinary.data.level.bind(function()
  {
      var status = (this.value) ? "on" : "off";
      system("/opt/z-way-server/automation/storage/status.sh", "ZWay_21," + status ) ;
  });

  devices[26].SwitchBinary.data.level.bind(function()
  {
      var status = (this.value) ? "on" : "off";
      system("/opt/z-way-server/automation/storage/status.sh", "ZWay_26," + status ) ;
  });

  devices[30].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 ) ;
  });

  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 ) ;
  });

  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 ) ;
  });

  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 ) ;
  });

  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 ) ;
  });

  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 ) ;
  });

  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.bindFunc1);
Furthermore, you can enumerate all devices/instances/CCs (and listen for the future ones), and set up those bindings automatically, based on available CCs.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Release Candidate 21 binding problems

Post by pz1 »

pofs wrote:Why don't you use just one handler for ZWave.register, and then perform all that binds inside it? It would be much more readable.
To be honest, because I don't have the slightest idea how these things work. So thank you for this. I'll give it a try and see if more can be handled.
Furthermore, you can enumerate all devices/instances/CCs (and listen for the future ones), and set up those bindings automatically, based on available CCs.
I did get a basic template for that from Sergeui, but that is even further out of my league ;) Besides, I would like to test this UDP connection to OpenRemote a bit longer to see its stability. Ultimately I would like to have a module, where I can select the sensors that are being send over UDP. Maybe even at the level of Zway virtual devices to make it more generic. But as said my knowledge is limited, and I can better leave it to the judgement of the zway-team to tell what is wisdom on this issue.
Since 29-12-2016 I am no longer a moderator for this forum
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Release Candidate 21 binding problems

Post by pz1 »

Get all specified sensors now. I'll fill the remainder to see if it continues to scale.
Thanks
Since 29-12-2016 I am no longer a moderator for this forum
digitaldan
Posts: 11
Joined: 11 Sep 2014 18:53

Re: Release Candidate 21 binding problems

Post by digitaldan »

I am attempting to do something similar. I can see my script being loaded, my first debug statement prints to the console, unfortunately my function with the second debug statement never gets called. I'm on rc24, any ideas?

Code: Select all

this.bindFunc1 = function(zwayName) {
  debugPrint("Binding enabled! " + zwayName);
}
debugPrint("Trying to bind Custom module");
global.controller.on("ZWave.register", this.bindFunc1);

Post Reply