[HowTo] Send status updates as UDP messages

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: [HowTo] Send status updates as UDP messages

Post by pz1 »

I don't see how and why I should iterate. These bindings work perfectly for weeks from the moment they got started properly. To me it seems that the unpredicatble startup behaviour of modules is the core problem.

Anyhow it is at yet unclear to me how I should iterate the bindings. Does it have to go forever, or is there a stop criterion

As said before, I did elaborate on the code for individual devices I got from PoltoS:

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);
* note: this is older code that worked well under previous versions for a long time. Here I do make system calls to a script that uses netcat to send UDP messages
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: [HowTo] Send status updates as UDP messages

Post by pofs »

pz1 wrote:Anyhow it is at yet unclear to me how I should iterate the bindings. Does it have to go forever, or is there a stop criterion
Just once, before subscribing to future notifications. If zway is created before your code executes, it will be processed during iteration, otherwise you'll receive notification and handle it.

First few lines is what is missing in your code:

Code: Select all

// process all active bindings
if (global.ZWave) {
  global.ZWave().forEach(this.bindFunc1);
}

// and listen for future ones
global.controller.on("ZWave.register", this.bindFunc1);
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: [HowTo] Send status updates as UDP messages

Post by pz1 »

Now I got it. Initially I thought this had to go to the beginning of the file. Now I understood I had to add it just before the last line.
Both machines now got it right after the reboot. Thanks for your patience

UPDATE: I have updated the recipe in the first post. Successfully performed several restarts of both my Raspberries. So I consider the code now as stable
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: [HowTo] Send status updates as UDP messages

Post by pz1 »

Successfully tested this morning with Openremote Pro 2.6 Alpha, which contains Drools 6.4. This release should work with Java 8 now.
Post Reply