Page 1 of 1

source of a bind() information push

Posted: 03 Nov 2013 21:16
by dirkx
I have a number of devices that sent out temperature updates/sets - that I'd like to run some code on (a PID controller and a calendar based override).

What is the proper way to get the zDeviceID et.al. ? The naive code below is obviously not working ?

Thanks,

Dw.

PS: Also wondering if there is a way to trigger z-way to reload a *.js file (and give line numbers for errors) on the fly.


// File: /opt/z-way-server/automation/test.js
//
for(var i =2; i < 10; i++) {
console.log("registering "+i);
zway.devices.instances[0].ThermostatSetPoint.data[1].val.bind(function () {
console.log("Device ?? got set to " + this);
});
zway.devices.instances[0].SensorMultilevel.data[1].val.bind(function (somearg) {
console.log("Device "+somearg+" read value " + this);
});
}
// Does not yet exit this early?
// zway.dataUpdate.bind(function(a,b,c,d) { console.log("Some dataUpate "+a+"/"+b+"/"+c+"/"+d+" = "+this); });


New 1.4.1 release provides

Posted: 03 Nov 2013 21:16
by PoltoS
New 1.4.1 release provides lines and stack trace for errors.


You need to add one more param to the second bind() that will be passed as somearg in your function.

Also make sure that all devices from 2 to 9 contains ThermostatSetPoint and SensorMutilevel, otherwise the code will fail.

Thanks!

Posted: 03 Nov 2013 21:16
by dirkx
That works most splendidly. The second (and in case of a set, third/this) argument are the device ID passed during registration and the temperature in case of a SET.

What is the first argument passed ? An argument count ?

No, it is type of change (see

Posted: 03 Nov 2013 21:16
by PoltoS
No, it is type of change (see C headers to find them out - search for "Phantom" word)