Multiple event-scripts in 1 script - 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: Multiple event-scripts in 1 script (/showthread.php?tid=750) |
Multiple event-scripts in 1 script - Mr.D - 24.04.2017 Hi, I need help to write a script (don't know which one is best for this task). I have magnets in doors and windows which is connected to the house alarm. I would like to write a script that sends a SMS telling me which door or window has been opened/closed. Each window/door has its own group address. I know I could write an Event-Script for each group address, but I am trying to avoid creating too many scripts. This is a typical Even-Script that could be created for each window/door, but is there a way I could collect all scripts in one, and send different SMS depending on which door/window has been opened/closed? if grp.getvalue('Status - Alarm - On/Off') == true then require('socket.http') socket.http.TIMEOUT = 1 socket.http.request('http://wwwwwwwww') end Thanks for your help. BR Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 24.04.2017 Hi, Add tags to the objects you want to monitor, and create a event based script that is linked to that tag and insert this to the event script: Code: if event.getvalue() == true then Where the log is now you can put your command to alert, mail, push or sms your string with the object name that triggers the event. BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 30.04.2017 Hi Erwin, Thanks for your reply and help. I am still a bit in the dark. The reason is that I send SMS by using Clickatell, and the message is part of an HTTP command. So I am struggling to get this ('value of ' .. grp.find(event.dst).name .. ' is true') a part of my http command. Also since I use Scandinavian language I need to translate the text to unicode... Is there a way to create a solution that send a unique http command, based on which ('value of ' .. grp.find(event.dst).name .. ' is true') is triggered? PS thank you for being so active on this forum and contributing and sharing your knowledge BR Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 30.04.2017 Hi, Can you test if this is working? Code: -- Perform action only on value true Erwin RE: Multiple event-scripts in 1 script - Mr.D - 04.05.2017 Hi Erwin, This almost gets me all the way I get the right object in my SMS but Clickatell does not support letters like æ å ø and inn my objects and text I use these letters. Therefor I need something like this: ('value of ' .. grp.find(event.dst).name .. ' is true') = (value of 1/1/1 is true) = 7093784523049875240897562 (this being unicode which supports åæø) When using your script I need the SMSText parameter to use the 7093784523049875240897562 instead of (value of 1/1/1 is true). ex. if the ('value of ' .. grp.find(event.dst).name .. ' is true') comes up with 'value of 1/1/1 is true' the correspondent to that would be '1234', if it came up with 'value of 2/2/2 is true', the correspondent would be '5678'. I hope this make sense, and if so, is there a way of doing this? Thanks Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 04.05.2017 Hi, You probably need octal unicode, but this script includes DEC, OCTAL and HTML formatting of UTF8: Try this: Code: function utf8tounicode(utf8str) BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 05.05.2017 Hi Erwin, Thank you for the script, just one question... How and where do I use this with the clickatell script you helped me with above...? BR Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 05.05.2017 Hi, Try this: Code: function utf8tounicode(utf8str) BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 05.05.2017 Hi Erwin, I tried this, but it does not seem to work. When using this script no SMS is generated. Just to try and problem solve I tried removing the Function script on top and the following from the below: Unicodetable = utf8tounicode(Eventname) -- Convert SMS text to unicode Unicodetable = utf8tounicode(SMSText) SMSText = Unicodetable[4] So the clickatell part seems to be working, but the conversion/funtion part must not work as intended... BR Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 05.05.2017 Hi, My mistake (: Remove line 40 as this is not valid (remain of testing). BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 05.05.2017 Hi, We are getting closer But it seems like the conversion uses the wrong kind of unicode.... it works fine if I remove the "unicode=1" from the url. But the result is a long string of numbers that don't mean anything... Clickatell has a text to unicode converter and I have compared the two strings generated from the converter and your script The result are different. On the text to unicode converter Clickatell have on their webpage it says "Converted output (UTF-16BE)", does this mean anything to you? I saw in your previous code/comment it stated UTF8... BR Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 05.05.2017 Hi, Yes it's now octal, i will check tonight as today i have a day off (: BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 05.05.2017 Hi Erwin, Thanks! Enjoy your day off Mr.D RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 06.05.2017 Hi, I checked some things and the function utf8tounicode returns utf-32 (codepoint), octal and html unicode. So basicly you need a codepoint to utf-16 big endian convert function to make it work. I searched the web for 1 but without results. Maybe admin can help you on this. BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 07.05.2017 Hi Erwin, Is it possible with a work around... By using the Text to Unicode converter on the clickatell website, I can translate the different text into the correct unicode format. So lets say that the text I went to send is already in Unicode format. If that was the case, then I would have to find a way to send the right text/unicode, depending on what object triggered the event. So lets say that the object 1/1/1 was the event.dst, then I would send text_A = 12345, if object 2/2/2 was the event.dst then text_B = 67890 is to be sent. It is not as sexy, but it might do the job....? Thanks for your help! BR, Mr.D RE: Multiple event-scripts in 1 script - admin - 08.05.2017 Try this, it only handles 1 and 2 byte utf8 characters, but this should be enough for your case: Code: function utf8cps(str) RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 08.05.2017 Hi, Thanks Admin! Then your code should be like this: Code: function utf8cps(str) Erwin RE: Multiple event-scripts in 1 script - admin - 08.05.2017 Erwin, you don't need to escape text before convertion to UTF16, otherwise it will not work at all (I've edited your code already ). UTF16 is converted to hex which does not need escaping as well. RE: Multiple event-scripts in 1 script - Erwin van der Zwart - 08.05.2017 (08.05.2017, 08:44)admin Wrote: Erwin, you don't need to escape text before convertion to UTF16, otherwise it will not work at all (I've edited your code already ). UTF16 is converted to hex which does not need escaping as well. Thanks!, then we also don't need the require('socket.url') (: (removed it already from sample) BR, Erwin RE: Multiple event-scripts in 1 script - Mr.D - 08.05.2017 Thank you guys!!! This works perfectly! BR, Mr.D |