Logic Machine Forum
KNX PIR detection should execute url (WLED) - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: KNX PIR detection should execute url (WLED) (/showthread.php?tid=3679)



KNX PIR detection should execute url (WLED) - MaGer - 13.11.2021

Hello all,

I am currently struggling with the integration of my WLED environment.
https://github.com/Aircoookie/WLED

The goal is that when my KNX motion detectors detect a movement their group address jumps to 1, that then a URL is called which activates the preset provided in the WLED controller. At 0, the 2nd URL should be executed, which again deactivates the lights.
With the URLs no value must be given, but only the URL must be called.
How must the script look, or where do I have to store this, so that it does not require too much performance.
Scripting => Event-Controlled => Add new script????

Here is the final score of my futile attempts:

################## START ######################

PIR1 = grp.getvalue('1/1/19')
PIR2 = grp.getvalue('1/1/20')
WLEDon = 'http://192.168.178.128/win&T=1'
WLEDoff = 'http://192.168.178.128/win&T=0'

http = require('socket.http')

if PIR1 or PIR2 == 1 then
http = 'http://192.168.178.128/win&T=1'
else
url = 'http://192.168.178.128/win&T=0'
end

################## END ########################

Error Message: 
[wiser.Client] 13.11.2021 02:59:46

RPC_SOCKET_SYSTEM:


Many thanks for your support.

Best regards.
Martin


RE: KNX PIR detection should execute url (WLED) - Erwin van der Zwart - 14.11.2021

Try this:
Code:
http = require('socket.http')

PIR1 = grp.getvalue('1/1/19')
PIR2 = grp.getvalue('1/1/20')

if PIR1 or PIR2 then
   http.request('http://192.168.178.128/win&T=1')
else
   http.request('http://192.168.178.128/win&T=0')
end



RE: KNX PIR detection should execute url (WLED) - MaGer - 15.11.2021

It's amazing, it works. So fast it can work if you know the material.

After I have now "seen through" the script with your help, I could combine this with my day / night circuit, so that from night circuit (0) the orientation light goes on. Cool If one of the motion detectors detects something (1) the FullLight goes on and at (0) back to the orientation light. With night switching to day (1) nothing is triggered.

Enclosed the working script:


Code:
http = require('socket.http')

PIR1 = grp.getvalue('1/1/19')
PIR2 = grp.getvalue('1/1/20')
DayNight = grp.getvalue('0/4/0')

if DayNight then
   http.request('http://192.168.178.128/win&T=0')
   goto Sprung1
end

if
   PIR1 or PIR2 then
   http.request('http://192.168.178.128/win&PL=2')
else
   http.request('http://192.168.178.128/win&PL=3')
end

::Sprung1::

Many thanks. This thread can be closed.
Best regards. 
Martin


RE: KNX PIR detection should execute url (WLED) - Erwin van der Zwart - 16.11.2021

You can change the goto Sprung1 into return and remove ::Sprung1:: to stop executing the rest of the script
Code:
http = require('socket.http')

PIR1 = grp.getvalue('1/1/19')
PIR2 = grp.getvalue('1/1/20')
DayNight = grp.getvalue('0/4/0')

if DayNight then
   http.request('http://192.168.178.128/win&T=0')
   return
end

if PIR1 or PIR2 then
   http.request('http://192.168.178.128/win&PL=2')
else
   http.request('http://192.168.178.128/win&PL=3')
end