HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: nolio on December 07, 2014, 09:11:32 PM

Title: Alarm add on (sms,...)
Post by: nolio on December 07, 2014, 09:11:32 PM
Hi,

I create a script (all in french for now) to add function in a centralize place (before i add code in the "90-Security Alarm System", or wizard script). So now my script permit in the 3 following case :
To do the following actions :
All this function are only activate in case of the field are fill in.

If some people think it can useful for us too, i probably have to :
So tell me :).

It takes me some times (probably because i am not a programmer), but i found the result very useful and i am proud to success :).
Thanks Gene for the help on debugging script and for the good job on HomeGenie.

Bye
Title: Re: Alarm add on (sms,...)
Post by: dani on December 14, 2014, 12:08:38 PM
Hi Nolio,

I think you have made a good job. I will try it as soon as possible.

Cheers
Dani
Title: Re: Alarm add on (sms,...)
Post by: nolio on December 27, 2014, 02:51:52 PM
Hi,
I update this script :
Bye
Title: Re: Alarm add on (sms,...)
Post by: nolio on July 02, 2015, 11:45:40 PM
Hi,
I work on 2 modifications on the sms part, by using of gammu-smsd instead of gammu :
1/ Install gammu-smsd :
[/list]
Code: [Select]
apt-get install gammu-smsd2/ Configure by editing /etc/gammu-smsdrc :
Code: [Select]
[gammu]
port = /dev/ttyUSB?
connection = at19200
3/ Test configuration :
Code: [Select]
echo "test !!" | gammu-smsd-inject TEXT <your phone number>4/ Modify in my "Alarm add on" HG script :
this :
Code: [Select]
Arguments = "-c \"echo '"+text+"' | /usr/bin/gammu --sendsms TEXT "+tel+"\"",by this :
Code: [Select]
Arguments = "-c \"echo '"+text+"' | gammu-smsd-inject TEXT "+tel+"\"", 1/ Configure by editing /etc/gammu-smsdrc :
Code: [Select]
[smsd]
runonreceive = /home/pi/receivesms.sh
2/ create file receivesms.sh in /home/pi/ (for example) :
Code: [Select]
#!/bin/sh
if [ "$SMS_1_TEXT" = "alarm on" ] ; then
wget 0 q t 1 --http-user=admin --http-password='<your HG password>' --auth-no-challenge  "http://<your HG IP address>:<your HG port>/api/HomeAutomation.HomeGenie.Automation/90/Control.On/1393535869092" >/dev/null 2>&1
fi
if [ "$SMS_1_TEXT" = "alarm off" ] ; then
wget 0 q t 1 --http-user=admin --http-password='<your HG password>' --auth-no-challenge  "http://<your HG IP address>:<your HG port>/api/HomeAutomation.HomeGenie.Automation/90/Control.Off/1393536682120" >/dev/null 2>&1
fi

Bye
Title: Re: Alarm add on (sms,...)
Post by: djatie on July 20, 2015, 01:46:52 AM
I dont understand about this
/90/Control.On/1393535869092
How to on off my gpio?
Thx for help
Title: Re: Alarm add on (sms,...)
Post by: nolio on July 20, 2015, 07:03:11 AM
I dont understand about this
/90/Control.On/1393535869092

It permit to turn the alarm on by the api.
How to on off my gpio?
Thx for help

You need to find the control api of gpio.
http://www.homegenie.it/docs/api/overview.html (http://www.homegenie.it/docs/api/overview.html)
Title: Re: Alarm add on (sms,...)
Post by: djatie on July 29, 2015, 11:10:09 PM
http://169.254.122.100/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.HomeGenie.Automation/100 (http://169.254.122.100/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.HomeGenie.Automation/100)


Show like this

