Bonjour,
J’ai créé une fonction sync et refresh sur la base des nombreux posts, une sorte de Groovy Script OpenHab adapté à jeedom.
Je pense que j’ai zappé un truc au niveau des fonctionnalités BUTTON / NEXT.
En effet, si j’ajoute le status lorsqu’il y a la notion de next, l’affichage n’est pas bon. Si en revanche, j’enlève le « status », alors tout s’affiche correctement. J’ai corrigé ma fonction et maintenant, je butte sur le « NEXT », qui fait planter le NSPANEL (reboot au lieu de lier à l’écran suivant via un refresh ou sync).
Quelqu’un à une idée de là ou ça plante ? J’ai certainement zappé quelque chose dans les doc de ce tuto. J’ai placé des dumps un peu partout, mais là, je vois pas.
Merci pour votre aide.
Voici un premier exemple de script que j’ai :
/…/…/data/php/panel.user.function.class.php
global $Name_scenario ;
$Name_scenario = $scenario->getName();
$scenario->setLog("$Name_scenario - Step 01 - Variable");
/*
PANEL : Format :
"" - Power - Min - Max
Ex : Dimmer : {"refresh":{"pid":17,"name":"Lounge Fan", "power":ON, "min":1, "max":4, "icon":13,"dimmer":3}}
Ex : Dimmer : {"refresh":{"pid":18,"name":"Lounge Light", "power":ON, "dimmer":30}}
Ex : Dimmer color : {"refresh":{"pid":16,"name":"Bedroom mood light", "power":ON, "hsbcolor":"10,100,50"}}
Ex : Thermostat : {"refresh":{"pid":15,"name":"Cabin","therm":{"set":14,"temp":0,"heat":1,"state":0"}}
Ex : Media : {"refresh":{"pid":20,"name":"Music Room","artist":"New Order","album":"Power, Corruption & Lies","track":"Blue Monday","volume":70}}
Ex : Status : {"refresh":{"pid":19,"name":"System Status", "status":[{"id":1,"text":"Gate":,"value":"Open","color":2},...]}}
color=2 : vert - color=3 : red
*/
/* Definition of Panel types (page types) for available layouts *
NOTE! This is not the same as the PanelID (id) parameter but instead one of * 15 predefined “panel designs */
$PAGE_HOME = 1 ; $PAGE_2_BUTTON = 2 ; $PAGE_3_BUTTON = 3 ; $PAGE_4_BUTTON = 4 ;
$PAGE_6_BUTTON = 5 ; $PAGE_8_BUTTON = 6 ; $PAGE_DIMMER = 7 ; $PAGE_DIMMER_COLOR = 8 ;
$PAGE_THERMOSTAT = 9 ; $PAGE_ALERT_1 = 10 ; $PAGE_ALERT_2 = 11 ; $PAGE_ALARM = 12 ;
$PAGE_MEDIA = 13 ; $PAGE_PLAYLIST = 14 ; $PAGE_STATUS = 15 ;
/* Definition of button types */
$BUTTON_UNUSED = 0 ; $BUTTON_TOGGLE = 1 ; $BUTTON_PUSH = 2 ;
$BUTTON_DIMMER = 3 ; $BUTTON_DIMMER_COLOR = 4 ; $BUTTON_PAGE = 10 ;
/* Definition of icon types */
$ICON_BLANK = 0 ; $ICON_BULB = 1 ; $ICON_DIMMER = 2 ; $ICON_DIMMER_COLOR = 3;
$ICON_VACUUM = 4 ; $ICON_BED = 5 ; $ICON_HOUSE = 6 ; $ICON_SOFA = 7 ;
$ICON_BELL = 8 ; $ICON_HEAT = 9 ; $ICON_CURTAINS = 10 ; $ICON_MUSIC = 11 ;
$ICON_BINARY = 12 ; $ICON_FAN = 13 ; $ICON_SWITCH = 14 ; $ICON_TALK = 15 ;
$ICON_INFO = 16 ; $ICON_NONE = 0 ;
/* Status of each Button */
$P10B1 = 0; $P10B2=0;$P10B3=0;$P10B4=0;$P10B5=0;$P10B6=0;$P10B7=0;$P10B8=0;
// Chambre Parents
$P11B1 = cmd::byString('#[Chambre Parents][Lampe parent bf26c59a890374c427d0t8][Etat]#')->execCmd(null, false, false); // Plafond
$P11B2 = cmd::byString('#[Chambre Parents][Volet Parents][Position]#')->execCmd(null, false, false); // Volet
$P11B3 = cmd::byString('#[Chambre Parents][Vanne MOES Parents][Consigne]#')->execCmd(null, false, false); // Thermostat
$P11B4 = cmd::byString('#[Chambre Parents][INNR Parents][Etat]#')->execCmd(null, false, false); // Prise INNR
$P11B5 = cmd::byString('#[Chambre Parents][Diffuseur Maman bf6f1f0cb65c373cc3zvai][Status]#')->execCmd(null, false, false); // Diffuseur
$P11B6 = '0' ; // cmd::byString('#[Chambre Parents][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Infos
// Chambre Lysandre
$P12B1 = cmd::byString('#[Chambre Lysandre][Lampe Lysandre bfaffc4e853676bd34bd21][Etat]#')->execCmd(null, false, false); // Plafond
$P12B2 = cmd::byString('#[Chambre Lysandre][Volet Lysandre][Position]#')->execCmd(null, false, false); // Volet
$P12B3 = cmd::byString('#[Chambre Lysandre][Vanne MOES Lysandre][Consigne]#')->execCmd(null, false, false); // Thermostat
$P12B4 = 0 ; //cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Infos
// Douche
$P13B1 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Plafond
$P13B2 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Evier
$P13B3 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Thermostat
$P13B4 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // HP
$P13B5 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // EAU
$P13B6 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Infos
// Salon
$P14B1 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Lampes
$P14B2 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Volet
$P14B3 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Thermostat
$P14B4 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Ampli
$P14B5 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Infos
// Cuisine
$P15B1 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Plafond
$P15B2 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Evier
$P15B3 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P15B4 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P15B5 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
// Salle à manger
$P16B1 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Lampes
$P16B2 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P16B3 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P16B4 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P16B5 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
// Terrasse
$P17B1 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Lampes
$P17B2 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); // Store
$P17B3 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P17B4 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P17B5 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
// Autre
$P18B1 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P18B2 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P18B3 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P18B4 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
$P18B5 = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false); //
/* Definition of PANEL AND BUTTONS
'XX' => array( // The panel number to define
'0' => // The Panel description, used for refresh function
// Name is the title of the panel, which appear on the top of the panel
// Format specify the format of panel, see $PAGE_XXX variable definition, and choose the corresponding panel to design
// NB_BUTTON : This number correspond to the number of button in panel PAGE_X_BUTTON
'1' => // 1-8 Description of each button to design in the panel
*/
global $PANELS;
$PANELS = array (
10 => array (
// ... ajoutez les autres boutons B101 à B108 pour le Panel 1 de 8 Boutons
0 => array('NAME' => 'Etage 1', 'FORMAT' => $PAGE_8_BUTTON , 'NB_BUTTON' => 8 ),
1 => array( 'ID' => 1, 'Name' => 'Parents' , 'Type' => $BUTTON_PAGE , 'Next' => 11 , 'Icon' => $ICON_BED),
2 => array( 'ID' => 2, 'Name' => 'Lysandre' , 'Type' => $BUTTON_PAGE , 'Next' => 12 , 'Icon' => $ICON_BED),
3 => array( 'ID' => 3, 'Name' => 'Douche' , 'Type' => $BUTTON_PAGE , 'Next' => 13 , 'Icon' => $ICON_FAN),
4 => array( 'ID' => 4, 'Name' => 'Salon' , 'Type' => $BUTTON_PAGE , 'Next' => 14 , 'Icon' => $ICON_SOFA),
5 => array( 'ID' => 5, 'Name' => 'Cuisine' , 'Type' => $BUTTON_PAGE , 'Next' => 15 , 'Icon' => $ICON_BELL),
6 => array( 'ID' => 6, 'Name' => 'SAM' , 'Type' => $BUTTON_PAGE , 'Next' => 16 , 'Icon' => $ICON_SOFA),
7 => array( 'ID' => 7, 'Name' => 'Terrasse' , 'Type' => $BUTTON_PAGE , 'Next' => 17 , 'Icon' => $ICON_SOFA),
8 => array( 'ID' => 8, 'Name' => 'Autre' , 'Type' => $BUTTON_PAGE , 'Next' => 18 , 'Icon' => $ICON_SOFA)
),
11 => array (
// ... ajoutez les boutons pour PANEL 11 ici
0 => array('NAME' => 'Chambre Parents', 'FORMAT' => $PAGE_8_BUTTON , 'NB_BUTTON' => 8),
1 => array('ID'=>1 , 'Name' => 'Plafond' , 'Type' => $BUTTON_DIMMER , 'Next' => 0 , 'Icon' => $ICON_BULB ),
2 => array('ID'=>2 , 'Name' => 'Volet' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Icon' => $ICON_CURTAINS ),
3 => array('ID'=>3 , 'Name' => 'Thermostat' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Icon' => $ICON_HEAT ),
4 => array('ID'=>4 , 'Name' => 'Prise INNR' , 'Type' => $BUTTON_PUSH , 'Next' => 0 , 'Icon' => $ICON_BULB ),
5 => array('ID'=>5 , 'Name' => 'Diffuseur' , 'Type' => $BUTTON_DIMMER_COLOR ,'Next' => 0 , 'Icon' => $ICON_DIMMER_COLOR ),
6 => array('ID'=>6 , 'Name' => 'Infos' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Icon' => $ICON_INFO )
),
12 => array (
// ... ajoutez les boutons pour PANEL 12 ici
0 => array('NAME' => 'Chambre Lysandre', 'FORMAT' => $PAGE_4_BUTTON , 'NB_BUTTON' => 4),
1 => array('ID'=>1 , 'Name' => 'Plafond' , 'Type' => $BUTTON_DIMMER , 'Next' => 0 , 'Status' => $P12B1 , 'Icon' => $ICON_BULB ),
2 => array('ID'=>2 , 'Name' => 'Volet' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Status' => $P12B2 , 'Icon' => $ICON_CURTAINS ),
3 => array('ID'=>3 , 'Name' => 'Thermostat' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Status' => $P12B3 , 'Icon' => $ICON_HEAT ),
4 => array('ID'=>4 , 'Name' => 'Infos' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Status' => $P12B4 , 'Icon' => $ICON_INFO )
),
//[...] j'ai coupé le code des autres définitions
18 => array (
// ... ajoutez les boutons pour PANEL 18 ici
0 => array('NAME' => 'Autres', 'FORMAT' => $PAGE_8_BUTTON , 'NB_BUTTON' => 8),
1 => array('ID'=>1 , 'Name' => 'Test1' , 'Type' => $BUTTON_PUSH , 'Next' => 0 , 'Status' => $P18B1 , 'Icon' => $ICON_BULB ),
2 => array('ID'=>2 , 'Name' => 'Test2' , 'Type' => $BUTTON_PUSH , 'Next' => 0 , 'Status' => $P18B2 , 'Icon' => $ICON_BULB ),
3 => array('ID'=>3 , 'Name' => 'Test3' , 'Type' => $BUTTON_PAGE , 'Next' => 9 , 'Status' => $P18B3 , 'Icon' => $ICON_HEAT ),
4 => array('ID'=>4 , 'Name' => 'Test4' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Status' => $P18B4 , 'Icon' => $ICON_MUSIC),
5 => array('ID'=>5 , 'Name' => 'Test5' , 'Type' => $BUTTON_PAGE , 'Next' => 0 , 'Status' => $P18B5 , 'Icon' => $ICON_INFO)
)
);
$scenario->setLog("$Name_scenario - Step 02 - GetValue");
// Les commandes ne doivent pas être exécutées à ce stade, elles doivent seulement être récupérées
$button_pid = cmd::byString('#[Technique][NSPANNEL01][button_pid]#')->execCmd(null, false, false);
$button_bid = cmd::byString('#[Technique][NSPANNEL01][button_bid]#')->execCmd(null, false, false);
$page_pid = cmd::byString('#[Technique][NSPANNEL01][page_pid]#')->execCmd(null, false, false);
$page_type = cmd::byString('#[Technique][NSPANNEL01][page_type]#')->execCmd(null, false, false);
$button_next = cmd::byString('#[Technique][NSPANNEL01][page_next]#')->execCmd(null, false, false);
$button_result = cmd::byString('#[Technique][NSPANNEL01][button_result]#')->execCmd(null, false, false);
function sync_panel ($PANEL_ID) {
global $PANELS;
// Construct JSON for SYNC_PANEL
$nb_button = $PANELS[$PANEL_ID][0]["NB_BUTTON"];
$SYNC_PAGE = '{"sync":{"pid":'.$PANEL_ID.',"buttons":[';
for ($i = 1 ; $i < ($nb_button + 1) ; $i++) {
$BID = $PANELS[$PANEL_ID][$i]['ID']; $B_STATUS = $PANELS[$PANEL_ID][$i]['Status'] ;
if ($i == 1) {
$SYNC_PAGE .= '{"bid":' . $BID . ',"state":' . $B_STATUS . '}';
} else {
$SYNC_PAGE .= ',{"bid":' . $BID . ',"state":' . $B_STATUS . '}';
}
}
$SYNC_PAGE .= ']}}';
// Send Panel design
$SYNC= json_encode($SYNC_PAGE,JSON_FORCE_OBJECT);
$cmd=cmd::byString('#[Technique][NSPANNEL01][CustomCMD]#');
log::add('scenario_execution', 'info', 'PANEL_SYNC PANEL_ID ' . $PANEL_ID );
$cmd->execCmd($options=array('title'=>'SYNC_PANEL', 'message'=> $SYNC), $cache=0);
echo "------- $Name_scenario ---------- SYNC_PANEL $PANEL_ID \n";
//var_dump($cmd) ;
var_dump($SYNC) ;
};
function sync_button ($PANEL_ID, $PANEL_BUTTON) {
global $PANELS;
// Construct JSON for SYNC_BUTTON
//$nb_button = $PANELS[$PANEL_ID][0]["NB_BUTTON"];
$SYNC_PAGE = '{"sync":{"pid":'.$PANEL_ID.',"buttons":[';
$BID = $PANELS[$PANEL_ID][$PANEL_BUTTON]['ID']; $B_STATUS = $PANELS[$PANEL_ID][$PANEL_BUTTON]['Status'] ;
$SYNC_PAGE .= '{"bid":' . $BID . ',"state":' . $B_STATUS . '}';
$SYNC_PAGE .= ']}}';
// Send Panel design
$SYNC= json_encode ($SYNC_PAGE,JSON_FORCE_OBJECT);
$cmd=cmd::byString('#[Technique][NSPANNEL01][CustomCMD]#');
log::add('scenario_execution', 'info', 'SYNC_BUTTON - PANEL_ID ' . $PANEL_ID . 'PANEL_BUTTON ' . $PANEL_BUTTON );
$cmd->execCmd($options=array('title' => "SYNC_BUTTON", 'message'=> $SYNC), $cache=0);
echo "------- $Name_scenario ---------- SYNC_BUTTON $PANEL_ID , $PANEL_BUTTON \n";
// var_dump($cmd) ;
var_dump($SYNC) ;
};
function refresh_panel ($PANEL_ID){
global $PANELS;
// Construct JSON for REFRESH_PANEL
log::add('scenario_execution', 'info', "$Name_scenario - Step 3 - PANEL $PANEL_ID - construction");
// Construct JSON_PANEL
//if (isset($PANELS[$PANEL_ID][0]['NB_BUTTON'])) {
$nb_button = $PANELS[$PANEL_ID][0]['NB_BUTTON'];
$PANEL_NAME = $PANELS[$PANEL_ID][0]['NAME'];
$PANEL_FORMAT = $PANELS[$PANEL_ID][0]['FORMAT'];
$PANEL = '{"refresh":{"pid":' .$PANEL_ID. ' ,"name":"' .$PANEL_NAME. '","format":' . $PANEL_FORMAT . ',buttons:[' ;
//for ($i = 1 ; $i < $nb_of_button ; $i++) {
for ($i = 1 ; $i < $nb_button ; $i++) {
$BID=$PANELS[$PANEL_ID][$i]['ID'] ;
$BNAME=$PANELS[$PANEL_ID][$i]['Name'];
$BTYPE=$PANELS[$PANEL_ID][$i]['Type'];
$BNEXT=$PANELS[$PANEL_ID][$i]['Next'];
$BSTATUS=$PANELS[$PANEL_ID][$i]['Status'];
$BICON=$PANELS[$PANEL_ID][$i]['Icon'];
// log::add('scenario_execution', 'info', $PANELS[$PANEL_ID][$i]['Name'] );
if ($i == 1) {
$PANEL .= '{"bid":'. $BID .',"label":"'. $BNAME .'","type":'. $BTYPE .',"next":'. $BNEXT .',"state":'. $BSTATUS .',"icon":'. $BICON .'}';
} else {
$PANEL .= ',{"bid":'. $BID .',"label":"'. $BNAME .'","type":'. $BTYPE .',"next":'. $BNEXT .',"state":'. $BSTATUS .',"icon":'. $BICON .'}';
}
}
$PANEL .= ']}}';
$JSON_PANEL=json_encode($PANEL, JSON_FORCE_OBJECT);
// Send Panel design
$cmd=cmd::byString('#[Technique][NSPANNEL01][CustomCMD]#');
// log::add('scenario_execution', 'info', 'PANEL_PAGE_' . $PANELS[$PANEL_ID] . ' PANDEL_NAME ' . $PANELS[$PANEL_ID][0][NAME] );
$cmd->execCmd($options=array('title'=>'Titre', 'message'=> "$JSON_PANEL"), $cache=0);
echo "------- $Name_scenario ---------- refresh_panel $PANEL_ID \n";
// var_dump($cmd) ;
var_dump($JSON_PANEL) ;
};
Lorsque j’ai un refresh ou sync demandé, j’appel donc la fonction souhaitée dans un scénario :
require_once dirname(__FILE__) . '/../../data/php/panel.user.function.class.php';
// Construct JSON_PANEL
echo $page_pid ;
refresh_panel($page_pid);
ou
require_once dirname(__FILE__) . '/../../data/php/panel.user.function.class.php';
// Construct JSON_PANEL
echo $page_pid ;
sync_panel($page_pid);