Page 1 of 1
External request after mouvement detection
Posted: 05 May 2016 12:59
by Slayes
Hello,
I bought raspberry, razberry and fibaro sensor motion.
Somebody could tell me, how it's possible (with the more simple method) to send a external http request when the IR of the Fibaro has detected a mouvement ?
I'm sorry for my poor english, a sample will be more clear :
- When my Fibaro detected a mouvement
- Raspberry send this request :
http://www.xxxx.fr/entry.php?source=[ad ... sensorName]
I have a little knowledge in php, js, python.
Thanks by advance for your help.
Re: External request after mouvement detection
Posted: 06 May 2016 15:12
by Slayes
I tried this code, found on this post :
https://forum.z-wave.me/viewtopic.php?f=3422&t=20028
At the end of file main.js
Code: Select all
var zone = 'www.xxxx.fr/zwave/action.php?';
var port = 80;
zway.devices[11].instances[0].commandClasses.SensorBinary.data[1].level.bind(function() {
eventString = 'Device_11_Instance_0';
try {
system(
"python /opt/z-way-server/automation/script/network_send.py",
eventString,
this.value,
zone,
port
);
return;
} catch(err) {
debugPrint("Failed to execute script system call: " + err);
}
});
Code: Select all
#!/usr/bin/python2.7
import sys
import subprocess
zone = str(sys.argv[3])
port = int(sys.argv[4])
eventString = str(sys.argv[1])
payloadString = ''
print "Message de test"
sys.stdout.flush()
try:
payloadString = str(sys.argv[2])
except:
pass
try:
url = zone + "&source=" + eventString + "&value=" + payloadString
subprocess.call(["wget", "-O/dev/null", url])
sys.exit(0)
except:
sys.exit(0)
I did the test with a Everspring SM103, i can see that in the log :
Code: Select all
[2016-05-06 12:07:24.233] [D] [zway] SETDATA devices.11.data.lastReceived = 0 (0x00000000)
[2016-05-06 12:07:24.233] [D] [zway] SETDATA devices.1.instances.0.commandClasses.32.data.srcNodeId = 11 (0x0000000b)
[2016-05-06 12:07:24.233] [D] [zway] SETDATA devices.1.instances.0.commandClasses.32.data.srcInstanceId = 0 (0x00000000)
[2016-05-06 12:07:24.233] [D] [zway] SETDATA devices.1.instances.0.commandClasses.32.data.level = 0 (0x00000000)
[2016-05-06 12:07:24.234] [D] [zway] SETDATA devices.11.instances.0.commandClasses.48.data.1.level = False
[2016-05-06 12:07:24.234] [D] [zway] SETDATA devices.11.instances.0.commandClasses.48.data.1 = Empty
[2016-05-06 12:07:24.250] [I] [core] Notification: device-info (device-OnOff): {"dev":"Everspring General purpose (11.0.48.1)","l":"off"}
But my script is never called, somebody can help me plz ?
Re: External request after mouvement detection
Posted: 06 May 2016 19:59
by bogr
Sounds like it might be easier to just use the "HTTP Device" app and configure your URL for "URL for action ON" and then just create a "Logical Rule" with the condition "Fibaro sensor movement" in "Type of condition" and in section "Actions" you just chose "List of switches" = the newly created "HTTP device" and chose "On"?
Re: External request after mouvement detection
Posted: 07 May 2016 10:20
by Slayes
Thanks for your reply.
I tried this solution in first time, but i need to add more dynamic parameters in the request. I prefer try to use python for this task.
Re: External request after mouvement detection
Posted: 07 May 2016 11:14
by Slayes
I corrected one line :
Code: Select all
zway.devices[11].instances[0].commandClasses.SensorBinary.data[1].level.bind(function()
by
Code: Select all
zway.devices[11].instances[0].commandClasses[48].data[1].level.bind(function() {
console.log('Point 1');
Now i can see on the log that the code is executed.
But the next command see below is not executed :
system(
"/usr/bin/python /opt/z-way-server/automation/script/network_send.py",
I added these lines on the file .syscommands
Code: Select all
/usr/bin/python /opt/z-way-server/automation/script/network_send.py
Somebody know where is my fault plz ?
Re: External request after mouvement detection
Posted: 07 May 2016 11:58
by bogr
Ok, I understand you point about the need for more dynamic handling.
I guess that you have entered the values in .syscommands on each line like:
Code: Select all
/usr/bin/python
/opt/z-way-server/automation/script/network_send.py
I haven't messed around with python (just bash), but it looks like your python script has defined version 2.7, but in your syscommands you entered python? In my RPi I see that python links to python2.7, so maybe you have to add 2.7 as well to syscommands? Just grasping here

. Otherwise you could just try to replace the python script with a bash containing only an "echo test" just for testing and debugging and verifying that the system call part actually works. In that case the problem has to be python related.
Re: External request after mouvement detection
Posted: 08 May 2016 09:53
by Slayes
I don't understand, certainly i did an error but i don't see it.
In the end of the file '/opt/z-way-server/automation/main.js'
Code: Select all
var zone = 'www.xxx.fr/zwave/action.php?id_test=de&ede=defrfr';
var port = 80;
zway.devices[11].instances[0].commandClasses[48].data[1].level.bind(function() {
eventString = 'Device_11_Instance_0';
try {
console.log('Point 1');
console.log('Point 2');
system("sh /opt/z-way-server/automation/script/test.sh");
return;
} catch(err) {
debugPrint("Failed to execute script system call: " + err);
}
});
My /opt/z-way-server/automation/.syscommands file :
Code: Select all
sh /opt/z-way-server/automation/script/test.sh
sh
End my script : /opt/z-way-server/automation/script/test.sh
#!/bin/bash
echo Mon premier script
I start the z-way-server with :
sudo cp /dev/null /var/log/z-way-server.log && sudo /etc/init.d/z-way-server restart && tail -f /var/log/z-way-server.log
When i action my Everspring SM103, i can see in the log :
[D] [zway] RECEIVED: ( 01 09 00 04 00 0B 03 20 01 63 B8 )
[D] [zway] SENT ACK
[D] [zway] SETDATA devices.11.data.lastReceived = 0 (0x00000000)
[D] [zway] SETDATA devices.1.instances.0.commandClasses.32.data.srcNodeId = 11 (0x0000000b)
[D] [zway] SETDATA devices.1.instances.0.commandClasses.32.data.srcInstanceId = 0 (0x00000000)
[D] [zway] SETDATA devices.1.instances.0.commandClasses.32.data.level = 99 (0x00000063)
[D] [zway] SETDATA devices.11.instances.0.commandClasses.48.data.1.level = True
[D] [zway] SETDATA devices.11.instances.0.commandClasses.48.data.1 = Empty
[core] Point 1
[core] Point 2
[core] Notification: device-info (device-OnOff): {"dev":"Everspring General purpose (11.0.48.1)","l":"on"}
I didn't see "Mon premier script" from my bash script.
Re: External request after mouvement detection
Posted: 08 May 2016 16:18
by bogr
Don't know if it's of any difference, but when I call a script I just do:
Code: Select all
system("/opt/z-way-server/automation/script/test.sh");
and I don't put "sh" in .syscommands, but my looks like:
Code: Select all
echo
/opt/z-way-server/automation/script/test.sh
Don't know if the echo goes to the log-file, but I would just redirect it to a file like:
Code: Select all
#!/bin/bash
echo "Mon premier script" > /tmp/test.txt
Re: External request after mouvement detection
Posted: 09 May 2016 08:48
by Slayes
It was my fault, in my sh or python script i used 'echo' or 'print' to trace the execution of the script. And i monitored the file '/var/log/z-way-server.log'. It was a problem of linux knowledge.
Thanks everybody for your help.