{
   "Name": "GPIO Modules",
   "Description": "",
   "DeviceType": "Program",
   "Domain": "HomeAutomation.HomeGenie.Automation",
   "Address": "100",
   "Properties": [
       {
           "Name": "ConfigureOptions.GPIO17",
           "Description": "GPIO17 (IN, OUT or OFF)",
           "Value": "OFF",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO18",
           "Description": "GPIO18 (IN, OUT or OFF)",
           "Value": "OFF",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO21",
           "Description": "GPIO21 (IN, OUT or OFF)",
           "Value": "OFF",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO22",
           "Description": "GPIO22 (IN, OUT or OFF)",
           "Value": "OUT",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO23",
           "Description": "GPIO23 (IN, OUT or OFF)",
           "Value": "OUT",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO24",
           "Description": "GPIO24 (IN, OUT or OFF)",
           "Value": "OFF",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO25",
           "Description": "GPIO25 (IN, OUT or OFF)",
           "Value": "OUT",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "ConfigureOptions.GPIO4",
           "Description": "GPIO04 (IN, OUT or OFF)",
           "Value": "OFF",
           "UpdateTime": "2015-07-29 19:20:04Z"
       },
       {
           "Name": "Program.Status",
           "Description": "",
           "Value": "Idle",
           "UpdateTime": "2015-07-29 19:20:10Z"
       },
       {
           "Name": "VirtualModule.ParentId",
           "Description": "",
           "Value": "100",
           "UpdateTime": "2014-04-11 18:45:32Z"
       },
       {
           "Name": "Widget.DisplayModule",
           "Description": "",
           "Value": "",
           "UpdateTime": "2014-04-11 18:45:31Z"
       }   ],
   "RoutingNode": ""
}



Then i use my web browser with this URL
http://169.254.122.100/api/HomeAutomation.HomeGenie.Automation/100/ConfigureOptions.GPIO22/Control.On (http://169.254.122.100/api/HomeAutomation.HomeGenie.Automation/100/ConfigureOptions.GPIO22/Control.On) <--- Nothing happen

http://169.254.122.100/api/HomeAutomation.HomeGenie.Automation/100/GPIO22/Control.On (http://169.254.122.100/api/HomeAutomation.HomeGenie.Automation/100/GPIO22/Control.On) <--- Nothing happen

http://169.254.122.100/api/RaspberryPi.GPIO/22/Control.On (http://169.254.122.100/api/RaspberryPi.GPIO/22/Control.On) <--- Nothing happen

Any somthing missing? Pls help

Title: Re: Alarm add on (sms,...)
Post by: djatie on July 31, 2015, 06:12:42 AM
I found my problem  ;D
I modificate on RaspberryPi.Gpio Program modul

on last script im change with this

// implement web serice API Control.On, Control.Off, Control.Toggle
// for the domain RaspberryPi.GPIO
When.WebServiceCallReceived("RaspberryPi.Gpio", ( args ) =>
                            {
                              string[] reqs = ((string)args).Split('/');
                         var res = "{ 'ResponseValue' : 'ERROR' }";
   
                        //Command cmd = new Command((string)args);
                         try
                              {
                                string command = reqs[2];
                         string Gpioid = reqs[1];
                           var module = Modules.InDomain("HomeGenie.Gpio").WithAddress(Gpioid).Get();
                         //
                           switch(command)
                                {
                                  // eg. http://hg_address/api/RaspberryPi.GPIO/1/Control.On (http://hg_address/api/RaspberryPi.GPIO/1/Control.On)
                                  case "Control.On":
                                  connection[Gpioid] = true;
                              Program.RaiseEvent(module, "Status.Level", "1", "Gpio " + Gpioid);
                              res = "{ 'ResponseValue' : 'OK' }";
                               break;
               
                                  break;
                                  // eg. http://hg_address/api/RaspberryPi.GPIO/3/Control.Off (http://hg_address/api/RaspberryPi.GPIO/3/Control.Off)
                                  case "Control.Off":
                                  connection[Gpioid] = false;
                              Program.RaiseEvent(module, "Status.Level", "0", "Gpio " + Gpioid);
                              res = "{ 'ResponseValue' : 'OK' }";
                                  break;
                                  // eg. http://hg_address/api/RaspberryPi.GPIO/9/Control.Toggle (http://hg_address/api/RaspberryPi.GPIO/9/Control.Toggle)
                                  case "Control.Toggle":
                                  connection[Gpioid] = !connection[Gpioid];
                              Program.RaiseEvent(module, "Status.Level", connection[Gpioid] ? "1" : "0", "Gpio " + Gpioid);
                              res = "{ 'ResponseValue' : 'OK' }";
                                  break;
                                }
                                //
                                return "{ 'ResponseValue' : 'OK' }";   
                              }
                              catch (Exception ex)
                              {
                               res = ex.Message + " " + ex.StackTrace;
                              }
                              // unable to process request
                              return res;
                            });

