Bloc code
/////////////////////// Configuration des Auth-ID //////////////////////////////////
/////////////////////// Configuration OF Auth-ID ///////////////////////////////////
// Please respect the type of each category because it allows the Auth-ID to be differentiated in the rest of the code.
// Veuillez a respecter le type de chaque catégorie parce qu'il permet de différencier le Auth-ID dans la suite du code.
$_authId = array(
// utilisateurs programmés dans le keypad | users programmed into the keypad
// type keypad_user
1111 => array('type' => 'keypad_user', 'name' => 'Phpvarious'),
2222 => array('type' => 'keypad_user', 'name' => 'Nom2'),
// type keypad
33333 => array('type' => 'keypad', 'name' => 'Keypad'),
// type app
44444 => array('type' => 'app', 'name' => 'Nom1-app'),
// type fob
55555 => array('type' => 'fob', 'name' => 'Nom1-fob')
);
//////////////////////// conversion //////////////////////////////
$_lockActions = array(
1 => 'Déverrouiller', // unlock
2 => 'Verrouiller', // lock
3 => 'Déverrouiller avec ouverture', // unlatch
4 => 'verrouiller et partir', // lock'n'go
5 => 'verrouiller et partir avec ouverture', // lock'n'go with unlatch
6 => 'verrouillage complet', // full lock
80 => 'porte-clés', // fob (sans action programmée // without programmed action)
90 => 'bouton ' // button (sans action programmée // without programmed action)
);
$_trigger = array(
0 => 'système ou bluetooth', // system or bluetooth command
1 => 'reserved', // reserved
2 => 'bouton', // button
3 => 'automatique', // automatic (e.g. time control)
6 => 'auto verrouillage', // auto lock
171 => 'HomeKit ou Matter', // HomeKit / Matter
172 => 'mqtt' // MQTT
);
$_options = array(
'keypad' => array(0 => 'back', 1 => 'code', 2 => 'fingerprint')
);
///////////////////////// DATA PROCESSING //////////////////////////////////////
// Récupère la liste des tags
// Retrieves the list of tags
$tags = $scenario->getTags();
// La fonction getRealTriggerValue() a été supprimée dans la version 4.5 et remplacée par la balise #trigger_value#.
// getRealTriggerValue() was removed in 4.5, it was replaced by tag #trigger_value#
if(method_exists("scenario", "getRealTriggerValue")) {
$tags['#trigger_value#'] = $scenario->getRealTriggerValue();
}
$scenario->setLog('┌────────────▶︎ Tag ◀──────────────');
$scenario->setLog('| lockActionEvent ─▶︎ ' . $tags['#trigger_value#']);
$array = explode(",", $tags['#trigger_value#']);
if (count($array) >= 5) {
//// VAR ////
$lockActions = $array[0];
$trigger = $array[1];
$authId = $array[2]; // Auth-ID of the user
$userId = $array[3]; // ID of the Keypad code, 0= unknown
$option = $array[4]; //Auto-Unlock (0 or 1) or number of button presses (only button & fob actions) or Keypad source (0 = back key, 1 = code, 2 = fingerprint)
//// LOGs AND TAGs ////
if (isset($_lockActions[$lockActions])) {
$scenario->setLog('| Tag ─▶︎ action = ' . $_lockActions[$lockActions]);
$tags['#action#'] = $_lockActions[$lockActions];
if ($lockActions == '80' || $lockActions == '90') { // fob or button not configured.
$tags['#nbPressButton#'] = $option;
$scenario->setLog('| Tag ─▶︎ nbPressButton = ' . $tags['#nbPressButton#']);
}
}
if (isset($_trigger[$trigger])) {
$scenario->setLog('| Tag ─▶︎ trigger = ' . $_trigger[$trigger]);
$tags['#trigger#'] = $_trigger[$trigger];
if ($trigger == '2') { // button
$tags['#nbPressButton#'] = $_trigger[$trigger];
$scenario->setLog('| Tag ─▶︎ nbPressButton = ' . $tags['#nbPressButton#']);
}
}
if ($authId != '0' && isset($_authId[$authId]) && isset($_authId[$authId]['name'])) {
$tags['#authId#'] = $_authId[$authId]['name'];
$scenario->setLog('| Tag ─▶︎ authId = ' . $tags['#authId#']);
if (isset($_authId[$authId]['type'])) {
if (isset($_options[$_authId[$authId]['type']]) && isset($_options[$_authId[$authId]['type']][$option])) {
$tags['#key#'] = $_options[$_authId[$authId]['type']][$option];
$scenario->setLog('| Tag ─▶︎ key = ' . $tags['#key#']);
}
}
}
if ($userId != '0' && isset($_authId[$userId])) {
$tags['#user#'] = $_authId[$userId]['name'];
$scenario->setLog('| Tag ─▶︎ user = ' . $tags['#user#']);
}
/// for widget perso cmd.info.string.user_nuki ///
if ($lockActions == '1') { // unlock
$scenario->setLog('|┌────────────▶︎ widget perso ◀──────────────');
if ($trigger == '172') { // MQTT
$tags['#lastUser#'] = $_trigger[$trigger];
$scenario->setLog('|| Tag ─▶︎ lastUser = ' . $tags['#lastUser#']);
} else if ($trigger == '0') { // system / bluetooth
if ($authId != '0' && isset($_authId[$authId]) && isset($_authId[$authId]['name'])) {
if (isset($_authId[$authId]['type']) && $_authId[$authId]['type'] == 'keypad') {
if ($userId != '0' && isset($_authId[$userId])) {
if (isset($_authId[$userId]['name'])) {
$user = $_authId[$userId]['name'];
if (isset($_options[$_authId[$authId]['type']][$option])) {
$user .= '_' . $_options[$_authId[$authId]['type']][$option];
}
$tags['#lastUser#'] = $user;
}
//if (isset($_options[$_authId[$authId]['type']]) && isset($_options[$_authId[$authId]['type']][$option])) {
//$user = $_authId[$authId]['name'];
}
} else {
$user = $_authId[$authId]['name'];
$tags['#lastUser#'] = $user;
}
$scenario->setLog('|| Tag ─▶︎ lastUser = ' . $user);
}
}
$scenario->setLog('|└───────────────────────────────────────────');
} else if ($lockActions == '2') { // LockAction = lock
//
}
}
$scenario->setTags($tags);
$scenario->setLog('└───────────────────────────────────────────');
Ce bloc code permet de mettre a disposition plusieurs tags, exemple :
[2026-06-21 19:19:40][SCENARIO] ┌────────────▶︎ Tag ◀──────────────
[2026-06-21 19:19:40][SCENARIO] | lockActionEvent ─▶︎ 1,0,33333,1234,1
[2026-06-21 19:19:40][SCENARIO] | Tag ─▶︎ action = Déverrouiller
[2026-06-21 19:19:40][SCENARIO] | Tag ─▶︎ trigger = système ou bluetooth
[2026-06-21 19:19:40][SCENARIO] | Tag ─▶︎ authId = Keypad
[2026-06-21 19:19:40][SCENARIO] | Tag ─▶︎ key = code
[2026-06-21 19:19:40][SCENARIO] | Tag ─▶︎ user = Naomy
[2026-06-21 19:19:40][SCENARIO] |┌────────────▶︎ widget perso ◀──────────────
[2026-06-21 19:19:40][SCENARIO] || Tag ─▶︎ lastUser = Naomy_code
[2026-06-21 19:19:40][SCENARIO] |└───────────────────────────────────────────
[2026-06-21 19:19:40][SCENARIO] └───────────────────────────────────────────
Le tag lastUser est spécialement conçu pour le widget, il ne sera pas généré que si l’action est un déverrouillage.
C’est pourquoi j’utilise ensuite un bloc si tag(lastUser,false) != 'false', qui mettra a jour ma commande lastUser.
Bloc Si
A ajouter juste après le bloc code, il permet de faire un event sur ma commande lastUser qui contient le widget custom :

