24.04.2017, 17:33 (This post was last modified: 24.04.2017, 17:34 by Mr.D.)
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 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
04.05.2017, 15:21 (This post was last modified: 04.05.2017, 20:35 by Mr.D.)
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
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
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
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.
08.05.2017, 09:09 (This post was last modified: 08.05.2017, 09:11 by Erwin van der Zwart.)
(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') (: