External request after mouvement detection
External request after mouvement detection
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.
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
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
I did the test with a Everspring SM103, i can see that in the log :
But my script is never called, somebody can help me plz ?
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)
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"}
Re: External request after mouvement detection
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
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.
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
I corrected one line :
by
Now i can see on the log that the code is executed.
But the next command see below is not executed :
Somebody know where is my fault plz ?
Code: Select all
zway.devices[11].instances[0].commandClasses.SensorBinary.data[1].level.bind(function()
Code: Select all
zway.devices[11].instances[0].commandClasses[48].data[1].level.bind(function() {
console.log('Point 1');
But the next command see below is not executed :
I added these lines on the file .syscommandssystem(
"/usr/bin/python /opt/z-way-server/automation/script/network_send.py",
Code: Select all
/usr/bin/python /opt/z-way-server/automation/script/network_send.py
Re: External request after mouvement detection
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:
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.
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
Re: External request after mouvement detection
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'
My /opt/z-way-server/automation/.syscommands file :
End my script : /opt/z-way-server/automation/script/test.sh
I didn't see "Mon premier script" from my bash script.
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);
}
});
Code: Select all
sh /opt/z-way-server/automation/script/test.sh
sh
I start the z-way-server with :#!/bin/bash
echo Mon premier script
When i action my Everspring SM103, i can see in the log :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
[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
Don't know if it's of any difference, but when I call a script I just do:
and I don't put "sh" in .syscommands, but my looks like:
Don't know if the echo goes to the log-file, but I would just redirect it to a file like:
Code: Select all
system("/opt/z-way-server/automation/script/test.sh");
Code: Select all
echo
/opt/z-way-server/automation/script/test.sh
Code: Select all
#!/bin/bash
echo "Mon premier script" > /tmp/test.txt
Re: External request after mouvement detection
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.
Thanks everybody for your help.