Scenario code pour frigate vers Jeedom mobile V2

Bonjour a tous,

j’essay de modifier un code creer par @ngrataloup (merci pour son travail) pour l’adapter à chez moi.
L’objectif est d’envoyer la notifiction vers l’appli Jeedom mobile V2 et non vers jeedomconnect mais je rencontre un probléme bizare.

il ne trouve pas les objets dans mon jeedoms.

$scenario->setLog('┌──────────── Logs bloc code - version du '.$version);

// Variables
$urlFrigate = 'http://127.0.0.1:55000' ;
$eqLogicEventId =  eqLogic::byString('[Camera][Frigate_Event][events]')->getId() ;
$destinationPath = '/var/www/html/data/events';
$cmdNotifJC = cmd::byString('[7 Présence][Android Jeedom Antho][Notification]') ;

// Vérifier si le répertoire existe
function createDir($destinationPath,$scenario) {
  if (!is_dir($destinationPath)) {
    // Créer le répertoire s'il n'existe pas
    if (mkdir($destinationPath, 0777, true)) $scenario->setLog('Répertoire créé avec succès : ' .$destinationPath );
    else $scenario->setLog('Erreur lors de la création du répertoire : ' . $destinationPath);
    }
}

function recupFile($sourceUrl,$eventId,$destinationPath,$scenario) {
  $fileContent = file_get_contents($sourceUrl);

  $localFileName = $eventId.'.png';
  $destinationFile = $destinationPath .'/'. $localFileName ;
  imagepng(imagecreatefromstring($fileContent),   $destinationFile );
      
  if ( $fileContent !== false) {
    // Sauvegarder le fichier localement
    
    file_put_contents($destinationFile, $fileContent);
    $scenario->setLog('| Fichier recupéré et redimensionné : '.$destinationFile);
    
    return $destinationFile ;
  } else {
    $scenario->setLog('| Impossible de récupérer le fichier depuis l\'URL '.$sourceUrl);
    return 0 ;
  }
}

function chmodAll666($dir) {
  $files = scandir($dir);
  foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
      $path = $dir . DIRECTORY_SEPARATOR . $file;
      chmod($path, 0666);
    }
  }
}
//Programme principal

// Recupération de l'EventID de l'evenement
$eventId = cmd::byEqLogicIdCmdName($eqLogicEventId,'ID')->execCmd() ;
$camera = cmd::byEqLogicIdCmdName($eqLogicEventId,'Camera')->execCmd(); 
$timestamp = cmd::byEqLogicIdCmdName($eqLogicEventId,'Timestamp')->execCmd() ; 
$label = cmd::byEqLogicIdCmdName($eqLogicEventId,'Label')->execCmd() ; 
$type = cmd::byEqLogicIdCmdName($eqLogicEventId,'Type')->execCmd() ; 
$Score = cmd::byEqLogicIdCmdName($eqLogicEventId,'Score')->execCmd() ; 

$scenario->setLog('| Evenement : '.$eventId);
$scenario->setLog('| Lieu      : '.$camera);
$scenario->setLog('| Date      : '.date('d/m H:i:s',$timestamp));
$scenario->setLog('| Label     : '.$label.' ('.$Score.'%) - Type : '.$type );

if ( $type != 'update' ) {
 
  $sourceUrl = $urlFrigate.'/api/events/'.$eventId.'/snapshot.jpg?bbox=1×tamp=1';

  createDir($destinationPath,$scenario) ;
  $destinationFile = recupFile($sourceUrl,$eventId,$destinationPath,$scenario) ;
  
  if ( $destinationFile != '0' ) {
    // Modificaiton des droits sur les fichiers
    chmodAll666($destinationPath) ;
    
    // Envoi notification
    $cmdNotifJC->execCmd($options = array('title' => 'title='.$camera.' Detecion mvt | files='.$destinationFile, 'message' => 'Heure : '.date('d/m H:i:s',$timestamp).'<br>Type : '.$label.' ('.$Score.'%) - Etat : '.$type), $cache   = 0);
    $scenario->setLog('| Envoi de la notification avec le fichier '.$destinationFile);
  }
  else {
    $cmdNotifJC->execCmd($options = array('title' => 'title='.$camera.' Detecion mvt', 'message' => 'Heure : '.date('j/m H:i:s',$timestamp).'<br>Type : '.$label.' ('.$Score.'%) - Etat : '.$type), $cache   = 0);
    $scenario->setLog('| Envoi de la notification sans fichier ');
  }
}
$scenario->setLog('└───────────────────────────');

log scenario

[2024-04-09 20:41:10][SCENARIO] -- Début : Scenario lance manuellement.
[2024-04-09 20:41:10][SCENARIO] - Exécution du sous-élément de type [action] : code
[2024-04-09 20:41:10][SCENARIO] Exécution d'un bloc code
[2024-04-09 20:41:10][SCENARIO] ┌──────────── Logs bloc code - version du
[2024-04-09 20:41:10][SCENARIO] L'équipement n'a pas pu être trouvé : [Camera][Frigate_Event][events] => [Camera][Frigate_Event][events]
[2024-04-09 20:41:10][SCENARIO] Fin correcte du scénario

l’objet en question dans mon jeedom

merci :slight_smile:

Salut,

