HWG SMS gateway integration into Homematic

Support for our english speaking visitors

Moderator: Co-Administratoren

Antworten
omicronCZ
Beiträge: 206
Registriert: 31.07.2011, 17:37
System: CCU
Wohnort: Czech Rep.
Hat sich bedankt: 80 Mal
Danksagung erhalten: 12 Mal

HWG SMS gateway integration into Homematic

Beitrag von omicronCZ » 01.10.2019, 20:56

Sending SMS messages via GSM network using GSM-SMS gateway without Internet
I have hardware (GSM-SMS gateway) with LAN Ehernet connection, through which it is possible to send an SMS message from various devices or even from the command line of a web browser via HTTP GET command (in the same local network).

The gate is very compact, in industrial design, the manufacturer is preparing its variant with PoE power supply. If the gateway is connected to an uninterruptible power supply UPS (as well as CCU and your home LAN technology), it will be a very robust and reliable solution for sending alarm SMS. For example, when power is turned off or the Internet is disconnected when a house is disrupted, and normal PUSH messages cannot be sent. Also, if you are with your smartphone somewhere where the Internet is not available, the SMS is still reliable wherever the GSM signal is available.
hwg-sms-gw3id56906.png
The gateway (where your regular SIM card is inserted) can send an alarm SMS or even call the specified phone number (6 rings). All this can be done with the help of the Homematic program and scripts

Finally, with the scripts helped me again great expert @Alchy (than you so much!). Let me therefore make the whole solution public.

Script for SMS (enter SMS text, destination phone number, user / admin for gateway access and gateway IP address)
This script sends an SMS message to the specified phone number

Code: Alles auswählen

