Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. ehemalige Historydaten finden

    NEWS

    • [erledigt] 15. 05. Wartungsarbeiten am ioBroker Forum

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    ehemalige Historydaten finden

    This topic has been deleted. Only users with topic management privileges can see it.
    • Homoran
      Homoran Global Moderator Administrators @Matt77CHE last edited by

      @matt77che sagte in ehemalige Historydaten finden:

      was muss ich da genau eintragen?

      fs <enter>

      M 1 Reply Last reply Reply Quote 0
      • M
        Matt77CHE @Homoran last edited by

        @homoran
        fs hinzugefügt, adapter neu gestartet;

        14.10.2024, 20:41:24.871	[error]: javascript.0 (623441) script.js.common.Alte_history_dp_löschen: TypeError: Cannot read properties of undefined (reading 'length')
        14.10.2024, 20:41:24.872	[error]: javascript.0 (623441)     at script.js.common.Alte_history_dp_löschen:238:18
        14.10.2024, 20:41:25.376	[error]: host.iobroker Caught by controller[0]:     at script.js.common.Alte_history_dp_löschen:239:18
        
        1 Reply Last reply Reply Quote 0
        • M
          Matt77CHE @Homoran last edited by

          @homoran sagte in ehemalige Historydaten finden:

          @matt77che da steht kein length an der genannten Stelle

          Das habe ich auch festgestellt. Die Angegebenen falschen Zeilen stimmen nicht überein

          Homoran 1 Reply Last reply Reply Quote 0
          • Homoran
            Homoran Global Moderator Administrators @Matt77CHE last edited by

            @matt77che hast du Scripte in global?

            M 1 Reply Last reply Reply Quote 0
            • M
              Matt77CHE @Homoran last edited by

              @homoran

              nein, der Ordner Global ist leer

              Homoran 1 Reply Last reply Reply Quote 0
              • Homoran
                Homoran Global Moderator Administrators @Matt77CHE last edited by

                @matt77che sind die zeilennummern hier im Post denn identisch mit denen von deinem Script?

                M 1 Reply Last reply Reply Quote 0
                • M
                  Matt77CHE @Homoran last edited by

                  @homoran

                  Ja - Also im Script stimmt es auch nicht überein

                  Homoran M 2 Replies Last reply Reply Quote 0
                  • Homoran
                    Homoran Global Moderator Administrators @Matt77CHE last edited by

                    @matt77che sagte in ehemalige Historydaten finden:

                    @homoran

                    Ja - Also im Script stimmt es auch nicht überein

                    dann zeig doch bitte die Zeilen deines Skripts (+/- 3) die angemeckert werden

                    1 Reply Last reply Reply Quote 0
                    • M
                      MCU @Matt77CHE last edited by MCU

                      @matt77che Hab es gerade mal probiert und es läuft ohne Probleme.
                      Zeig mal bitte die History-Einstellungen.
                      Auch mit
                      History-Adapter V3.0.1
                      Javascript-Adapter V8.8.3

                      Es gibt in der 237 ein file.length
                      10c211ff-67a2-4639-857b-88ae6f4aa264-image.png

                      Verwendest du eine andere History-Instanz?
                      51590510-401e-4733-844d-dbd1e0789b10-image.png

                      NEUE VERSION v1.0.6 reingestellt -> automatische Suche der History-Instanzen.

                      1 Reply Last reply Reply Quote 0
                      • M
                        Matt77CHE last edited by

                        Ja, ich habe zwei instanzen; history.0 und eine history.1

                        Also ich habe mir die v1.0.6 gezogen und es noch einmal versucht:
                        Fehlermeldung:

                        16.10.2024, 17:36:27.155	[error]: javascript.0 (1767186) script.js.common.Alte_history_dp_löschen: Fehler beim Lesen des Verzeichnisses: Error: ENOENT: no such file or directory, scandir ''
                        
                        M 1 Reply Last reply Reply Quote 0
                        • M
                          MCU @Matt77CHE last edited by

                          @matt77che Was steht im Log?

                          Ablage für History
                          
                          1 Reply Last reply Reply Quote 0
                          • M
                            Matt77CHE last edited by

                            Im >Script zeigt es mit bei den Zeilen
                            148
                            214
                            218
                            238
                            einen Fehler an

                            // ********************************
                            // findOldHistoryDPs v1.0.6
                            // Copyright ©MCU
                            // ********************************
                            // v1.0.1 directDelete-> true  Möglichkeit die DatenDateien direkt löschen
                            // v1.0.2 aliasId berücksichtigt bei enabledDPs
                            // v1.0.3 zusätzliche Funktion listHistoryDPsWithaliasId('history.0');
                            // v1.0.4 zusätzlich: fillAlias -> alle aktiven history-DPs mit alias in Array withAliasIdInEnabled
                            //        fillEnabled_DPs -> nur die akitven History DPs in Array füllen -> enabled_DPs
                            //        useAliasIdInEnabled -> true -> AliasId wird in enabled_DPs verwendet (was richtig ist, da die history-Werte mit alias geschrieben werden)
                            // v1.0.5 zusätzliche Funktion: alias-Suche in allen ioBroker-DPs (unabhängig von history)
                            // v1.0.6 error-Handling bei searchDir(),activeHistory, DP-Auswahl History
                            
                            
                            let findOldDP                       = '0_userdata.0.history.findOldDPs';
                            let findOldDPs_Old                  = findOldDP + '.old_DPs';
                            let findOldDPs_Enabled              = findOldDP + '.enabled_DPs';
                            let findOldDPs_InDB                 = findOldDP + '.inDB_DPS';
                            let findOldDPs_BeginTS              = findOldDP + '.dirStart';
                            let findOldDPs_EndTS                = findOldDP + '.dirEnd';
                            let findOldDPs_Start                = findOldDP + '.start';
                            let findOldDPs_DirectDel            = findOldDP + '.directDelete';
                            let findOldDPs_fillEnabled          = findOldDP + '.fillEnabled_DPs';
                            let findOldDPs_fillAlias            = findOldDP + '.fillWithAliasId';
                            let findoldDPs_withAliasId          = findOldDP + '.withAliasId_DPs';
                            let findOldDPs_useAliasInEnabled    = findOldDP + '.useAliasIdInEnabled';
                            let activeHistoryDP                 = findOldDP + '.activeHistory';
                            let findOldDPs_aliasDPs             = findOldDP + '.aliasDPs';
                            let findOldDPs_aliasDPs_search      = findOldDP + '.aliasDPs_search'; 
                            createStateAsync(findOldDPs_aliasDPs, {read: true, write: true, name: "ioBroker-DPs mit aliasId (unabhängig history)", type: "string", role: "text", def: JSON.stringify([]) });
                            createStateAsync(findOldDPs_aliasDPs_search, {read: true, write: true, name: "Start Suche aliasIds in all ioBroker DPs", type: "boolean", role: "button", def: false });
                            
                            let dbNamespace = 'history.0';
                            
                            
                            //createStateAsync(findOldDPs_Old, {read: true, write: true, name: "JSON für nicht genutzte DPs noch in DB", type: "string", role: "text", def: JSON.stringify([]) });
                            createStateAsync(findOldDPs_Enabled, {read: true, write: true, name: "Aktive History-DPs in DB", type: "string", role: "text", def: JSON.stringify([]) });
                            createStateAsync(findoldDPs_withAliasId, {read: true, write: true, name: "Aktive History-DPs mit aliasId", type: "string", role: "text", def: JSON.stringify([]) });
                            //createStateAsync(findOldDPs_InDB, {read: true, write: true, name: "Genutzte DPs in DB", type: "string", role: "text", def: JSON.stringify([]) });
                            createStateAsync(findOldDPs_BeginTS, {read: true, write: true, name: "Startverzeichnis", type: "number", role: "", def: 0 });
                            createStateAsync(findOldDPs_EndTS, {read: true, write: true, name: "Endverzeichnis", type: "number", role: "", def: 10 }); //new Date().getTime()
                            createStateAsync(findOldDPs_Start, {read: true, write: true, name: "Start Suche", type: "boolean", role: "button", def: false });
                            createStateAsync(findOldDPs_fillEnabled, {read: true, write: true, name: "enabled_DPs suchen", type: "boolean", role: "button", def: false });
                            createStateAsync(findOldDPs_fillAlias, {read: true, write: true, name: "withAliasId suchen", type: "boolean", role: "button", def: false });
                            createStateAsync(findOldDPs_DirectDel, {read: true, write: true, name: "!!! Daten direkt löschen !!!", type: "boolean", role: "", def: false });
                            createStateAsync(findOldDPs_useAliasInEnabled, {read: true, write: true, name: "AliasId in Enabled_DPs", type: "boolean", role: "", def: false });
                            
                            
                            setTimeout(function(){
                                findHistoryInstance()
                            },3000)
                            
                            
                            
                            on({id: findOldDPs_Start, change: "any"}, function (obj) {
                                let value = obj.state.val;
                                if (value){
                                    //setState(findOldDPs_EndTS,parseInt(new Date().getTime()),false);
                                    let dbNamespace = getState(activeHistoryDP).val
                                    if(dbNamespace !=''){
                                        getEnabledHistoryDPs(dbNamespace);
                                        let fromDir = getState(findOldDPs_BeginTS).val;
                                        let toDir = getState(findOldDPs_EndTS).val;
                                        setTimeout(function(){
                                            searchDir(fromDir,toDir);
                                        },5000);
                                    }else{
                                        console.warn('Es wurde keine History-Instanz ausgewählt!')
                                    }
                                    setStateDelayed(findOldDPs_Start,false,3000,false);
                                }
                            });
                            
                            on({id: findOldDPs_fillEnabled, change: "any"}, function (obj) {
                                let value = obj.state.val;
                                if (value){
                                    let dbNamespace = getState(activeHistoryDP).val
                                    if(dbNamespace !=''){
                                        getEnabledHistoryDPs(dbNamespace);
                                    }else{
                                        console.warn('Es wurde keine History-Instanz ausgewählt!')
                                    }
                                    setStateDelayed(findOldDPs_fillEnabled,false,3000,false);
                                }
                            });
                            
                            on({id: findOldDPs_fillAlias, change: "any"}, function (obj) {
                                let value = obj.state.val;
                                if (value){
                                    let dbNamespace = getState(activeHistoryDP).val
                                    if(dbNamespace !=''){
                                        listHistoryDPsWithaliasId(dbNamespace);
                                    }else{
                                        console.warn('Es wurde keine History-Instanz ausgewählt!')
                                    }
                                    setStateDelayed(findOldDPs_fillAlias,false,3000,false);
                                }
                            });
                            
                            on({id: findOldDPs_aliasDPs_search, change: "any"}, function (obj) {
                                let value = obj.state.val;
                                if (value){
                                    findDPsWithAliasId(); 
                                    setStateDelayed(findOldDPs_aliasDPs_search,false,3000,false);
                                }
                            });
                            //listHistoryDPsWithaliasId('history.0');
                            
                            function listHistoryDPsWithaliasId(adp){
                                let arr =[];
                                sendTo(adp, 'getEnabledDPs', {}, function (result) {
                                    let count = 0;
                                    for ( let dp in result){
                                        let dpHistoryAlias = getObject(dp).common.custom[adp].aliasId;
                                        if (dpHistoryAlias != '' && dpHistoryAlias != undefined){
                                            arr.push({'dpId':dp,'aliasId':dpHistoryAlias});
                                            count++;
                                        }
                                    }
                                    log('Anzahl der aktiv geloggten DPs mit aliasId: '+count);        
                                    // setStateAsync(findOldDPs_Enabled,JSON.stringify(arr),false);
                                    //log(JSON.stringify(arr));
                                    setState(findoldDPs_withAliasId,JSON.stringify(arr),false);
                                });
                            }
                            
                            
                            
                            
                            function findHistoryInstance(){
                                let historyDPs = $('system.adapter.history.*.alive')
                                let arr = []
                                for(let i=0;i< historyDPs.length;i++){
                                    let instance = historyDPs[i].split('.')[3]
                                    arr.push(instance)
                                    //console.log(historyDPs[i])
                                }
                                console.log('Gefundene History Instanzen: '+arr)
                                let obj = {'':'History auswählen'}
                                for (let i=0;i<arr.length;i++){
                                    obj['history.'+arr[i]] = 'history.'+arr[i]
                                }
                                // console.log(obj)
                                let firstHistory = 'history.'+arr[0]
                                
                                if(existsState(activeHistoryDP)){
                                    let histObj = getObject(activeHistoryDP)
                                    histObj.common.states = obj
                                    setObject(activeHistoryDP,histObj)
                                }else{
                                    createStateAsync(activeHistoryDP, {read: true, write: true, name: "Auswahl aktive History", type: "string", role: "", def: firstHistory, states: JSON.stringify(obj) });
                                }
                            }
                            
                            //findDPsWithAliasId(); 
                            
                            function findDPsWithAliasId(){
                                let allDPs = $('*');
                                let arr = [];
                                log('Anzahl der States: '+allDPs.length);
                                for (let i=0;i<allDPs.length;i++){
                                    if (existsObject(allDPs[i])){
                                        if (getObject(allDPs[i]).common != undefined){
                                            if (getObject(allDPs[i]).common.alias!= undefined){
                                                let aliasId = getObject(allDPs[i]).common.alias.id;
                                                if (aliasId != undefined){
                                                    //log(allDPs[i] +' mit aliasId: '+aliasId);
                                                    //break;
                                                    arr.push({'id':allDPs[i],'aliasId':aliasId});
                                                }
                                            }
                                        }
                                    }
                                }
                                //log(arr);
                                setState(findOldDPs_aliasDPs,JSON.stringify(arr),false);
                            }
                            
                            
                            /*
                            setTimeout(function(){
                                getEnabledHistoryDPs(db);
                                getHistoryDPinDB(db);
                            },3000);
                            */
                            
                            // getEnabledHistoryDPs('history.0');
                            
                            function getEnabledHistoryDPs(adp){
                                let arr =[];
                                let useAliasIdInenabled = getState(findOldDPs_useAliasInEnabled).val;
                                sendTo(adp, 'getEnabledDPs', {}, function (result) {
                                    let count = 0;
                                    for ( let dp in result){
                                        let dpHistoryAlias = getObject(dp).common.custom[adp].aliasId;
                                        if (dpHistoryAlias != '' && dpHistoryAlias != undefined && useAliasIdInenabled){
                                            arr.push(dpHistoryAlias);
                                        }else{
                                            arr.push(dp);
                                        }
                                        count++;
                                    }
                                    log('Anzahl der aktiv geloggten DPs: '+count);        
                                    setStateAsync(findOldDPs_Enabled,JSON.stringify(arr),false);
                                });
                            }
                            
                            // getHistoryDPinDB('history.0');
                            
                            function getHistoryDPinDB(db){
                                //Die 50 zuletzt gespeicherte Ereignisse für alle IDs holen:
                                let beginTS = getState(findOldDPs_BeginTS).val;
                                if (beginTS == 0){
                                    beginTS = parseInt(new Date().getTime()) - 30*24*60*60*1000;
                                }
                                let endTS = getState(findOldDPs_EndTS).val;
                                if(endTS == 0){
                                    endTS = parseInt(new Date().getTime());
                                }
                                sendTo(db, 'getHistory', {
                                    id: '*',
                                    options: {
                                        begin: beginTS,
                                        end:   endTS,
                                        /* count:     50,*/
                                        addId:     true
                                    }
                                }, function (result) {
                                    let dpArr =[];
                                    let count = 0;
                                    for (var i = 0; i < result.result.length; i++) {
                                        if (!isObjInArray(dpArr,result.result[i].id)){
                                            dpArr.push(result.result[i].id);
                                            count++;
                                        }
                                        //console.log(JSON.stringify(result.result[i]) + ' ' + new Date(result.result[i].ts).toISOString());
                                    }
                                    dpArr = dpArr.sort(function(a, b) {
                                            return a > b;
                                            });
                                    setStateAsync(findOldDPs_InDB,JSON.stringify(dpArr),false);
                                    //log('Anzahl der DPs in dem durchsuchten Bereich:'+count);
                                    log(count+' unterschiedliche DPs in "inDB" von '+ formatDate(beginTS,'DD.MM.YYYY hh:mm:ss')+' - '+formatDate(endTS,'DD.MM.YYYY hh:mm:ss'));
                                    //Vergleich der DPs
                                    let nonActiveArr = [];
                                    let activeDPs = JSON.parse(getState(findOldDPs_Enabled).val);
                                    for (let i=0; i< dpArr.length;i++){
                                        // dpArr[i]
                                        let vorhanden = false;
                                        for (let  j=0; j< activeDPs.length;j++ ){
                                            if (dpArr[i] === activeDPs[j]){
                                                vorhanden = true;
                                                break; // vorhanden
                                            }
                                        }
                                        if (!vorhanden){
                                            // wird nicht mehr geloggt von active
                                            nonActiveArr.push(dpArr[i]);
                                        }
                                    }
                                    setState(findOldDPs_Old,JSON.stringify(nonActiveArr),false);
                                });
                            }
                            
                            
                            
                            
                            function isObjInArray(arr,itemObj){
                                if (arr.length>0){
                                    for (let x=0;x<arr.length-1;x++){
                                        if (JSON.stringify(arr[x]) === JSON.stringify(itemObj)){
                                            return true;
                                        }
                                    }
                                    return false;
                                }else{
                                    return false;
                                }
                            }
                            
                            // searchDir(0,10);
                            
                            function searchDir(fromDir, toDir){
                                let fs = require('fs');
                                let activeDPs = JSON.parse(getState(findOldDPs_Enabled).val);
                                let notActiveDPs = [];
                                let dbNamespace = getState(activeHistoryDP).val
                                if(dbNamespace !=''){
                                    let sysAdaptDir = getObject('system.adapter.'+dbNamespace).native.storeDir;
                                    console.warn('Ablage für History: '+dbNamespace+' im Verzeichnis: '+sysAdaptDir)
                                    fs.readdir(sysAdaptDir , function (erro, file) {
                                        if (erro) {
                                            log('Fehler beim Lesen des Verzeichnisses: ' + erro, 'error');
                                            return;
                                        }
                                        log(file.length+' Verzeichnisse wurde(n) gelesen!');
                                        log('fromDir und toDir dürfen nur im Bereich von 0 bis '+file.length +' sein! Bitte in 10er-Schritten verwenden!');
                                        log('Es wurde ein Bereich von '+fromDir +' bis '+ toDir+' gewählt-> es dauert '+(toDir-fromDir)*2 +' Sekunden');
                                        if (fromDir <0 || toDir >file.length){
                            
                                        }else{
                                            for (let j=fromDir; j<toDir; j++){
                                                //log(file[j]);
                                                if (file[j].indexOf('.')>=0 && file[j].length >8){
                            
                                                }else{
                                                    fs.readdir(sysAdaptDir+'/'+file[j] , function (error, files) {
                                                        log(files.length+' DPs im Verzeichnis: '+file[j]);
                                                        for (let i=0;i< files.length; i++){
                                                            let dpFiles = files[i].substring(8,files[i].length-5);
                                                            if (isObjInArray(activeDPs,dpFiles)){
                                                            }else{
                                                                notActiveDPs.push({'id':dpFiles,'dir':file[j]});
                                                            }
                                                        }
                                                    });
                                                    //fs.unlinkSync('/opt/iobroker/iobroker-data/files/vis.0/'+jarvisDirName+'/'+files[i]+'/'+file[j]);
                                                }
                                            }
                                            setTimeout(function(){
                                                log('Nicht aktive DPs in den ausgewählten Verzeichnissen: '+notActiveDPs.length);
                                                let olddir= '';
                                                let directDelete = getState(findOldDPs_DirectDel).val;
                                                for (let i=0;i<notActiveDPs.length;i++){
                                                    if (directDelete){
                                                        // Direkt löschen
                                                        fs.unlinkSync(sysAdaptDir+'/'+notActiveDPs[i].dir+'/history.'+notActiveDPs[i].id+'.json');
                                                    }
                                                    if (notActiveDPs[i].dir != olddir){
                                                        if (directDelete){
                                                            log('Im Verzeichnis: '+notActiveDPs[i].dir +' folgende Dateien sind gelöscht!:','warn');
                                                        }else{
                                                            log('Im Verzeichnis: '+notActiveDPs[i].dir +' können folgende Dateien gelöscht werden:','warn');
                                                        }
                                                        olddir = notActiveDPs[i].dir;
                                                    }
                                                    log(notActiveDPs[i].id);
                                                }
                                            },2000 * (toDir-fromDir)); // file.length
                                        }
                                    });
                                }else{
                                    console.warn('Es wurde keine History-Instanz ausgewählt!')
                                }
                            }
                            
                            M Homoran 3 Replies Last reply Reply Quote 0
                            • M
                              MCU @Matt77CHE last edited by MCU

                              @matt77che Die angezeigten Fehler sind nicht das Problem.
                              Es geht um das Verzeichnis in dem die Daten liegen.
                              Was steht im Log?
                              -> Ablage für History
                              Welche Instanz wurde ausgewählt

                              Wie sind die Einstellungen in den History-Instanzen.

                              1 Reply Last reply Reply Quote 0
                              • Homoran
                                Homoran Global Moderator Administrators @Matt77CHE last edited by

                                @matt77che sagte in ehemalige Historydaten finden:

                                einen Fehler an

                                und der ist geheim?

                                M 1 Reply Last reply Reply Quote 0
                                • M
                                  MCU @Homoran last edited by

                                  @homoran Nein, wird nur rot unterschtrichen.

                                  1 Reply Last reply Reply Quote 1
                                  • M
                                    MCU @Matt77CHE last edited by

                                    @matt77che Versuch mal v1.0.7.
                                    Anscheinend hast du kein Speicherverzeichnis definiert und somit wurde bislang kein Standardverzeichnis gesetzt.
                                    Ich hatte bei mir immer ein Speicherverzeichnis gesetzt.
                                    Wurde mit v1.0.7 behoben.

                                    1 Reply Last reply Reply Quote 1
                                    • M
                                      Matt77CHE last edited by

                                      Im Log steht nur

                                      2024-10-16 18:10:59.887	error	script.js.common.Alte_history_dp_löschen: Fehler beim Lesen des Verzeichnisses: Error: ENOENT: no such file or directory, scandir ''
                                      

                                      von history steht nichts

                                      Screenshot 2024-10-16 180606.jpg

                                      Screenshot 2024-10-16 180728.jpg

                                      M 1 Reply Last reply Reply Quote 0
                                      • M
                                        MCU @Matt77CHE last edited by

                                        @matt77che Ja wie vermutet, kein Speicherverzeichnis gesetzt. Das sollte jetzt mit v1.0.7 funktionieren.

                                        M 1 Reply Last reply Reply Quote 0
                                        • M
                                          Matt77CHE @MCU last edited by

                                          @mcu
                                          Ja, jetzt läuft es ohne Fehler durch!

                                          Vielen Dank! - auch an @Homoran !

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post

                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate
                                          FAQ Cloud / IOT
                                          HowTo: Node.js-Update
                                          HowTo: Backup/Restore
                                          Downloads
                                          BLOG

                                          678
                                          Online

                                          31.6k
                                          Users

                                          79.5k
                                          Topics

                                          1.3m
                                          Posts

                                          7
                                          148
                                          7343
                                          Loading More Posts
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                          The ioBroker Community 2014-2023
                                          logo