Zurück   IP-Symcon Community Forum > IP-Symcon 2.x (English) > General Discussion

Antwort
 
LinkBack Themen-Optionen Thema durchsuchen
  #1 (permalink)  
Alt 29.07.10, 10:55
Junior Member
 
Registriert seit: Jan 2010
Ort: Utrecht, Netherlands
Beiträge: 21
Question Sample code of a good alarm handler???

Hi,

Maybe someone can help me. I have looked on the forum for a good sample script of a general alarm handler.

This is the case: I have multiple things that can raise an alarm connected to IPS, for instance: tempertuur reading of the solar installation thet trigger an alarm when hotter then > 95, temperture reading of multiple vessels that trigger when > 80, flow reading in case the pump is not working, multiple door and window contacts from HM, smoke detectors, a wind messure device that will give an alarm when wind >55 knots, etc. etc. Also setting the alarm when I am away could be controlled with this!

Of course I can put them all in seprate variable but that would be hard to follow and display in one view. I can also put them in an array and add or delete something when an alarm raises or trips.

Does any of you have a good idea how to set this up? Or do you have some sample code/ sample project?

regards,
Robert
Mit Zitat antworten
  #2 (permalink)  
Alt 29.07.10, 21:21
Benutzerbild von Attain
Senior Member
 
Registriert seit: Feb 2008
Beiträge: 233
Standard

Hi Robert,

i'll try to answer in english.
I wrote the following function to display different messages at the "dashbord" and also in to the "webfront".
PHP-Code:
function SetMessageList($ID,$sender,$message){
    
$quantity 6;                                              //how many messages are displayd
    
$header ='<body bgcolor="#a6caf0"><style type="text/css">table.list { width: 100%; border-collapse: true;} table.list td { border: 1px solid #444455; } table.list th { border: 1px solid #444455; }</style>';
    
$header.='<table frame="box" class="list">';
   
$header.='<tr>';
   
$header.='<th>Datum</th>';                                   //head of the table
   
$header.='<th>Uhrzeit</th>';
   
$header.='<th>Sender</th>';
   
$header.='<th>Meldung</th>';
   
$header.='</tr>';

    
$data ='<tr align="center"><td>'.date("d.m.Y").'</td>';
      
$data.='<td>'.date("H:i").'</td>';
   
$data.='<td>'.$sender.'</td>';
   
$data.='<td>'.$message.'</td>';

   
$string GetValue($ID);
    
$buffer explode("</tr>",$string);                                    //explode the string in to the array
   
array_shift ($buffer);                                      //delete the header
   
array_unshift ($buffer$data);                                       //new row to the beginning of an array
   
$buffer array_slice $buffer0$quantity );              //remove oldest message
    
$string implode("</tr>",$buffer);                           //implode array back to string
   
SetValue($ID$header $string "</table></body>");       //save html string

You have to add a stringvariable with profile "~HTMLBox".
Then You can add a new row in to the list with:
PHP-Code:
SetMessageList(51809,"test","new message"); 
51809 is the String Variable ID

Questions?

benefit: only one variable is needed

regards
Attain
Miniaturansicht angehängter Grafiken
wf.png  
Mit Zitat antworten
  #3 (permalink)  
Alt 29.07.10, 23:28
Junior Member
 
Registriert seit: Jan 2010
Ort: Utrecht, Netherlands
Beiträge: 21
Standard question ?

Dear Attain,

Thanks for the reply... It looks simple the code and very usefull.

I don't have any problem with reading in German, only writing in German is difficult. I don't know if de moderators will let me start an English topic the German topics else I would have placed it there. Maybe I just have to try it an see what will happen .

I have some questions... hopefully you can help me with it:

Do you also use it to read back if an alarm has been raised. This to prevent that you keep writing messages in the log. Example: on a variable change of a temperature I have some code that checks if the temperature is not above 95 C. When it's too high it will trip an alarm. But in the meantime the temperature keeps rising which can give it an alarm again. I have an extra alarm set on 105 C that will send a sms to different mobile numbers. How would you do this? Put an global variable in say ‘Alarm95Solar’ which you set when the temperature is too high and reset it when it drops below the 95?


Do you put this function in every php script where an alarm can be raised? Or is there a way to call a function from a different file? I tried to do this, call a function from another file but couldn't get it to work. It would be nice to have a function base so that I can reuse the code.

The rest looks easy, thanks!
Robert
Mit Zitat antworten
  #4 (permalink)  
Alt 30.07.10, 21:30
Benutzerbild von Attain
Senior Member
 
Registriert seit: Feb 2008
Beiträge: 233
Standard

Robert

Zitat:
Zitat von robertg Beitrag anzeigen
I don't have any problem with reading in German, only writing in German is difficult.
In my case it ist complete different

