Script for motion detection

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
LAN-Opfer
Posts: 98
Joined: 03 Oct 2014 13:23

Script for motion detection

Post by LAN-Opfer »

I have a Aeon Labs Multi Sensor (Id 14) and want to use it for control of my Outdoor lights.
I tried following script:

Code: Select all

zway.devices[14].SensorBinary.data[1].bind
(
function()
{
if (zway.devices[14].SensorMultilevel.data[3].val.value <= 100)
zway.devices[3].instances[0].SwitchBinary.Set(1);
zway.devices[3].instances[0].SwitchBinary.Set(0);

}
)
It Switches a Test-Actor on and off. But it has two disadvantages:

1. the script fires 2 times - first at te Moment the sensor detects a Motion and second a time period after detections (sensor Parameter no 3: Timeout period of no-motion detected before the Multisensor sends the OFF state after being triggered). The script causes firing for rising and falling edge, but with Parameter set to 1 second it is not really a Problem.

2. it ignites even if the value for the brightness is less than 100 Lux. I don't want to Switch On the lights on broad daylight.

Code: Select all

http://192.168.178.46:8083/JS/Run/zway.devices[14].SensorMultilevel.data[3].val.value
delivers the correct value for the brightness.
What is wrong?

Uwe
Z-Way v2.0.1-rc18 on Raspberry Pi
LAN-Opfer
Posts: 98
Joined: 03 Oct 2014 13:23

Re: Script for motion detection

Post by LAN-Opfer »

...I think, I have a strange Problem with my Z-Way Home Automation UI. I have delete the 2 lines
  • zway.devices[3].instances[0].SwitchBinary.Set(1);
    zway.devices[3].instances[0].SwitchBinary.Set(0);
Nevertheless the scripts worked. Then I removed the whole script an did a reboot.
Then I created the same script new. Now it did not work. I get the error
"Can not init module CustomUserCode: Error:
Uncaught ReferenceError: zway is not defined"

Any idea?

Uwe
Z-Way v2.0.1-rc18 on Raspberry Pi
LAN-Opfer
Posts: 98
Joined: 03 Oct 2014 13:23

Re: Script for motion detection

Post by LAN-Opfer »

I removed the script again an did a reboot. I get the same error again:
"Can not init module CustomUserCode: Error:
Uncaught ReferenceError: zway is not defined"
Very strange
A script, which worked before without any Problems did not work any more. I only saved the script (without change) and now it works again.
Z-Way v2.0.1-rc18 on Raspberry Pi
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: Script for motion detection

Post by PoltoS »

This is a pretty common problem: your script runs before zway started. Run it on ZWave.register event: viewtopic.php?f=3422&t=21028&p=54047&hi ... ter#p54047

Also you miss "else" between to commands with Set(1) and Set(0)

Also this.value is the value of the dataholder you added the bind(), so adding "if (this.value)" will help.
LAN-Opfer
Posts: 98
Joined: 03 Oct 2014 13:23

Re: Script for motion detection

Post by LAN-Opfer »

Thanks for the advice, but I think, I could not understand it really. Unfortunately I have not programmed in JavaScript before.
I tried:

Code: Select all

this.bindFunc1 = function(zwayName) {
   if (zwayName != "zway") return; // you want to bind to default zway instance
   debugPrint("Binding enabled");
   var devices = global.ZWave[zwayName].zway.devices;

devices[14].SensorBinary.data[1].bind
(
function()
{
if (zway.devices[14].SensorMultilevel.data[3].val.value <= 200)
devices[13].instances[0].Basic.Set(99);
devices[13].instances[0].Basic.Set(50);
devices[13].instances[0].Basic.Set(99);
devices[13].instances[0].Basic.Set(0);
});
};
global.controller.on("ZWave.register", this.bindFunc1);
This code is only to see an effect - it is not ready

Code: Select all

if (zway.devices[14].SensorMultilevel.data[3].val.value <= 200)
devices[13].instances[0].Basic.Set(99);
devices[13].instances[0].Basic.Set(50);
devices[13].instances[0].Basic.Set(99);
devices[13].instances[0].Basic.Set(0);
It lacks a delay time and a lock, if the light was switched on manually.
I am also not clear how I need to use the values of the sensor.

The Trigger should be done by the motion

Code: Select all

devices[14].SensorBinary.data[1].bind
But I need also a lock with the value of brightness

Code: Select all

if (zway.devices[14].SensorMultilevel.data[3].val.value <= 200)
How do I correct this?

Uwe
Z-Way v2.0.1-rc18 on Raspberry Pi
LAN-Opfer
Posts: 98
Joined: 03 Oct 2014 13:23

Re: Script for motion detection

Post by LAN-Opfer »

does anyone have some working examples for me?
Z-Way v2.0.1-rc18 on Raspberry Pi
Post Reply