Troubles Writing My First Automation Module

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
erturne
Posts: 2
Joined: 15 Jul 2014 06:16

Troubles Writing My First Automation Module

Post by erturne »

Yet another newbie here, so I apologize if this is simple. I received my RaspberryPi and Razberry, and have a door contact sensor. Just to get my feet wet I want to write an Automation module that logs something when the door is opened and closed. I tried writing a module to do just that, but it doesn't log anything.

Code: Select all

function FrontDoor( id, controller ) {
   FrontDoor.super_.call(this, id, controller);
}

inherits(FrontDoor, AutomationModule);

_module = FrontDoor;

FrontDoor.prototype.init = function __init__( config ) {
   FrontDoor.super_.prototype.init.call(this, config);

   var self = this;

   zway.devices[2].data.bind(function(d) {
      // TODO: Do something when the binary sensor changes.
      debugPrint(d);
   });
};

FrontDoor.prototype.stop = function __stop__() {
   FrontDoor.super_.prototype.stop.call( this );
};
The logs show my module being instantiated:

Code: Select all

[2014-07-15 03:12:55.278] Instantiating module 6 from class FrontDoor
[2014-07-15 03:12:55.283] --- Starting module Front door automation
From a hardware standpoint everything seems to be working. When I open and close my door the log on the server shows:

Code: Select all

[2014-07-15 03:13:23.225] RECEIVED: ( 01 09 00 04 00 02 03 30 03 FF 3F )
[2014-07-15 03:13:23.226] SENT ACK
[2014-07-15 03:13:23.228] SETDATA devices.2.data.lastReceived = 0 (0x00000000)
[2014-07-15 03:13:23.230] SETDATA devices.2.instances.0.commandClasses.48.data.1.level = True
[2014-07-15 03:13:23.231] SETDATA devices.2.instances.0.commandClasses.48.data.1 = Empty
[2014-07-15 03:13:23.244] RECEIVED: ( 01 09 00 04 00 02 03 20 01 FF 2D )
[2014-07-15 03:13:23.245] SENT ACK
[2014-07-15 03:13:23.246] SETDATA devices.2.data.lastReceived = 0 (0x00000000)
[2014-07-15 03:13:23.248] SETDATA devices.1.instances.0.commandClasses.32.data.srcNodeId = 2 (0x00000002)
[2014-07-15 03:13:23.249] SETDATA devices.1.instances.0.commandClasses.32.data.srcInstanceId = 0 (0x00000000)
[2014-07-15 03:13:23.261] SETDATA devices.1.instances.0.commandClasses.32.data.level = 255 (0x000000ff)
[2014-07-15 03:13:23.262] SETDATA devices.2.instances.0.commandClasses.48.data.1.level = True
[2014-07-15 03:13:23.264] SETDATA devices.2.instances.0.commandClasses.48.data.1 = Empty
[2014-07-15 03:13:24.485] RECEIVED: ( 01 09 00 04 00 02 03 30 03 00 C0 )
[2014-07-15 03:13:24.486] SENT ACK
[2014-07-15 03:13:24.487] SETDATA devices.2.data.lastReceived = 0 (0x00000000)
[2014-07-15 03:13:24.489] SETDATA devices.2.instances.0.commandClasses.48.data.1.level = False
[2014-07-15 03:13:24.491] SETDATA devices.2.instances.0.commandClasses.48.data.1 = Empty
But nothing from my calls to debugPrint ever show up in the log. I've tried a number of ways of binding a function to the device, but they all either fail with errors about not being able to access a property or call a function on an undefined value, or nothing ever gets logged.

Any suggestions? Thanks!
User avatar
kambis
Posts: 36
Joined: 23 Jun 2014 08:06
Location: Germany
Contact:

Re: Troubles Writing My First Automation Module

Post by kambis »

You may find some answers and how to bind events you are looking for by going through the example code found in the post: viewtopic.php?f=3424&t=20528
erturne
Posts: 2
Joined: 15 Jul 2014 06:16

Re: Troubles Writing My First Automation Module

Post by erturne »

kambis wrote:You may find some answers and how to bind events you are looking for by going through the example code found in the post: viewtopic.php?f=3424&t=20528
Thanks for that link! Just looking at the source code and using the values from my logs I was able to log the sensor value using:

Code: Select all

zway.devices[2].instances[0].commandClasses[48].data[1].level.bind(function() {
   // TODO: Do something when the binary sensor changes.
   debugPrint(this.value);
});
I'm definitely going through that post (and links) later to get a better understanding of what's going on, but it's nice to know I was close! Thanks again.
Post Reply