Code: Select all
devices[N].SwitchBinary.data.level.bind(function()
{
some code
});
Code: Select all
vDev.on(’change:metrics:... ”, function (vDev) ... );
Code: Select all
devices[N].SwitchBinary.data.level.bind(function()
{
some code
});
Code: Select all
vDev.on(’change:metrics:... ”, function (vDev) ... );
Code: Select all
//Get vDev reference by deviceId
binarySensor = controller.devices.get('RemoteHA_3_ZWayVDev_zway_29-0-37');
// Subscribe to metrics:level change of the device
binarySensor.on('change:metrics:level', function (vDev) {
// The code is called when metrics:level of vDev is changed
// vDev is the reference of device
// So you can use it to retieve the level value
var level = binarySensor.get("metrics:level");
});
// Produce the same result as the example above for binarySensor.on
controller.devices.on(binarySensor, 'change:metrics:level', handler)
// Unsubscribe from receiving events
binarySensor.off('change:metrics:level', handler)
Thanks for the reply. I do get it partially. Don't understand what "handler" means.dolpheen wrote:Like this?Code: Select all
//Get vDev reference by deviceId binarySensor = controller.devices.get('RemoteHA_3_ZWayVDev_zway_29-0-37'); // Subscribe to metrics:level change of the device binarySensor.on('change:metrics:level', function (vDev) { // The code is called when metrics:level of vDev is changed // vDev is the reference of device // So you can use it to retieve the level value var level = binarySensor.get("metrics:level"); }); // Produce the same result as the example above for binarySensor.on controller.devices.on(binarySensor, 'change:metrics:level', handler) // Unsubscribe from receiving events binarySensor.off('change:metrics:level', handler)
Code: Select all
var sock = new sockets.udp();
sock.connect("192.168.1.33", 9091);
this.bindFunc1 = function (zwayName) {
if (zwayName != "zway")
return; // you want to bind to default zway instance
var devices = global.ZWave[zwayName].zway.devices;
//from here insert your devices
devices[2].SwitchBinary.data.level.bind(function () {
var status = (this.value) ? "on" : "off";
sock.send("ZWay_2," + status);
});
devices[3].SwitchBinary.data.level.bind(function () {
var status = (this.value) ? "on" : "off";
sock.send("ZWay_3," + status);
});
Handler means function to handle you event.pz1 wrote: Don't understand what "handler" means.
Code: Select all
binarySensor.on('change:metrics:level', function (vDev) {
var level = binarySensor.get("metrics:level");
sock.send(vDev.id + ',' + level); //Will send the id of vDev and status - on/off (for binary switch)
});
Code: Select all
var handler = function (vDev) {
var level = binarySensor.get("metrics:level");
sock.send(vDev.id + ',' + level); //Will send the id of vDev and status - on/off (for binary switch)
});
//Here we use handler variable that contains function to handle our event
binarySensor.on('change:metrics:level', handler)