voilà le premier scénario qui décode et classe les codes par nature. il y a trois choses à customiser, les utilisateurs à entrer définis sur la centrale et le scénario cible (ID) car le code envoie l’infos sous forme de tags à utiliser. tu as aussi une référence au champ message de la centrale, j’ai eu la flemme de mettre ça en paramètre ( $tmpcmd = cmd::byString(« #[Sécurité][75000.Nri1][Message]# »);
);
). a la fin du code tu auras la liste des tags créés. A ce jour ça marche toujours avec l’os courant, comme les codes SIA ne bougent pas en principe, ça devrait le faire encore pour longtemps 
// Date : Fev, 1st 2023
// codes are based on SIA DC9 codes sent by Ajax hub
// in OS Malevitch V2.15
// list of suported SIA DC9 codes with their category based on current Ajax OS
$codearray =array(
array('AF','Armed'),array('AR','Malfunction restored'),array('AT','Malfunction'),array('BA','Alarm'),array('BR','Alarm'),
array('BS','Malfunction'),array('CA','Armed'),array('CB','Armed'),array('CC','Malfunction'),array('CD','Malfunction'),
array('CF','Armed'),array('CG','Armed'),array('CL','Armed'),array('FA','Warning'),
array('FH','Warning restored'),array('FJ','Malfunction restored'),array('FS','Malfunction'),array('FT','Malfunction'),array('FX','Malfunction restored'),
array('GA','Warning'),array('GH','Warning restored'),array('HA','Disarmed'),array('JA','Alarm'),
array('KA','Malfunction'),array('KH','Malfunction'),array('MA','Warning'),array('MR','Warning restored'),
array('NB','Armed'),array('NC','Armed'),array('ND','Disarmed'),array('NE','Malfunction'),array('NF','Armed'),array('NL','Armed'),array('NO','Disarmed'),array('NP','Disarmed'),
array('OA','Disarmed'),array('OB','Disarmed'),array('OG','Disarmed'),array('OP','Disarmed'),array('OR','Malfunction restored'),
array('PA','Panic'),array('PF','Malfunction'),array('PH','Disarmed'),array('PO','Malfunction restored'),
array('QB','Malfunction'),array('QU','Malfunction restored'),
array('RB','Information'),array('RS','Information'),array('SM','Alarm'),array('TA','Alarm'),
array('TR','Malfunction restored'),array('WA','Warning'),array('WH','Warning restored'),array('XC','Malfunction restored'),
array('XH','Malfunction restored'),array('XI','Information'),array('XL','Malfunction'),array('XQ','Malfunction'),
array('XR','Malfunction restored'),array('XT','Malfunction'),array('YA','Information'),
array('YC','Information'),array('YG','Set'),array('YK','Information'),array('YM','Information'),
array('YP','Malfunction'),array('YQ','Malfunction restored'),array('YR','Malfunction restored'),
array('YS','Information'),array('YT','Malfunction'),array('YX','Malfunction'),
array('ZY','Information'),array('ZZ','Information'));
// type of categories based on code header (first char)
$detectorcategory = array(
array('F','Fire'),
array('G','Gaz'),
array('W','Water')
);
$usermapping = array(
array(0,'Centrale Ajax'), // reserved
array(502,'first user'), // enter users from the Ajax hub as defined
);
$trigger = $scenario->getRealTrigger();
//$scenario->setLog(' trigger='.$trigger);
if ($trigger != 'user') {
$triggerName = cmd::cmdToHumanReadable($trigger);
$cmd = cmd::byString($triggerName);
$siadc9 = $cmd->execCmd();
// decode sia dc9 message
$scenario->setLog('SIA payload='.$siadc9);
} else {
$tmpcmd = cmd::byString("#[Sécurité][75000.Nri1][Message]#");
$siadc9=$tmpcmd->execCmd();
// for testing purpose
}
// general state of system (red, orange, green)
$generalstate ="unknown";
if (strlen($siadc9) > 0)
if (substr($siadc9,0,1) == '*') { // encrypted message
$scenario->setLog(' encrypted message received, abort');
} elseif (substr($siadc9,0,7) == 'SIA-DCS') // unencrypted SIA DC9 message
{
$scenario->setLog(' unencrypted message received, processing...');
sscanf($siadc9,'SIA-DCS"%4dL0#%5d[#%5d|Nri%d/%2s%d]_%2s:%2s:%2s,%2s-%2s-%4s', $prefix, $account, $site, $nri, $codesia, $id, $hh,$mi,$ss,$mm,$dd,$yy);
$scenario->setLog('decoded '.$prefix." ".$account." ".$site." ".$nri." ".$codesia." ".$id." ".$hh." ".$mi." ".$dd." ".$yy);
$timestamp = "$yy-$mm-$dd $hh:$mi:$ss";
// quickly fetch description as well
$cmd = cmd::byString("#[Sécurité][$site.Nri$nri][Description]#");
$description = $cmd->execCmd();
// now check type of code
//$scenario->setLog(print_r($codearray));
// decode code of alarm to find category
$cat = $codearray[array_search($codesia,array_column($codearray, 0))];
// in the case of a warning, determine type of alarm because this is fire, gaz or water flood detector triggered
$typealarm = $detectorcategory[array_search($codesia[0],array_column($detectorcategory, 0))];
// map id to user name if available
$userNameA = $usermapping[array_search($id,array_column($usermapping, 0))];
$userName = $userNameA[1];
// fetch message to get the exact information
$cmd = cmd::byString("#[Sécurité][$site.Nri$nri][Description]#");
$description = $cmd->execCmd();
// now check for category
if ($cat == false)
$scenario->setLog("code not found, cannot decode category");
else
// all the elements are there, process message to properly take action
switch ($cat[1]) {
case 'Alarm': // a security breach is being detected
$siamessage = 'alarm triggered'.' on zone '.($nri==0?'main':$nri).' at '.$timestamp;
$generalstate='red';
break;
case 'Armed' : // zone, night mode or all armed
$siamessage='system armed '.($codesia[0]=='N'?'in night mode':'in full mode').' on zone '.($nri==0?'main':$nri).' by user '.$userName.' at '.$timestamp;
$generalstate='green';
$night=($codesia[0]=='N'?'Night':'Full');
break;
case 'Disarmed': // zone, night mode or all disarmed
$siamessage='system disarmed on zone '.($nri==0?'main':$nri).' by user '.$userName.' at '.$timestamp;
$night='';
$generalstate='green';
break;
case 'Malfunction': // command or device failed
$siamessage='error on request or device triggered by user ID '.$id.' on zone '.($nri==0?'main':$nri).' at '.$timestamp;
$generalstate='orange';
break;
case 'Malfunction restored': // command or device condition restored
$siamessage='an error has been cleared on zone '.($nri==0?'main':$nri).' at '.$timestamp;
$generalstate='green';
break;
case 'Warning': // fire or gaz alarm is raised
$siamessage=$typealarm.' detector triggered'.' at '.$timestamp;
$generalstate='red';
break;
case 'Warning Restored': // fire or gaz alarm end
$siamessage='problem with '.$typealarm.' cleared'.' at '.$timestamp;
$generalstate='green';
break;
case 'Panic': // panic button pressed
$siamessage='panic button pressed'.' on zone '.($nri==0?'main':$nri).' by user '.$userName.' at '.$timestamp;
$generalstate='red';
break;
case 'Set': // unknown or information purpose code
$siamessage='settings have been changed on hub or device at '.$timestamp;
$generalstate='green';
break;
case 'Information': // unknown or information purpose code
$siamessage='information message on device state'.' on zone '.($nri==0?'main':$nri).' at '.$timestamp;
$generalstate='green';
break;
default: // should not occur, this is a blank category because the code is not mapped
$siamessage='category not found: '.$cat[1].' this should not occur';
break;
}
$tags["#sia_state#"]=$generalstate;
$tags["#sia_zone#"] =$nri;
$tags["#sia_uid#"] =$id;
$tags["#sia_un#"] =$userName;
$tags["#sia_cat#"] =$cat[1];
$tags["#sia_code#"] =$codesia;
$tags["#sia_desc#"] =$description;
$tags["#sia_mode#"] =$night;
// send info to target scenario <<<<<<<<<<<<<< enter the target scenario here
$sid=135;
$sc=scenario::byId($sid);
if ($sc != null) {
$sc->setTags($tags);
$sc->launch();
}
$scenario->setTags($tags);
} else
$siamessage=' message format unknown, cannot decode, abort message='.$siadc9;
$tags["#sia_extdesc#"] =$siamessage;
$scenario->setLog($siamessage);
Les équipements sont dans l’objet Sécurité, d’où les références à changer en fonction.