/**
* Create states under 0_userdata.0 or javascript.x
* Current Version: https://github.com/Mic-M/iobroker.createUserStates
* Support: https://forum.iobroker.net/topic/26839/
* Autor: Mic (ioBroker) | Mic-M (github)
* Version: 1.1 (26 January 2020)
* Example: see https://github.com/Mic-M/iobroker.createUserStates#beispiel
* -----------------------------------------------
* PLEASE NOTE: Per https://github.com/ioBroker/ioBroker.javascript/issues/474, the used function setObject()
* executes the callback PRIOR to completing the state creation. Therefore, we use a setTimeout and counter.
* -----------------------------------------------
* @param {string} where Where to create the state: '0_userdata.0' or 'javascript.x'.
* @param {boolean} force Force state creation (overwrite), if state is existing.
* @param {array} statesToCreate State(s) to create. single array or array of arrays
* @param {object} [callback] Optional: a callback function -- This provided function will be executed after all states are created.
*/
function createUserStates(where, force, statesToCreate, callback = undefined) {
const WARN = false; // Only for 0_userdata.0: Throws warning in log, if state is already existing and force=false. Default is false, so no warning in log, if state exists.
const LOG_DEBUG = false; // To debug this function, set to true
// Per issue #474 (https://github.com/ioBroker/ioBroker.javascript/issues/474), the used function setObject() executes the callback
// before the state is actual created. Therefore, we use a setTimeout and counter as a workaround.
const DELAY = 50; // Delay in milliseconds (ms). Increase this to 100, if it is not working.
// Validate "where"
if (where.endsWith('.')) where = where.slice(0, -1); // Remove trailing dot
if ( (where.match(/^((javascript\.([1-9][0-9]|[0-9]))$|0_userdata\.0$)/) == null) ) {
log('This script does not support to create states under [' + where + ']', 'error');
return;
}
// Prepare "statesToCreate" since we also allow a single state to create
if(!Array.isArray(statesToCreate[0])) statesToCreate = [statesToCreate]; // wrap into array, if just one array and not inside an array
// Add "where" to STATES_TO_CREATE
for (let i = 0; i < statesToCreate.length; i++) {
let lpPath = statesToCreate[i][0].replace(/\.*\./g, '.'); // replace all multiple dots like '..', '...' with a single '.'
lpPath = lpPath.replace(/^((javascript\.([1-9][0-9]|[0-9])\.)|0_userdata\.0\.)/,'') // remove any javascript.x. / 0_userdata.0. from beginning
lpPath = where + '.' + lpPath; // add where to beginning of string
statesToCreate[i][0] = lpPath;
}
if (where != '0_userdata.0') {
// Create States under javascript.x
let numStates = statesToCreate.length;
statesToCreate.forEach(function(loopParam) {
if (LOG_DEBUG) log('[Debug] Now we are creating new state [' + loopParam[0] + ']');
let loopInit = (loopParam[1]['def'] == undefined) ? null : loopParam[1]['def']; // mimic same behavior as createState if no init value is provided
createState(loopParam[0], loopInit, force, loopParam[1], function() {
numStates--;
if (numStates === 0) {
if (LOG_DEBUG) log('[Debug] All states processed.');
if (typeof callback === 'function') { // execute if a function was provided to parameter callback
if (LOG_DEBUG) log('[Debug] Function to callback parameter was provided');
return callback();
} else {
return;
}
}
});
});
} else {
// Create States under 0_userdata.0
let numStates = statesToCreate.length;
let counter = -1;
statesToCreate.forEach(function(loopParam) {
counter += 1;
if (LOG_DEBUG) log ('[Debug] Currently processing following state: [' + loopParam[0] + ']');
if( ($(loopParam[0]).length > 0) && (existsState(loopParam[0])) ) { // Workaround due to https://github.com/ioBroker/ioBroker.javascript/issues/478
// State is existing.
if (WARN && !force) log('State [' + loopParam[0] + '] is already existing and will no longer be created.', 'warn');
if (!WARN && LOG_DEBUG) log('[Debug] State [' + loopParam[0] + '] is already existing. Option force (=overwrite) is set to [' + force + '].');
if(!force) {
// State exists and shall not be overwritten since force=false
// So, we do not proceed.
numStates--;
if (numStates === 0) {
if (LOG_DEBUG) log('[Debug] All states successfully processed!');
if (typeof callback === 'function') { // execute if a function was provided to parameter callback
if (LOG_DEBUG) log('[Debug] An optional callback function was provided, which we are going to execute now.');
return callback();
}
} else {
// We need to go out and continue with next element in loop.
return; // https://stackoverflow.com/questions/18452920/continue-in-cursor-foreach
}
} // if(!force)
}
// State is not existing or force = true, so we are continuing to create the state through setObject().
let obj = {};
obj.type = 'state';
obj.native = {};
obj.common = loopParam[1];
setObject(loopParam[0], obj, function (err) {
if (err) {
log('Cannot write object for state [' + loopParam[0] + ']: ' + err);
} else {
if (LOG_DEBUG) log('[Debug] Now we are creating new state [' + loopParam[0] + ']')
let init = null;
if(loopParam[1].def === undefined) {
if(loopParam[1].type === 'number') init = 0;
if(loopParam[1].type === 'boolean') init = false;
if(loopParam[1].type === 'string') init = '';
} else {
init = loopParam[1].def;
}
setTimeout(function() {
setState(loopParam[0], init, true, function() {
if (LOG_DEBUG) log('[Debug] setState durchgeführt: ' + loopParam[0]);
numStates--;
if (numStates === 0) {
if (LOG_DEBUG) log('[Debug] All states processed.');
if (typeof callback === 'function') { // execute if a function was provided to parameter callback
if (LOG_DEBUG) log('[Debug] Function to callback parameter was provided');
return callback();
}
}
});
}, DELAY + (20 * counter) );
}
});
});
}
}
//log('--- Datenobjekte fuer die Bewaesserung werden angelegt ---')
let vars = [
//Bewässerung
[basic_vars_pfad+'.bewaesserung_aktiv', {'name':'bewaesserung_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.bewaesserung_automatik', {'name':'bewaesserung_automatik','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.bewaesserung_pause', {'name':'bewaesserung_pause','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
//Timer
[basic_vars_pfad+'.lautzeit_gesamt_in_sek', {'name':'lautzeit_gesamt_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.lautzeit_ende_uhrzeit', {'name':'lautzeit_ende_uhrzeit','type':'string','read':true,'write':false,'role':'string','def': ''}],
[basic_vars_pfad+'.restlautzeit', {'name':'restlautzeit','type': 'mixed','read':true,'write':false,'role':'mixed','def':0}],
[basic_vars_pfad+'.restlautzeit_in_sek', {'name':'restlautzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.gesamtfortschritt', {'name':'gesamtfortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.gesamtrest', {'name':'gesamtrest','type':'mixed','read':true,'write':false,'role':'mixed','def':100,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.letzter_durchgang', {'name':'letzter_durchgang','type':'string','read':true,'write':false,'role':'string','def': '00:00'}],
//Schwellwerte
[basic_vars_pfad+'.schwellwerte.schwellwert_check_aktiv', {'name':'schwellwert_check_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':true}],
[basic_vars_pfad+'.schwellwerte.schwellwert_regen', {'name':'schwellwert_regen','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'mm'}],
[basic_vars_pfad+'.schwellwerte.schwellwert_temperatur', {'name':'schwellwert_temperatur','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'°C'}],
[basic_vars_pfad+'.schwellwerte.schwellwerte_ok', {'name':'schwellwerte_ok','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
[basic_vars_pfad+'.schwellwerte.schwellwerte_info_senden', {'name':'schwellwerte_info_senden','type':'boolean','read':true,'write':true,'role':'switch','def':false, 'descr':'Dieser DP wird ausgeloest, wenn die Automatik startet, die Schwellwerte aber ueberschritten wurden'}],
[basic_vars_pfad+'.schwellwerte.gestern_regen', {'name':'gestern_regen','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'mm'}],
[basic_vars_pfad+'.schwellwerte.gestern_temp', {'name':'gestern_temp','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'°C'}],
//Ventile
[basic_vars_pfad+'.ventile.anzahl_aktive_ventile', {'name':'anzahl_aktive_ventile','type':'number','read':true,'write':false,'role':'number','def':0,'min':0, 'max':6} ],
//Zeitplan
[basic_vars_pfad+'.zeitplan.cron_restart', {'name':'cron_restart','type': 'mixed','read':true,'write':false,'role':'mixed','def':0,'unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.sonnenaufgang', {'name':'sonnenaufgang','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.sonnenuntergang', {'name':'sonnenuntergang','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
//Morgens
[basic_vars_pfad+'.zeitplan.morgens_aktiv', {'name':'morgens_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.zeitplan.morgens_uhrzeit_start', {'name':'morgens_uhrzeit_start','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.morgens_uhrzeit_ende', {'name':'morgens_uhrzeit_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.morgens_verzoegerung_sonnenaufgang', {'name':'morgens_verzoegerung_sonnenaufgang','type': 'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
//Abends
[basic_vars_pfad+'.zeitplan.abends_aktiv', {'name':'abends_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.zeitplan.abends_uhrzeit_start', {'name':'abends_uhrzeit_start','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.abends_uhrzeit_ende', {'name':'abends_uhrzeit_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.abends_verzoegerung_sonnenuntergang', {'name':'abends_verzoegerung_sonnenuntergang','type': 'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
//Feste Startzeit 1
[basic_vars_pfad+'.zeitplan.feste_startzeit_1_aktiv', {'name':'feste_startzeit_1_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.zeitplan.feste_startzeit_1_uhrzeit_start', {'name':'feste_startzeit_1_uhrzeit_start','type':'string','read':true,'write':true,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.feste_startzeit_1_uhrzeit_ende', {'name':'feste_startzeit_1_uhrzeit_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
//Feste Startzeit 2
[basic_vars_pfad+'.zeitplan.feste_startzeit_2_aktiv', {'name':'feste_startzeit_2_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.zeitplan.feste_startzeit_2_uhrzeit_start', {'name':'feste_startzeit_2_uhrzeit_start','type':'string','read':true,'write':true,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.feste_startzeit_2_uhrzeit_ende', {'name':'feste_startzeit_2_uhrzeit_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
//Feste Startzeit 3
[basic_vars_pfad+'.zeitplan.feste_startzeit_3_aktiv', {'name':'feste_startzeit_3_aktiv','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.zeitplan.feste_startzeit_3_uhrzeit_start', {'name':'feste_startzeit_3_uhrzeit_start','type':'string','read':true,'write':true,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.zeitplan.feste_startzeit_3_uhrzeit_ende', {'name':'feste_startzeit_3_uhrzeit_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
]
createUserStates(basic_vars_speicherort, false, vars);
//Diese DPs sollen bei jedem Speichern überschrieben werden
let vars_writable = [
[basic_vars_pfad+'.ventile.anzahl_ventile', {'name':'anzahl_ventile','type':'number','read':true,'write':false,'role':'number','def':basic_vars_anzahl_ventile,'min':0, 'max':basic_vars_anzahl_ventile} ],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_name', {'name':'ventil_1_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis1_name}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_name', {'name':'ventil_2_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis2_name}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_name', {'name':'ventil_3_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis3_name}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_name', {'name':'ventil_4_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis4_name}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_name', {'name':'ventil_5_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis5_name}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_name', {'name':'ventil_6_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis6_name}],
]
createUserStates(basic_vars_speicherort, true, vars_writable);
if(basic_vars_anzahl_ventile > 0) {
let vars_ventil_1 = [
//Ventil 1
[basic_vars_pfad+'.ventile.ventil_1.ventil_1', {'name':'ventil_1','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_dauer', {'name': 'ventil_1_dauer','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_dauer_in_min', {'name': 'ventil_1_dauer_in_min','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_ende', {'name':'ventil_1_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_fortschritt', {'name':'ventil_1_fortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_rest', {'name':'ventil_1_rest','type':'number','read':true,'write':false,'role':'number','def':100,'unit':'%','min':0,'max':100}],
//[basic_vars_pfad+'.ventile.ventil_1.ventil_1_name', {'name':'ventil_1_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis1_name}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_restzeit', {'name':'ventil_1_restzeit','type': 'string','read':true,'write':false,'role':'string','def':'0:00','unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_restzeit_in_sek', {'name':'ventil_1_restzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_status', {'name':'ventil_1_status','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_1.ventil_1_parallel', {'name':'ventil_1_parallel','type':'boolean','read':true,'write':true,'role':'switch','def':false,'descr':'Wenn dieser DP aktiviert wird, dann werden Ventil 2 bis X parallel zu Ventil 1 gestartet. Usecase: an Ventil 1 ist ein Tropfschlauch angeschlossen.'}],
]
createUserStates(basic_vars_speicherort, false, vars_ventil_1);}
if(basic_vars_anzahl_ventile > 1) {
let vars_ventil_2 = [
//Ventil 2
[basic_vars_pfad+'.ventile.ventil_2.ventil_2', {'name':'ventil_2','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_dauer', {'name': 'ventil_2_dauer','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_dauer_in_min', {'name': 'ventil_2_dauer_in_min','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_ende', {'name':'ventil_2_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_fortschritt', {'name':'ventil_2_fortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_rest', {'name':'ventil_2_rest','type':'number','read':true,'write':false,'role':'number','def':100,'unit':'%','min':0,'max':100}],
//[basic_vars_pfad+'.ventile.ventil_2.ventil_2_name', {'name':'ventil_2_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis2_name}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_restzeit', {'name':'ventil_2_restzeit','type': 'string','read':true,'write':false,'role':'string','def':'0:00','unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_restzeit_in_sek', {'name':'ventil_2_restzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_2.ventil_2_status', {'name':'ventil_2_status','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
]
createUserStates(basic_vars_speicherort, false, vars_ventil_2);}
if(basic_vars_anzahl_ventile > 2) {
let vars_ventil_3 = [
//Ventil 3
[basic_vars_pfad+'.ventile.ventil_3.ventil_3', {'name':'ventil_3','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_dauer', {'name': 'ventil_3_dauer','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_dauer_in_min', {'name': 'ventil_3_dauer_in_min','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_ende', {'name':'ventil_3_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_fortschritt', {'name':'ventil_3_fortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_rest', {'name':'ventil_3_rest','type':'number','read':true,'write':false,'role':'number','def':100,'unit':'%','min':0,'max':100}],
//[basic_vars_pfad+'.ventile.ventil_3.ventil_3_name', {'name':'ventil_3_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis3_name}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_restzeit', {'name':'ventil_3_restzeit','type': 'string','read':true,'write':false,'role':'string','def':'0:00','unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_restzeit_in_sek', {'name':'ventil_3_restzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_3.ventil_3_status', {'name':'ventil_3_status','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
]
createUserStates(basic_vars_speicherort, false, vars_ventil_3);}
if(basic_vars_anzahl_ventile > 3) {
let vars_ventil_4 = [
//Ventil 4
[basic_vars_pfad+'.ventile.ventil_4.ventil_4', {'name':'ventil_4','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_dauer', {'name': 'ventil_4_dauer','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_dauer_in_min', {'name': 'ventil_4_dauer_in_min','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_ende', {'name':'ventil_4_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_fortschritt', {'name':'ventil_4_fortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_rest', {'name':'ventil_4_rest','type':'number','read':true,'write':false,'role':'number','def':100,'unit':'%','min':0,'max':100}],
//[basic_vars_pfad+'.ventile.ventil_4.ventil_4_name', {'name':'ventil_4_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis4_name}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_restzeit', {'name':'ventil_4_restzeit','type': 'string','read':true,'write':false,'role':'string','def':'0:00','unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_restzeit_in_sek', {'name':'ventil_4_restzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_4.ventil_4_status', {'name':'ventil_4_status','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
]
createUserStates(basic_vars_speicherort, false, vars_ventil_4);}
if(basic_vars_anzahl_ventile > 4) {
let vars_ventil_5 = [
//Ventil 5
[basic_vars_pfad+'.ventile.ventil_5.ventil_5', {'name':'ventil_5','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_dauer', {'name': 'ventil_5_dauer','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_dauer_in_min', {'name': 'ventil_5_dauer_in_min','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_ende', {'name':'ventil_5_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_fortschritt', {'name':'ventil_5_fortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_rest', {'name':'ventil_5_rest','type':'number','read':true,'write':false,'role':'number','def':100,'unit':'%','min':0,'max':100}],
//[basic_vars_pfad+'.ventile.ventil_5.ventil_5_name', {'name':'ventil_5_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis5_name}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_restzeit', {'name':'ventil_5_restzeit','type': 'string','read':true,'write':false,'role':'string','def':'0:00','unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_restzeit_in_sek', {'name':'ventil_5_restzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_5.ventil_5_status', {'name':'ventil_5_status','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
]
createUserStates(basic_vars_speicherort, false, vars_ventil_5);}
if(basic_vars_anzahl_ventile > 5) {
let vars_ventil_6 = [
//Ventil 6
[basic_vars_pfad+'.ventile.ventil_6.ventil_6', {'name':'ventil_6','type':'boolean','read':true,'write':true,'role':'switch','def':false}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_dauer', {'name': 'ventil_6_dauer','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_dauer_in_min', {'name': 'ventil_6_dauer_in_min','type':'number','read':true,'write':true,'role':'number','def':0,'unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_ende', {'name':'ventil_6_ende','type':'string','read':true,'write':false,'role':'string','def':'00:00','unit':'Uhr'}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_fortschritt', {'name':'ventil_6_fortschritt','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'%','min':0,'max':100}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_rest', {'name':'ventil_6_rest','type':'number','read':true,'write':false,'role':'number','def':100,'unit':'%','min':0,'max':100}],
//[basic_vars_pfad+'.ventile.ventil_6.ventil_6_name', {'name':'ventil_6_name','type':'string','read':true,'write':false,'role':'string','def':basic_vars_kreis6_name}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_restzeit', {'name':'ventil_6_restzeit','type': 'string','read':true,'write':false,'role':'string','def':'0:00','unit':'Minuten'}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_restzeit_in_sek', {'name':'ventil_6_restzeit_in_sek','type':'number','read':true,'write':false,'role':'number','def':0,'unit':'Sekunden'}],
[basic_vars_pfad+'.ventile.ventil_6.ventil_6_status', {'name':'ventil_6_status','type':'boolean','read':true,'write':false,'role':'switch','def':false}],
]
createUserStates(basic_vars_speicherort, false, vars_ventil_6);}
//Ab hier nicht benötigte Datenpunkte löschen
//###############################################################################
//Ventil 1 wieder löschen
timeout = setTimeout(function () {
if(basic_vars_anzahl_ventile < 1 && basic_vars_speicherort.slice(0, 10) == 'javascript') {
const idsjs = $('javascript.*.'+[basic_vars_pfad]+'.ventile.ventil_1.*');
idsjs.each(function(id, i) {
if(existsState(id)) deleteState(id.substring(13));})};
if(basic_vars_anzahl_ventile < 1 && basic_vars_speicherort.slice(0, 10) == '0_userdata') {
const idsud = $('0_userdata.0.'+[basic_vars_pfad]+'.ventile.ventil_1.*');
idsud.each(function(id, i) {
if(existsState(id)) deleteState(id);})};
//Ventil 2 wieder löschen
if(basic_vars_anzahl_ventile < 2 && basic_vars_speicherort.slice(0, 10) == 'javascript') {
const idsjs = $('javascript.*.'+[basic_vars_pfad]+'.ventile.ventil_2.*');
idsjs.each(function(id, i) {
if(existsState(id)) deleteState(id.substring(13));})};
if(basic_vars_anzahl_ventile < 2 && basic_vars_speicherort.slice(0, 10) == '0_userdata') {
const idsud = $('0_userdata.0.'+[basic_vars_pfad]+'.ventile.ventil_2.*');
idsud.each(function(id, i) {
if(existsState(id)) deleteState(id);})};
//Ventil 3 wieder löschen
if(basic_vars_anzahl_ventile < 3 && basic_vars_speicherort.slice(0, 10) == 'javascript') {
const idsjs = $('javascript.*.'+[basic_vars_pfad]+'.ventile.ventil_3.*');
idsjs.each(function(id, i) {
if(existsState(id)) deleteState(id.substring(13));})};
if(basic_vars_anzahl_ventile < 3 && basic_vars_speicherort.slice(0, 10) == '0_userdata') {
const idsud = $('0_userdata.0.'+[basic_vars_pfad]+'.ventile.ventil_3.*');
idsud.each(function(id, i) {
if(existsState(id)) deleteState(id);})};
//Ventil 4 wieder löschen
if(basic_vars_anzahl_ventile < 4 && basic_vars_speicherort.slice(0, 10) == 'javascript') {
const idsjs = $('javascript.*.'+[basic_vars_pfad]+'.ventile.ventil_4.*');
idsjs.each(function(id, i) {
if(existsState(id)) deleteState(id.substring(13));})};
if(basic_vars_anzahl_ventile < 4 && basic_vars_speicherort.slice(0, 10) == '0_userdata') {
const idsud = $('0_userdata.0.'+[basic_vars_pfad]+'.ventile.ventil_4.*');
idsud.each(function(id, i) {
if(existsState(id)) deleteState(id);})};
//Ventil 5 wieder löschen
if(basic_vars_anzahl_ventile < 5 && basic_vars_speicherort.slice(0, 10) == 'javascript') {
const idsjs = $('javascript.*.'+[basic_vars_pfad]+'.ventile.ventil_5.*');
idsjs.each(function(id, i) {
if(existsState(id)) deleteState(id.substring(13));})};
if(basic_vars_anzahl_ventile < 5 && basic_vars_speicherort.slice(0, 10) == '0_userdata') {
const idsud = $('0_userdata.0.'+[basic_vars_pfad]+'.ventile.ventil_5.*');
idsud.each(function(id, i) {
if(existsState(id)) deleteState(id);})};
//Ventil 6 wieder löschen
if(basic_vars_anzahl_ventile < 6 && basic_vars_speicherort.slice(0, 10) == 'javascript') {
const idsjs = $('javascript.*.'+[basic_vars_pfad]+'.ventile.ventil_6.*');
idsjs.each(function(id, i) {
if(existsState(id)) deleteState(id.substring(13));})};
if(basic_vars_anzahl_ventile < 6 && basic_vars_speicherort.slice(0, 10) == '0_userdata') {
const idsud = $('0_userdata.0.'+[basic_vars_pfad]+'.ventile.ventil_6.*');
idsud.each(function(id, i) {
if(existsState(id)) deleteState(id);})};
}, 5000);
//###############################################################################
//Funktion main mit Verzögerung aufrufen
timeout = setTimeout(function () {
Variablen_definieren();
}, 5000);