J’ai pas épluché le code mais en principe les commandes commencent et finissent par le caractère #

code mise à jours mais toujours erreur

$scenario->setLog('┌──────────── Logs bloc code - version du '.$version);

// Variables
$urlFrigate = 'http://127.0.0.1:55000' ;
$eqLogicEventId =  eqLogic::byString('#[Camera][Frigate_Event][events]#')->getId() ;
$destinationPath = '/var/www/html/data/events';
$cmdNotifJC = cmd::byString('#[7 Présence][Android Jeedom Antho][Notification]#') ;

// Vérifier si le répertoire existe
function createDir($destinationPath,$scenario) {
  if (!is_dir($destinationPath)) {
    // Créer le répertoire s'il n'existe pas
    if (mkdir($destinationPath, 0777, true)) $scenario->setLog('Répertoire créé avec succès : ' .$destinationPath );
    else $scenario->setLog('Erreur lors de la création du répertoire : ' . $destinationPath);
    }
}

function recupFile($sourceUrl,$eventId,$destinationPath,$scenario) {
  $fileContent = file_get_contents($sourceUrl);

  $localFileName = $eventId.'.png';
  $destinationFile = $destinationPath .'/'. $localFileName ;
  imagepng(imagecreatefromstring($fileContent),   $destinationFile );
      
  if ( $fileContent !== false) {
    // Sauvegarder le fichier localement
    
    file_put_contents($destinationFile, $fileContent);
    $scenario->setLog('| Fichier recupéré et redimensionné : '.$destinationFile);
    
    return $destinationFile ;
  } else {
    $scenario->setLog('| Impossible de récupérer le fichier depuis l\'URL '.$sourceUrl);
    return 0 ;
  }
}

function chmodAll666($dir) {
  $files = scandir($dir);
  foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
      $path = $dir . DIRECTORY_SEPARATOR . $file;
      chmod($path, 0666);
    }
  }
}
//Programme principal

// Recupération de l'EventID de l'evenement
$eventId = cmd::byEqLogicIdCmdName($eqLogicEventId,'ID')->execCmd() ;
$camera = cmd::byEqLogicIdCmdName($eqLogicEventId,'Camera')->execCmd(); 
$timestamp = cmd::byEqLogicIdCmdName($eqLogicEventId,'Timestamp')->execCmd() ; 
$label = cmd::byEqLogicIdCmdName($eqLogicEventId,'Label')->execCmd() ; 
$type = cmd::byEqLogicIdCmdName($eqLogicEventId,'Type')->execCmd() ; 
$Score = cmd::byEqLogicIdCmdName($eqLogicEventId,'Score')->execCmd() ; 

$scenario->setLog('| Evenement : '.$eventId);
$scenario->setLog('| Lieu      : '.$camera);
$scenario->setLog('| Date      : '.date('d/m H:i:s',$timestamp));
$scenario->setLog('| Label     : '.$label.' ('.$Score.'%) - Type : '.$type );

if ( $type != 'update' ) {
 
  $sourceUrl = $urlFrigate.'/api/events/'.$eventId.'/snapshot.jpg?bbox=1×tamp=1';

  createDir($destinationPath,$scenario) ;
  $destinationFile = recupFile($sourceUrl,$eventId,$destinationPath,$scenario) ;
  
  if ( $destinationFile != '0' ) {
    // Modificaiton des droits sur les fichiers
    chmodAll666($destinationPath) ;
    
    // Envoi notification
    $cmdNotifJC->execCmd($options = array('title' => 'title='.$camera.' Detecion mvt | files='.$destinationFile, 'message' => 'Heure : '.date('d/m H:i:s',$timestamp).'<br>Type : '.$label.' ('.$Score.'%) - Etat : '.$type), $cache   = 0);
    $scenario->setLog('| Envoi de la notification avec le fichier '.$destinationFile);
  }
  else {
    $cmdNotifJC->execCmd($options = array('title' => 'title='.$camera.' Detecion mvt', 'message' => 'Heure : '.date('j/m H:i:s',$timestamp).'<br>Type : '.$label.' ('.$Score.'%) - Etat : '.$type), $cache   = 0);
    $scenario->setLog('| Envoi de la notification sans fichier ');
  }
}
$scenario->setLog('└───────────────────────────');
[2024-04-09 20:50:31][SCENARIO] -- Début : Scenario lance manuellement.
[2024-04-09 20:50:31][SCENARIO] - Exécution du sous-élément de type [action] : code
[2024-04-09 20:50:31][SCENARIO] Exécution d'un bloc code
[2024-04-09 20:50:31][SCENARIO] ┌──────────── Logs bloc code - version du
[2024-04-09 20:50:31][SCENARIO] L'équipement n'a pas pu être trouvé : #13669# => #13669#
[2024-04-09 20:50:31][SCENARIO] Fin correcte du scénario

et 13699 est bien la cde info

$eqLogicEventId =  eqLogic::byString('#[Camera][Frigate_Event][events]#')->getId() ;

J’ai pas trop regardé son script mais à 1ere vue là dedans il doit y avoir un équipement ce ne doit pas être le nom d’une commande.

1 « J'aime »

Tu mets une commande alors qu’il attend un équipement. Faut enlever le [events] :wink:
Édit : remarque déjà faite au dessus par @Bison