! GSM-SMS gateway with Ehernet connection for omicronCZ - Script for SMS
! v0.7 (c) by Alchy https://homematic-forum.de/forum/viewtopic.php?f=49&t=53513&p=533054#p533054
string sMessage = "Domotica Alena - TEST GSM/SMS komunikace";
string sNumber = "0049xxxxxxxxx";
string sUser = "user";
string sPass = "password";
string sIP = "192.168.0.x";
!+++++++++++++++ Finger weg - dont touch +++++++++++++++++++
string url = "http://"#sUser#":"#sPass#"@"#sIP#"/values.xml?Cmd=SMS&Nmr="#sNumber#"&Text="#sMessage.UriEncode();
if ( (dom.GetObject(ID_DATAPOINTS)).Get("CUxD.CUX2801001:1.CMD_EXEC")) { (dom.GetObject(ID_DATAPOINTS)).Get("CUxD.CUX2801001:1.CMD_EXEC").State("/usr/local/addons/cuxd/curl '"#url#"'"); }
Call script (enter destination phone number, user / admin for gateway access and gateway IP address)
This script automatically calls the specified phone number, rings 6 times and then hangs up again

Code: Alles auswählen

! GSM-SMS gateway with Ehernet connection for omicronCZ - Call script
! v0.7 (c) by Alchy https://homematic-forum.de/forum/viewtopic.php?f=49&t=53513&p=533054#p533054
string sMessage = "Pozor toto je test prenosu SMS zpravy skrze SMS branu do smartphone";
string sNumber = "0049xxxxxxxxx";
string sUser = "user";
string sPass = "password";
string sIP = "192.168.0.x";
!+++++++++++++++ Finger weg - dont touch +++++++++++++++++++
string url = "http://"#sUser#":"#sPass#"@"#sIP#"/values.xml?Cmd=Call&Nmr="#sNumber;
if ( (dom.GetObject(ID_DATAPOINTS)).Get("CUxD.CUX2801001:1.CMD_EXEC")) { (dom.GetObject(ID_DATAPOINTS)).Get("CUxD.CUX2801001:1.CMD_EXEC").State("/usr/local/addons/cuxd/curl '"#url#"'"); }
Finally, big thanks to Alchy for help with the scripts.
Zuletzt geändert von omicronCZ am 18.05.2021, 17:01, insgesamt 3-mal geändert.

Matthias K.
Beiträge: 1165
Registriert: 14.02.2016, 12:32
System: Alternative CCU (auf Basis OCCU)
Wohnort: Heidenheim
Hat sich bedankt: 57 Mal
Danksagung erhalten: 225 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von Matthias K. » 02.10.2019, 16:44

You have to use URL encoding in your command (replace special characters by their percent encoded version).

omicronCZ
Beiträge: 206
Registriert: 31.07.2011, 17:37
System: CCU
Wohnort: Czech Rep.
Hat sich bedankt: 80 Mal
Danksagung erhalten: 12 Mal

HWG SMS gateway integration into Homematic

Beitrag von omicronCZ » 02.10.2019, 18:27

scorpionking hat geschrieben:
02.10.2019, 16:44
You have to use URL encoding in your command (replace special characters by their percent encoded version).
Which specific special characters?


All characters in this string:

Code: Alles auswählen

http://user:pass@192.168.1.1/values.xml?Cmd=SMS&Nmr=0049xxxyyyxxx&Text=Hello!
I normally use for "CMD_EXEC" using CUxD for other URL control strings without any problem.
From the command line it goes.


This simple script doesn't want me to go through:

Code: Alles auswählen

!..Script SMS Gateway
string url="http://user:pass@192.168.1.1/values.xml?Cmd=SMS&Nmr=0049111222333&Text=Hello!";
dom.GetObject("CUxD.CUX2801001:1.CMD_EXEC").State("wget -q -O - '"#url#"'");
Thank you for help
Zuletzt geändert von omicronCZ am 18.05.2021, 17:02, insgesamt 1-mal geändert.

Matthias K.
Beiträge: 1165
Registriert: 14.02.2016, 12:32
System: Alternative CCU (auf Basis OCCU)
Wohnort: Heidenheim
Hat sich bedankt: 57 Mal
Danksagung erhalten: 225 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von Matthias K. » 02.10.2019, 18:34

As far sas I know you only have to substitude the "Percent-encoding reserved characters" like "?", ":", "/", "!", "@", "&".

I guess in your case it is the Ampersand ("&") that's causing problems.

omicronCZ
Beiträge: 206
Registriert: 31.07.2011, 17:37
System: CCU
Wohnort: Czech Rep.
Hat sich bedankt: 80 Mal
Danksagung erhalten: 12 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von omicronCZ » 02.10.2019, 18:46

I try it:

Before change :

Code: Alles auswählen

http://user:pass@192.168.1.1/values.xml?Cmd=SMS&Nmr=0049111222333&Text=Hello
It does not work in script, it works from command line of web browser

After change (substitude "&" to "%26")

Code: Alles auswählen

http://user:pass@192.168.1.1/values.xml?Cmd=SMS%26Nmr=0049111222333%26Text=Hello
It does not work in script it does not work from command line of web browser :-(

Unfortunately it didn't help :?

omicronCZ
Beiträge: 206
Registriert: 31.07.2011, 17:37
System: CCU
Wohnort: Czech Rep.
Hat sich bedankt: 80 Mal
Danksagung erhalten: 12 Mal

Re: SMS gateway and CMD_EXEC - solved

Beitrag von omicronCZ » 02.10.2019, 22:26

So successfully resolved (over PM) with great help from the local Homematic script guru @Alchy :D
Thanks Alchy.

tomi_cc16
Beiträge: 1150
Registriert: 30.11.2013, 16:35
Wohnort: Mordor
Hat sich bedankt: 23 Mal
Danksagung erhalten: 56 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von tomi_cc16 » 02.10.2019, 23:12

Why not post the solution here so it can help more people

omicronCZ
Beiträge: 206
Registriert: 31.07.2011, 17:37
System: CCU
Wohnort: Czech Rep.
Hat sich bedankt: 80 Mal
Danksagung erhalten: 12 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von omicronCZ » 03.10.2019, 09:49

Of course, so I planned it :D , no problem with publishing solutions.

But now with @Alchy we are tuning the final version of the script with the possibility to transfer diacritics and spaces in the text of the SMS (conversion directly in the script).

When it is fully debugged and Alchy gives permission to publish it, I will certainly publish here the final version of the script.

alchy
Beiträge: 10752
Registriert: 24.02.2011, 01:34
System: CCU
Hat sich bedankt: 65 Mal
Danksagung erhalten: 672 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von alchy » 04.10.2019, 22:01

tomi_cc16 hat geschrieben:
02.10.2019, 23:12
Why not post the solution here so it can help more people
can help more people?
So help me!

i have a script:

Code: Alles auswählen

string sMessage = "Příliš žluťoučký kůň úpěl ďábelské ódy";
string sPerfect = "P%C5%99%C3%ADli%C5%A1%20%C5%BElu%C5%A5ou%C4%8Dk%C3%BD%20k%C5%AF%C5%88%20%C3%BAp%C4%9Bl%20%C4%8F%C3%A1belsk%C3%A9%20%C3%B3dy";
string sMesscon = sMessage.UriEncode();
if(sMesscon == sPerfect) {WriteLine("o.k.");}else{WriteLine("not o.k.");}
WriteLine(sMessage);
WriteLine(sPerfect);
WriteLine(sMesscon);
Why is not ok at Klickibunti but ok. at Executer?
:roll: :mrgreen:

Alchy

Blacklist................... almost full
Ignoranz ist die Summe aller Maßnahmen die man ergreift, um bestehende Tatsachen nicht sehen zu müssen.

© Sandra Pulsfort (*1974)

Lies bitte die Logik von WebUI Programmen und die Tipps und Tricks für Anfänger.

Wichtig auch CUxD ersetzt System.exec. Die HM Script Doku (Downloadart Skripte) hilft auch weiter.
Zum Testen von Scripten den >> HomeMatic Script Executor << von Anli benutzen.

omicronCZ
Beiträge: 206
Registriert: 31.07.2011, 17:37
System: CCU
Wohnort: Czech Rep.
Hat sich bedankt: 80 Mal
Danksagung erhalten: 12 Mal

Re: SMS gateway and CMD_EXEC

Beitrag von omicronCZ » 30.10.2019, 12:05

tomi_cc16 hat geschrieben:
02.10.2019, 23:12
Why not post the solution here so it can help more people
The complete solution is in the first post of this thread, thank you Alchy for your help with the scripts.

Antworten

Zurück zu „HomeMatic - english“