Page 1 of 1

JavaScript doesn't seem to work

Posted: 30 Aug 2015 07:35
by jstaffon
The problem below exists in both 2.0.0 and 2.0.1. I am currently running 2.0.1.

I have a JS that I've added via the Load custom JavaScript file App. The first two entries are looking for sensors 5 and 9 to trigger on motion. This part of the script works just fine. The BASH scripts below (movement-alert.bash and basement-alert.bash) send my iPhone text messages when they are triggered.

However, the last two entries for device 9 are for the temperature and LUX don't work. The device is an Aeon Multisensor that shows motion, temperature, humidity, battery status and LUX. I have the "temperature.bash" and "lights.bash" scripts in the .syscommands file. I doubt there's a typo anywhere in the scripts...they are pretty simple. I suspect the "if" statement in the JS file is malformed. If I want to check for 25.0 C and 20 LUX, is the JS below correct? I have also tried 25.0 and 20 without the quote marks. The actual values being displayed by the sensor is 21.7 C and 7 LUX but I don't receive text messages. Thanks in advance! Here is the file:

Code: Select all

zway.devices[5].instances[0].commandClasses[48].data[1].level.bind(function() {
   if (this.value == "1")
      system('/opt/z-way-server/automation/userModules/movement-alert.bash');
});

zway.devices[9].instances[0].commandClasses[48].data[1].level.bind(function() {
   if (this.value == "1")
      system('/opt/z-way-server/automation/userModules/basement-alert.bash');
});

zway.devices[9].instances[0].commandClasses[49].data[1].level.bind(function() {
   if (this.value < "25.0")
      system('/opt/z-way-server/automation/userModules/temperature.bash');
});

zway.devices[9].instances[0].commandClasses[49].data[3].level.bind(function() {
   if (this.value < "20")
      system('/opt/z-way-server/automation/userModules/lights.bash');
});

Re: JavaScript doesn't seem to work

Posted: 31 Aug 2015 17:26
by jstaffon
Here's an error message being reported... Not sure if it's relevant but seems suspicious.

"Cannot instantiate module: CustomUserCodeLoader: Error: Uncaught TypeError: Cannot read property 'bind' of undefined."

Thanks in advance.

Re: JavaScript doesn't seem to work

Posted: 01 Sep 2015 04:35
by jstaffon
Update: Solved.

I had the wrong structure..."level" should be replaced with "val" according to the device commandClass. Stupid mistake...

zway.devices[9].instances[0].commandClasses[49].data[3].val.bind(function() {
if (this.value < "20")
system('/opt/z-way-server/automation/userModules/basement-alert.bash');
});

Re: JavaScript doesn't seem to work

Posted: 01 Sep 2015 09:58
by pz1
It depends on the device type what you must choose. E.g. for SensorMultilevel it is val, for SensorBinary it is level

Re: JavaScript doesn't seem to work

Posted: 01 Sep 2015 16:57
by jstaffon
pz1,
Thanks. The more I work with these JavaScripts the more fun I'm having. The script seems to be working fine now but my device doesn't update or post automatically....not sure of the right terminology. I have to go into the Expert UI and manually "Update All" to get a response from my JavaScript. As soon as I click on the Update button, a text is sent to my phone. Wakeup time is set to 480 seconds in the "Configuration Settings" but nothing sent to my iPhone automatically. Any ideas?

Thanks.

Re: JavaScript doesn't seem to work

Posted: 01 Sep 2015 17:20
by pz1
Some older Z-Wave devices don't update automatically. The automatic update only works if your devices are associated with the controller (device 1) In assition some binary switches have some problems See Recipes topic: viewtopic.php?f=3424&t=20831

Re: JavaScript doesn't seem to work

Posted: 01 Sep 2015 21:20
by jstaffon
Thanks for the link. That was very interesting. Didn't know you could send commands to the devices via http and JS. My device is pretty new. See the specs below. I looked in the Expert UI "Associations" menu and it talks about "Devices to be switched on upon motion deteced and off after a timeout (on time) (maximum 5 devices)". I can add Device 1 (Raspberry) but it doesn't sound like it's the right association. Can you explain to me how to get the correct association? Right now I don't think this device has any associations.

Device Id 9
Device Name Aeon Multisensor
Brand Aeon Labs
Device type Routing Binary Sensor
Product Multi Sensor 1.18
Description Motion detector, temperature, luminosity and humidity sensor. Can be powered by USB
Application version 1.18
SDK version 5.03

Re: JavaScript doesn't seem to work

Posted: 02 Sep 2015 09:22
by pz1
hmm, I don't have any such devices, so I have to leave the answer about how to do the associations to others who do have experience with this or similar devices

Re: JavaScript doesn't seem to work

Posted: 09 Dec 2015 01:05
by waver
Hi,

I also want this movement detected association to work, but it does not.

I add the code you provided to my main.js.
When I request:
http://MYDOMAINNAME:8083/ZWaveAPI/Run/d ... a[1].level

I get:
{"name":"level","type":"bool","value":false,"updateTime":1449611478,"invalidateTime":1449611477}

you seem to bind to a 'level' that has a integer value.
Can you explain a little bit more how you get your system working?

Thanks