Salut,
OK pas de souci, voici un exemple de mes callback en mod code.
Celui-ci, je l’utilise pour changer les chaines de ma Freebox (il y a un plugin Snips qui peut le faire en direct mais je préfère passer par Jeedom).
On récupère les infos de snips en utilisant des tags (ex: $tags[’#channel#’];).
Dans mon exemple, je récupère plusieurs TAG mais je n’exploite que le « channel » pour l’instant.
Lors du lancement du scénario :
Start : Lancement provoque. Tags : {"#identifier#":"snips::akashha:TvChannelJeedom::Callback","#intent#":"akashha:TvChannelJeedom","#siteId#":"salon","#query#":"mets rmc découverte","#channel#":"RMC découverte"}
Quand j’aurai plusieurs TV dans des pièces différentes (avec des snips satellite), je pourrai utiliser le « siteId » et en fonction de ma pièce, sélectionner automatiquement la bonne TV.
Scénario de callback :
/*****************
DEBUT BLOC CODE
*****************/
// VARIABLES EQUIPEMENTS
$freebox='[Freebox Player][Telcommande]';
// RECUPERATION DES VARIABLES (TAGS)
$tags = $scenario->getTags();
$intent = $tags['#intent#'];
$siteId = $tags['#siteId#'];
$query = $tags['#query#'];
$channel = $tags['#channel#'];
// RUN COMMANDE CHANGEMENT CHAINE
function run_cmd($freebox, $channel){
// ACTION SUR LA CHAINE
cmd::byString('#' . $freebox . $channel . '#')->execCmd();
cmd::byString('#[Snips-Intents][Snips-TTS-default][say]#')->execCmd($options=array('message'=> "C'est fait"));
}
if(!empty($channel)){
// UNE CHAINE EST DEFINIE
switch (true) {
case preg_match("/TF1/", $channel):
$scenario->setLog("PLAY TF1");
run_cmd($freebox, '[Chaine 001]');
break;
case preg_match("/france 2/", $channel):
$scenario->setLog("PLAY FRANCE DEUX");
run_cmd($freebox, '[Chaine 002]');
break;
case preg_match("/france 3/", $channel):
$scenario->setLog("PLAY FRANCE TROIS");
run_cmd($freebox, '[Chaine 003]');
break;
case preg_match("/canal plus/", $channel):
$scenario->setLog("PLAY CANAL PLUS");
run_cmd($freebox, '[Chaine 004]');
break;
case preg_match("/france 5/", $channel):
$scenario->setLog("PLAY FRANCE CINQ");
run_cmd($freebox, '[Chaine 005]');
break;
case preg_match("/M6/", $channel):
$scenario->setLog("PLAY M6");
run_cmd($freebox, '[Chaine 006]');
break;
case preg_match("/arte/", $channel):
$scenario->setLog("PLAY ARTE");
run_cmd($freebox, '[Chaine 007]');
break;
case preg_match("/C8/", $channel):
$scenario->setLog("PLAY C8");
run_cmd($freebox, '[Chaine 008]');
break;
case preg_match("/W9/", $channel):
$scenario->setLog("PLAY W9");
run_cmd($freebox, '[Chaine 009]');
break;
case preg_match("/TMC/", $channel):
$scenario->setLog("PLAY TMC");
run_cmd($freebox, '[Chaine 010]');
break;
case preg_match("/TFX/", $channel):
$scenario->setLog("PLAY TFX");
run_cmd($freebox, '[Chaine 011]');
break;
case preg_match("/NRJ 12/", $channel):
$scenario->setLog("PLAY NRJ 12");
run_cmd($freebox, '[Chaine 012]');
break;
case preg_match("/LCP/", $channel):
$scenario->setLog("PLAY LCP");
run_cmd($freebox, '[Chaine 013]');
break;
case preg_match("/france 4/", $channel):
$scenario->setLog("PLAY france 4");
run_cmd($freebox, '[Chaine 014]');
break;
case preg_match("/BFM TV/", $channel):
$scenario->setLog("PLAY BFM TV");
run_cmd($freebox, '[Chaine 015]');
break;
case preg_match("/CNEWS/", $channel):
$scenario->setLog("PLAY CNEWS");
run_cmd($freebox, '[Chaine 016]');
break;
case preg_match("/Cstar/", $channel):
$scenario->setLog("PLAY Cstar");
run_cmd($freebox, '[Chaine 017]');
break;
case preg_match("/Gulli/", $channel):
$scenario->setLog("PLAY Gulli");
run_cmd($freebox, '[Chaine 018]');
break;
case preg_match("/France Ô/", $channel):
$scenario->setLog("PLAY France Ô");
run_cmd($freebox, '[Chaine 019]');
break;
case preg_match("/L'équipe/", $channel):
$scenario->setLog("PLAY L'équipe");
run_cmd($freebox, '[Chaine 021]');
break;
case preg_match("/6ter/", $channel):
$scenario->setLog("PLAY 6ter");
run_cmd($freebox, '[Chaine 022]');
break;
case preg_match("/Numéro 23/", $channel):
$scenario->setLog("PLAY Numéro 23");
run_cmd($freebox, '[Chaine 023]');
break;
case preg_match("/RMC découverte|découverte/", $channel):
$scenario->setLog("PLAY RMC découverte");
run_cmd($freebox, '[Chaine 024]');
break;
case preg_match("/Chérie 25/", $channel):
$scenario->setLog("PLAY Chérie 25");
run_cmd($freebox, '[Chaine 025]');
break;
case preg_match("/LCI/", $channel):
$scenario->setLog("PLAY LCI");
run_cmd($freebox, '[Chaine 026]');
break;
case preg_match("/France info/", $channel):
$scenario->setLog("PLAY France info");
run_cmd($freebox, '[Chaine 027]');
break;
default:
cmd::byString('#'. $snips_say .'#')->execCmd($options=array('message'=> "La chaine n'a pas été trouvée"));
}
}
/*****************
FIN BLOC CODE
*****************/
Je sais pas si c’est la façon la plus simple de faire, mais moi ça me va bien.