more G-Labs products

Author Topic: Alarm add on (sms,...)  (Read 6177 times)

December 07, 2014, 09:11:32 PM
Read 6177 times

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
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 :
  • Alarm on
  • Alarm off
  • Alarm triggered
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 :
  • Traduce in English
  • Add customize field
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
« Last Edit: December 07, 2014, 09:26:38 PM by nolio »

December 14, 2014, 12:08:38 PM
Reply #1

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
Hi Nolio,

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

Cheers
Dani

December 27, 2014, 02:51:52 PM
Reply #2

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
I update this script :
  • Translation in english
  • Correction to permit to send 2 sms (suppress the runasync because gammu doesn't support to launch 2 command line too quickly)
  • Add the field for customize opekarotz alert
Bye

July 02, 2015, 11:45:40 PM
Reply #3

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
I work on 2 modifications on the sms part, by using of gammu-smsd instead of gammu :
  • More reliable send of sms : the sms are store and send when the "phone" is "ready" (not lost if phone is not ready like 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+"\"",
  • Permit to enable/disable alarm by sending a sms (by sending "alarm on" or "alarm off" in a sms)
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
    « Last Edit: July 02, 2015, 11:48:32 PM by nolio »

    July 20, 2015, 01:46:52 AM
    Reply #4

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    I dont understand about this
    /90/Control.On/1393535869092
    How to on off my gpio?
    Thx for help

    July 20, 2015, 07:03:11 AM
    Reply #5

    nolio

    • *****
    • Information
    • Global Moderator
    • Posts: 544
    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

    July 29, 2015, 11:10:09 PM
    Reply #6

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    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 <--- Nothing happen

    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 <--- Nothing happen

    Any somthing missing? Pls help

    « Last Edit: July 29, 2015, 11:14:41 PM by djatie »

    July 31, 2015, 06:12:42 AM
    Reply #7

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    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
                                      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
                                      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
                                      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

    August 30, 2015, 02:59:21 AM
    Reply #8

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    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'
    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
    « Last Edit: August 30, 2015, 03:09:34 AM by djatie »

    August 30, 2015, 04:53:56 AM
    Reply #9

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    I have remove
    this -->if [ "$SMS_1_TEXT" = "23on" ] ; then
    curl 'http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On'
    and this ->fi

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

    i send some sms then its on. i use new gammu. OMG how to fix this  :( :( :( :( :( :( :(

    August 30, 2015, 08:42:00 AM
    Reply #10

    nolio

    • *****
    • Information
    • Global Moderator
    • Posts: 544
    I have remove
    this -->if [ "$SMS_1_TEXT" = "23on" ] ; then
    curl 'http://localhost/api/RaspberryPi.Gpio/GPIO23/Control.On'
    and this ->fi

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

    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.

    September 06, 2015, 08:46:06 PM
    Reply #11

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    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
    :):)

    September 06, 2015, 08:50:00 PM
    Reply #12

    nolio

    • *****
    • Information
    • Global Moderator
    • Posts: 544
    Ok what kinds of problem with gamma install ?
    Share share :-)

    September 10, 2015, 12:08:57 AM
    Reply #13

    djatie

    • **
    • Information
    • Jr. Member
    • Posts: 34
    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

    August 17, 2016, 01:09:36 AM
    Reply #14

    nolio

    • *****
    • Information
    • Global Moderator
    • Posts: 544
    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