Die Buttons funzen nicht richtig, da die Datenpunkte nicht komplett erzeugt werden.
Besser wäre folgende Erstellung:
// states für Asführungsbestätigung der remote reboot / shutdown scripts
// und zum automatischem schließen des Bestätigungsbutton nach einer Zeit X (timout)
// -----------------------------------------------
// Vorbereitung
// -----------------------------------------------
var timout = 2*1000;
var forceCreation = true;
var pfad = 't2c_System.';
var datenpunkte = {
'restart_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für Reboot', unit: ''}},
'stop_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für Shutdown', unit: ''}},
'update_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für Update', unit: ''}},
'upgrade_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für Upgrade', unit: ''}},
'upgradeSelf_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für UpgradeSelf', unit: ''}},
'LinuxRestart_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für Linux-Restart', unit: ''}},
'LinuxShutdown_Bestaetigung': {"init": false, "common": {type: 'boolean', name: 'Bestätigung für Linux-Shutdown', unit: ''}},
'restart_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung des "iobroker restart" Kommandos', unit: ''}},
'stop_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung "iobroker stop" Kommandos', unit: ''}},
'update_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung "iobroker update" Kommandos', unit: ''}},
'upgrade_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung "iobroker upgrade" Kommandos', unit: ''}},
'upgradeSelf_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung "iobroker upgrade self" Kommandost', unit: ''}},
'LinuxShutdown_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung "shutdown -h now" Kommandos', unit: ''}},
'LinuxRestart_command': {"init": false, "common": {type: 'boolean', name: 'Ausführung "reboot" Kommandos', unit: ''}}
};
//=========================================================================
// Trigger
//=========================================================================
on({id: 'javascript.0.t2c_System.restart_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.restart_Bestaetigung', false)},timout);
}
});
on({id: 'javascript.0.t2c_System.stop_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.stop_Bestaetigung', false)},timout);
}
});
on({id: 'javascript.0.t2c_System.update_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.update_Bestaetigung', false)},timout);
}
});
on({id: 'javascript.0.t2c_System.upgrade_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.upgrade_Bestaetigung', false)},timout);
}
});
on({id: 'javascript.0.t2c_System.upgradeSelf_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.upgradeSelf_Bestaetigung', false)},timout);
}
});
on({id: 'javascript.0.t2c_System.LinuxRestart_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.LinuxRestart_Bestaetigung', false)},timout);
}
});
on({id: 'javascript.0.t2c_System.LinuxShutdown_Bestaetigung', change : 'any'}, function(obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
setTimeout(function(){setState('javascript.0.t2c_System.LinuxShutdown_Bestaetigung', false)},timout);
}
});
// -----------------------------------------------
// Scripte zum Ausführen der exec Funktionen
// -----------------------------------------------
// iobroker restart
on({id: 'javascript.0.t2c_System.restart_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: iobroker restart');
setState('javascript.0.t2c_System.restart_command', false);
exec ('iobroker restart');
}
});
// iobroker stop
createState('t2c_System.stop_command', '');
on({id: 'javascript.0.t2c_System.stop_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: iobroker stop');
setState('javascript.0.t2c_System.stop_command', false);
exec ('iobroker stop');
}
});
// iobroker update
createState('t2c_System.update_command', '');
on({id: 'javascript.0.t2c_System.update_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: iobroker update');
setState('javascript.0.t2c_System.update_command', false);
exec ('iobroker update');
}
});
// iobroker upgrade
createState('t2c_System.upgrade_command', '');
on({id: 'javascript.0.t2c_System.upgrade_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: iobroker upgrade');
setState('javascript.0.t2c_System.upgrade_command', false);
exec ('iobroker upgrade');
}
});
// iobroker upgrade self
createState('t2c_System.upgradeSelf_command', '');
on({id: 'javascript.0.t2c_System.upgradeSelf_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: iobroker upgrade self');
setState('javascript.0.t2c_System.upgradeSelf_command', false);
exec ('iobroker upgrade self');
}
});
// Linux shutdown
createState('t2c_System.LinuxShutdown_command', '');
on({id: 'javascript.0.t2c_System.LinuxShutdown_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: Linux shutdown');
setState('javascript.0.t2c_System.LinuxShutdown_command', false);
exec ('sudo shutdown -h 0');
}
});
// Linux Reboot
createState('t2c_System.LinuxRestart_command', '');
on({id: 'javascript.0.t2c_System.LinuxRestart_command', change: 'any'}, function (obj) {
if (obj.newState.val === true || obj.newState.val === 'true'){
log('vis: Linux Reboot');
setState('javascript.0.t2c_System.LinuxRestart_command', false);
exec ('reboot');
}
});
// -----------------------------------------------------------------------------------------------------------------------------------------
// Erzeuge Datenpunkte
// -----------------------------------------------------------------------------------------------------------------------------------------
function createDp()
{
var name;
var init;
var common;
for (var dp in datenpunkte)
{
name = pfad + dp;
init = datenpunkte[dp].init;
common = datenpunkte[dp].common;
createState(name, init , forceCreation, common);
}
}
// -----------------------------------------------
// Start Skript:
// Initialisierung
// -----------------------------------------------
createDp();
Habe es noch etwas "gebeautyfied"