I did elaborate on the example of the bind function of Developers Guide 1.7 page 42.
The objective is to catch the status change of, in this case, a switch, and send the latest value to my OpenRemote Controller. The status.sh script takes care of that part. It does send (statusname,value)-pairs to the OpenRemote UDPListener. That script works.
In the new automation engine I have used the following code in CustomUserCode module.
Code: Select all
zway.devices[2].instances[0].SwitchBinary.data.level.bind(function()
{
var status = (zway.devices[2].SwitchBinary.data.level.value) ? "on" : "off";
system("/opt/z-way-server/automation/storage/status.sh", "Switch2Status," + status ) ;
} );
Code: Select all
#!/bin/bash
def_host=ds212
def_port=9091
HOST=${2:-$def_host}
PORT=${3:-$def_port}
echo -n "$1" | nc -4u -w 0 "$HOST" "$PORT"
exit
The OpenRemote end is working now.
============= Below this line is - for reference only - my original first post. ============================
I did follow this Recipe to setup my RaZberryAfter a Z-Way restart I found the following error in the log.Code: Select all
zway.devices[2].instances[0].SensorBinary.data.level.bind ( function() { var status = (zway.devices[2].SwitchBinary.data.level.value ? "on" : "off"; system("/opt/z-way-server/automation/storage/status.sh" + "Switch2Status," + status ) ; } )
What am I doing wrong? Are multiple statements not allowed in bind?Code: Select all
[2014-11-13 11:35:19.463] [I] [core] Instantiating module 12 from class CustomUserCode [2014-11-13 11:35:19.468] [I] [core] --- Starting module Load custom JavaScript code [2014-11-13 11:35:19.512] [I] [core] Executing script: zway.devices[2].instances[0].SensorBinary.data.level.bind ... [2014-11-13 11:35:19.537] [C] [core] JavaScript compilation error: SyntaxError: Unexpected token ; at CustomUserCode.init (automation/modules/CustomUserCode/index.js:36:30) at AutomationController.instantiateModule (automation/classes/AutomationController.js:225:22) at AutomationController.reconfigureInstance (automation/classes/AutomationController.js:415:22) at ZAutomationAPIWebRequest.<anonymous> (automation/webserver.js:606:44) at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/request.js:251:30) at automation/request.js:31:35 at WebServerRequestHandler (automation/main.js:221:10) [2014-11-13 11:35:19.567] [I] [core] Notification: error (core): Can not init module CustomUserCode: Error: JavaScript compilation error: Uncaught SyntaxError: Unexpected token ; [2014-11-13 11:35:19.587] [I] [core] Error: JavaScript compilation error: Uncaught SyntaxError: Unexpected token ; at Error (native) at CustomUserCode.init (automation/modules/CustomUserCode/index.js:36:30) at AutomationController.instantiateModule (automation/classes/AutomationController.js:225:22) at AutomationController.reconfigureInstance (automation/classes/AutomationController.js:415:22) at ZAutomationAPIWebRequest.<anonymous> (automation/webserver.js:606:44) at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/request.js:251:30) at automation/request.js:31:35 at WebServerRequestHandler (automation/main.js:221:10)