EnOcean WatchDog

Nach der Idee von aag:

hier eine Variante (zwar ohne Mail, kann jedoch nach belieben erweitert werden):

Kategorie eröffenen, darunter das folgende Script erstellen und dem Script einen Timer drunter legen (z.B. alle 1Std - siehe auch Bild1):

<?
/*
 Enocean Modul Id's:
 EnOcean EltakoDimmer = {48909406-A2B9-4990-934F-28B9A80CD079}
 EnOcean EltakoFAFT60 = {0BE195DC-6002-4D99-A566-3B9B0B57FAD6}
 EnOcean EltakoFAH60 = {AF827EB8-08A3-434D-9690-424AFF06C698}
 EnOcean EltakoFSS12 = {7124C1BC-B260-4C5E-BF00-B38D3C7B5CB7}
 EnOcean EltakoSwitch = {FD46DA33-724B-489E-A931-C00BFD0166C9}
 EnOcean Gateway = {A52FEFE9-7858-4B8E-A96E-26E15CB944F7}
 EnOcean Hoppe = {1C8D7E80-3ED1-4117-BB53-9C5F61B1BEF3}
 EnOcean Opus = {9B1F32CD-CD74-409A-9820-E5FFF064449A}
 EnOcean PTM200 = {40C99CC9-EC04-49C8-BB9B-73E21B6FA265}
 EnOcean PTM200RX = {63484585-F8AD-4780-BAFD-3C0353641046}
 EnOcean RCM100 = {8492CEAF-ED62-4634-8A2F-B09A7CEDDE5B}
 EnOcean STM100 = {FA1479DE-C0C1-433D-98BC-EA7C298D1AA5}
 EnOcean STM250 = {B01DE819-EA69-4FC1-91AB-4D9FF8D55370}
 EnOcean Thermokon = {B4249BC6-5BA8-45E3-B506-86680935D4EE}

 */

$maxTimeout = 1*60*60;  // maximum timeout in seconds

//------------------------------------------------------------------------------
function CreateVariableByName($parentId, $name, $type, $info)
{
	$vid = @IPS_GetVariableIDByName($name, $parentId);
	if($vid === false)
	{
		$vid = IPS_CreateVariable($type);
		IPS_SetParent($vid, $parentId);
		IPS_SetName($vid, $name);
		IPS_SetInfo($vid, $info);
		IPS_SetVariableCustomProfile($vid, "~Alert.Reversed");
	}
	return $vid;
}

//------------------------------------------------------------------------------
function AddAllModules($parentId)
{
	$modulGuidsToAdd = array
		(
			"{FA1479DE-C0C1-433D-98BC-EA7C298D1AA5}",  // STM100
			"{B01DE819-EA69-4FC1-91AB-4D9FF8D55370}",  // STM250
			"{7124C1BC-B260-4C5E-BF00-B38D3C7B5CB7}"   // EltakoFSS12
		);

	foreach($modulGuidsToAdd as $modulGuid)
	{
		$moduleIds = IPS_GetInstanceListByModuleID($modulGuid);
		foreach($moduleIds as $modulId)
		{
			$location = IPS_GetLocation($modulId);
			CreateVariableByName($parentId, $location, 0, $modulId);
		}
	}
}

//------------------------------------------------------------------------------
function StateChanged($objId, $objText, $isOk)
{
	if ($isOk)
	{
		IPS_LogMessage("enoWDog", $objText.": Is OK now");
	}
	else
	{
		IPS_LogMessage("enoWDog", $objText.": Has timed out!");
	}
}

//------------------------------------------------------------------------------

$parentID = IPS_GetObject($_IPS['SELF']);
$parentID = $parentID['ParentID'];
$stateIds = IPS_GetChildrenIDs($parentID);

// create all state variables the first time
if (count($stateIds) <= 1)  // one object is the script himself
{
	AddAllModules($parentID);
	IPS_LogMessage("enoWDog", "State variables created");
	$stateIds = IPS_GetChildrenIDs($parentID);
}

// now control the states
if (count($stateIds) > 1)
{
	foreach ($stateIds as $stateId)
	{
		$idInfo = IPS_GetObject($stateId);
		if ($idInfo['ObjectType'] == 2)  // only variables
		{
			if ($idInfo['ObjectIsHidden'] == false)
			{
				// object reference (id) is stored in info
				$modulId = (int)$idInfo['ObjectInfo'];
				if (IPS_ObjectExists($modulId))
				{
					$modulChilds = IPS_GetChildrenIDs($modulId);
					if (count($modulChilds) > 0)
					{
					   // search for a read only varaiable
					   $lastUpdate = 0;
					   foreach ($modulChilds as $modulChild)
					   {
					      $objInfo = IPS_GetObject($modulChild);
					      if (($objInfo['ObjectType'] == 2) && ($objInfo['ObjectIsReadOnly']))
					      {
								$varInfo = IPS_GetVariable($modulChild);
								if ($varInfo['VariableUpdated'] != null)
								{
									$lastUpdate = $varInfo['VariableUpdated'];
									break;
								}
					      }
					   }
					   
					   if ($lastUpdate != 0)
					   {
							//echo($stateId.":".date("H:i:s")."-".date("H:i:s",$lastUpdate));
							$isOk = (bool)(time() < $lastUpdate + $maxTimeout);

							// write only new state
							if (GetValue($stateId) != $isOk)
							{
								SetValue($stateId, $isOk);
								StateChanged($modulId, $idInfo['ObjectName'], $isOk);
							}
						}
						else
						{
							IPS_LogMessage("enoWDog", $idInfo['ObjectName']." no variable found!");
						}
					}
					else
					{
						IPS_LogMessage("enoWDog", $idInfo['ObjectName']." has no childs!");
					}
				}
				else
				{
					IPS_LogMessage("enoWDog", $idInfo['ObjectName'].": modul-Id ".$modulId." not found!");
				}
			}
		}
	}
}

?>

Beim ersten Aufruf des Scripts werden alle EnOcean STM100, STM250 und EltakoFSS12 (weitere Modularten können in Liste $modulGuidsToAdd ergänzt werden) gesucht, und für jedes gefundene Objekt eine Statusvariable angelegt (siehe Bild2).
Die Id für das zu prüfende Modul (STM) wird im Info-Feld (Beschreibung) der Statusvariable abgelegt.

Im Script kann das maximale Timeout (im Moment 1 Std) angegeben werden.
Im Moment wird bei Timeout oder OK ein Log-Eintrag vorgenommen (weitere Reaktionen einfach in funktion StateChanged… ergänzen).
Versteckte Statusvariablen werden nicht geprüft.

Für neue Module:
a) Alle Statusvariablen löschen, es werden dann alle gewünschten Module gesucht und neu eröffnet.
b) Statusvariable selber anlegen, die ID des zu prüfenden Moduls in die Beschreibung der Statusvariable einsetzen.

Viel Spass

Gruss
Tinu

PS: Diskussionen bitte hier

enoWDog.IPS.PHP.zip (1.73 KB)