2'nd at 1'st
Zitat:
Do you put this function in every php script where an alarm can be raised? Or is there a way to call a function from a different file? I tried to do this, call a function from another file but couldn't get it to work. It would be nice to have a function base so that I can reuse the code.
You can put this function in to another script (for instance the Name of the script is 12345.ips.php), then you can use this function, if you use the include() statment

To Your example.
You have a temperature variable. If the Value is changing, then it will starts an Script like this
PHP-Code:
include'12345.ips.php';//you have to use the filename
if ($IPS_OLDVALUE 95 and $IPS_VALUE >= 95){  //Value exceeds 95°
    
SetMessageList(51809 /*[MessageBox]*/,"Solar","Temperatur $IPS_VALUE ");
}
if (
$IPS_OLDVALUE 105 and $IPS_VALUE >= 105){
    
// send SMS
    // pray for clouds

HTH
Attain
Mit Zitat antworten
  #5 (permalink)  
Alt 30.07.10, 21:57
Junior Member
 
Registriert seit: Jan 2010
Ort: Utrecht, Netherlands
Beiträge: 21
Standard Perfect, thanks...

The trick to use the $IPS_OLDVALUE is something i haven't seen somewhere else, SUPER! I will try it out tonight...

And the include statement is something so obvious that I totally forgot about it. This makes it easy to make a simple reusable code library.

Thanks for the tips and trick… I appreciate it.

Robert
Mit Zitat antworten
  #6 (permalink)  
Alt 31.07.10, 11:34
Benutzerbild von audi2010
Senior Member
 
Registriert seit: Dec 2006
Ort: Friedberg (Hessen)
Beiträge: 599
Question

Zitat:
Zitat von robertg Beitrag anzeigen
The trick to use the $IPS_OLDVALUE is something i haven't seen somewhere else, SUPER! I will try it out tonight...
Was gibts denn noch so geheimnisvolle Systemvariablen.
Im Handbuch habe ich vergebens gesucht.
__________________
Viele Grüße Rainer

_____________________________________________
Windows XP IPS V 2.2 -- FHZ -- 1-Wire
Edip über XBee
Anwesendheits-Tracker und viele Spielereien
Mit Zitat antworten
  #7 (permalink)  
Alt 31.07.10, 14:41
Junior Member
 
Registriert seit: Jan 2010
Ort: Utrecht, Netherlands
Beiträge: 21
Standard $IPS_OLDVALUE, it works...

Rainer,

I couldn't find $IPS_OLDVALUE in the documentation either but after a search on the forum I found a peace of samplecode from Attain... the thing is that you have to trigger the script through the varable change (Attain will explain this when you follow the link

Anfängerprobleme: Änderungsrate einer Temperatur berechnen

You can try this one to:
PHP-Code:
IF ( $IPS_SENDER == "Variable"){
    
$Differenz $IPS_VALUE $IPS_OLDVALUE;
    
$Script IPS_GetScript($IPS_SELF);
    
$Zeit time() - $Script['LastExecute'];
    
IPS_LogMessage$Differenz $Zeit);
    
IPS_LogMessage$IPS_OLDVALUE $IPS_VALUE);

    
// weitere Berrechnungen.......

Question remains: "How did Attain know about the $IPS_OLDVALUE"

But it works

Regards,
Robert

I can read and speak it but not write it...
Mit Zitat antworten
  #8 (permalink)  
Alt 31.07.10, 15:29
Benutzerbild von RWN
RWN RWN ist gerade online
Moderator
 
Registriert seit: Jan 2007
Ort: Nidda(Hessen)
Beiträge: 3,348
Standard

Das ist wohl vergessen worden.

Für Variablenereignisse gibt es $IPS_OLDVALUE (IPS2.1 / 04.10.2009) damit erhält man den alten Wert der Variable.
__________________
Gruß Rainer

Unmögliches wird sofort erledigt, Wunder dauern etwas länger
Mit Zitat antworten
  #9 (permalink)  
Alt 31.07.10, 17:19
Benutzerbild von Attain
Senior Member
 
Registriert seit: Feb 2008
Beiträge: 233
Standard

Zitat:
Zitat von robertg Beitrag anzeigen
Question remains: "How did Attain know about the $IPS_OLDVALUE"
This is my supernatural powers.
No, as I remember, there was a short description in the "V2.1 changelog treat".

regards
A
Mit Zitat antworten
Antwort

Stichworte
alarmanlage

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
IPS sample project (including code) accessible with IPS MC robertg General Discussion 2 18.04.10 18:37


Alle Zeitangaben in WEZ +2. Es ist jetzt 14:12 Uhr.


Powered by vBulletin® Version 3.8.4 (Deutsch)
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.0