Récupérer les authId
Pour récupérer les authId il faudra analyser la donnée lockActionEvent qui est envoyé en mqtt lorsque vous effectuez un déverrouillage.
Exemple 1 :
Je déverrouille depuis l’app, le payload envoyé est 1,0,44444,0,0
je sais donc que l’id de l’user utilisé sur mon app est 44444
j’ajoute maintenant cet authId dans la config du bloc code, pour qu’il puisse reconnaitre l’user :
44444 => array('type' => 'app', 'name' => 'Nom1-app'),
Exemple 2 :
Je déverrouille a l’aide de mon code d’accès sur le keypad : 1,0,33333,1111,1
Je peut en déduire 2 choses
- mon keypad utilise l’id 33333
- et l’utilisateur utilise l’id 1111
j’ajoute maintenant ces 2 authId dans le bloc code :
33333 => array('type' => 'keypad', 'name' => 'Keypad'),
1111 => array('type' => 'keypad_user', 'name' => 'Phpvarious'),
Pour tous ces exemples, vous pouvez choisir le name que vous souhaitez mais ne surtout pas utiliser de caractère _ sinon le widget pourrait mal l’interprèter.
Attention le type a son importance aussi, pour
- un user sur keypad
'type' => 'keypad_user'
- un user sur l’app
'type' => 'app'
- le keypad
'type' => 'keypad'
- fob
'type' => 'fob' // j’ai pas de fob, donc jamais testé