Now its can on off gpio using web call thanks ITS GREAT SOFWARE  ;D ;D ;D ;D
Title: Re: Alarm add on (sms,...)
Post by: djatie on August 30, 2015, 02:59:21 AM
i have create new program to control sms gpio ON or OFF

i use like sample
runonreceive = /home/pi/receivesms.sh

my scipt like this
if [ "$SMS_1_TEXT" = "23on" ] ; then
                wget 0 q t 1 --http-user=admin --http-password='' --auth-no-challenge  "http://169.254.122.100/api/RaspberryPi.Gpio/GPIO23/Control.On" >/dev/null 2>&1$
fi


noting happen with my gpio

scrip no 2
if [ "$SMS_1_TEXT" = "23on" ] ; then
curl 'http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On' (http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On')
fi

notting happen to with my gpio

PLS HELP WHAT HAPPEN THIS?
I use smstools3 with curl it can executed gpio can on and off
Title: Re: Alarm add on (sms,...)
Post by: djatie on August 30, 2015, 04:53:56 AM
I have remove
this -->if [ "$SMS_1_TEXT" = "23on" ] ; then
curl 'http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On' (http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On')
and this ->fi

so it just
curl 'http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On' (http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On')

i send some sms then its on. i use new gammu. OMG how to fix this  :( :( :( :( :( :( :(
Title: Re: Alarm add on (sms,...)
Post by: nolio on August 30, 2015, 08:42:00 AM
I have remove
this -->if [ "$SMS_1_TEXT" = "23on" ] ; then
curl '[url]http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On'[/url] ([url]http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On'[/url])
and this ->fi

so it just
curl '[url]http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On'[/url] ([url]http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On'[/url])

In that case, every sms receive will turn on your GPIO23, is that you want ?
I update my script like that :
Code: [Select]
if [[ "$SMS_1_TEXT" == *"xxxxxxxxx"* ]] ; then
and with at the begining (don't care of case): 
Code: [Select]
shopt -s nocasematchand at the end (care of case again):
Code: [Select]
shopt -u nocasematch
With "xxxxxxxxx", the string to test.
Perhaps you can try ...

Good luck.
Title: Re: Alarm add on (sms,...)
Post by: djatie on September 06, 2015, 08:46:06 PM
I have remove my gammu, then i use SMS server tools 3, now work properly, i have problem installing gammu.
I will share my sms remote control soon
:):)
Title: Re: Alarm add on (sms,...)
Post by: nolio on September 06, 2015, 08:50:00 PM
Ok what kinds of problem with gamma install ?
Share share :-)
Title: Re: Alarm add on (sms,...)
Post by: djatie on September 10, 2015, 12:08:57 AM
i have install newer version gammu. its canot send and receive sms. i dont know why. im not familiar with gammu, and not unix/linux user. Im reinstall with old version, can send sms but can not receive sms, may problem with receive daemon. Im tired to try use gammu like on tutorial. Im know Visual Studio so then use java python bash ksh it make me dizzy im newbie in here, blank dont know how to write script, than i back to sms tools 3, its more simple and have facility like gammu.
I will share soon, now i want HG GPIO can remote use jaber xmpp. Try to loving linux/unix :D:D:D:D:D
Title: Re: Alarm add on (sms,...)
Post by: nolio on August 17, 2016, 01:09:36 AM
Hi all,

Since some month,  i use SMS every day to arm/disarm my HomeGenie alarm.

But last week, i update my bash script to do more (with HomeGenie API) :
1/ Receive some device information : temperature, level status
2/ Do some actions : close, open, nearly close shutter

Example in the joint picture.

I share with you the script (which is not perfect but it work fine !) "receivesms.sh", but it is just an example customize with my own devices, so you have to customize to your ;) :
Code: [Select]
#!/bin/bash

shopt -s nocasematch
if [[ "$SMS_1_TEXT" == *"alarm on"* ]] ; then
        wget 0 q t 1 --http-user=admin --http-password='<HG password>' --auth-no-challenge  "http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie.Automation/90/Control.On/1393535869092" >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"alarm off"* ]] ; then
        wget 0 q t 1 --http-user=admin --http-password='<HG password>' --auth-no-challenge  "http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie.Automation/90/Control.Off/1393536682120" >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"camou"* ]] ; then
        wget 0 q t 1 --http-user=admin --http-password='<HG password>' --auth-no-challenge  "http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Automation/Programs.Run/1042" >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"ouvert"* ]] ; then
        wget 0 q t 1 --http-user=admin --http-password='<HG password>' --auth-no-challenge "http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Automation/Programs.Run/1041" >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"fermet"* ]] ; then
        wget 0 q t 1 --http-user=admin --http-password='<HG password>' --auth-no-challenge "http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Automation/Programs.Run/1000" >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"temper"* ]] ; then
