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

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“.

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 ( $buffer, 0, $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:

SetMessageList(51809,"test","new message");

51809 is the String Variable ID

Questions?

benefit: only one variable is needed

regards
Attain

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

Robert

In my case it ist complete different :stuck_out_tongue:

2’nd at 1’st

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

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

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

Was gibts denn noch so geheimnisvolle Systemvariablen.
Im Handbuch habe ich vergebens gesucht.

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 :slight_smile:

Anfängerprobleme: Änderungsrate einer Temperatur berechnen

You can try this one to:

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“ :wink:

But it works :cool:

Regards,
Robert

I can read and speak it but not write it…

Das ist wohl vergessen worden. :eek:

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

This is my supernatural powers. :smiley:
No, as I remember, there was a short description in the „V2.1 changelog treat“.

regards
A