TempDetectSalon="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/31/ | grep -A 1 -B 1 "Sensor.Temperature" | grep -Po '(?<="Value": ")[^"]*')"
TempDetectSalon3="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/54/ | grep -A 1 -B 1 "Sensor.Temperature" | grep -Po '(?<="Value": ")[^"]*')"
TempDetectGarage="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/61/ | grep -A 1 -B 1 "Sensor.Temperature" | grep -Po '(?<="Value": ")[^"]*')"
        gammu-smsd-inject TEXT "$SMS_1_NUMBER" -text "DetectSalon : $TempDetectSalon // DetectSalon3 : $TempDetectSalon3 // DetectGarage : $TempDetectGarage //"  >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"volet"* ]] ; then
Volet1="$(curl -u admin:<HG password>-s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/50/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
Volet2="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/57/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
Volet3="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/58/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
Volet4="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/62/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
Volet5="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/63/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
        gammu-smsd-inject TEXT "$SMS_1_NUMBER" -text "Volet1 : $Volet1 // Volet2 : $Volet2 // Volet3 : $Volet3 // Volet4 : $Volet4 // Volet5 : $Volet5 //"  >/dev/null 2>&1
fi
if [[ "$SMS_1_TEXT" == *"level"* ]] ; then
DetectSalon="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/31/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
DetectSalon3="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/54/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
DetectGarage="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/61/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
PorteGarage="$(curl -u admin:<HG password> -s http://<HG @IP>:<HG port>/api/HomeAutomation.HomeGenie/Config/Modules.Get/HomeAutomation.ZWave/20/ | grep -A 1 -B 1 "Status.Level" | grep -Po '(?<="Value": ")[^"]*')"
        gammu-smsd-inject TEXT "$SMS_1_NUMBER" -text "DetectSalon : $DetectSalon // DetectSalon3 : $DetectSalon3 // DetectGarage : $DetectGarage // PorteGarage : $PorteGarage //"  >/dev/null 2>&1
fi
shopt -u nocasematch
Bye