NEWS

Probleme mit Script nach js-controller Update [gelöst]

  • Starter

    Hallo,

    nach dem Update von JS-Controller habe ich bei dem Script Adapter-infos folgedes Problem:

    Im Log-File kommt 4 mal folgende Zeile:

    javascript.0	2020-05-30 14:59:25.403	error	(920) script.js.Allgemein.adapter_infos: setForeignState: undefined is not a valid state value
    javascript.0	2020-05-30 14:59:25.403	error	(920) script.js.Allgemein.adapter_infos: setForeignState: undefined is not a valid state value
    javascript.0	2020-05-30 14:59:25.399	error	(920) script.js.Allgemein.adapter_infos: setForeignState: undefined is not a valid state value
    javascript.0	2020-05-30 14:59:25.398	error	(920) script.js.Allgemein.adapter_infos: setForeignState: undefined is not a valid state value
    

    Kann mir da jemand weiter helfen?

    Hier das Script

    // Liest die ioBroker Adapter aus und legt verschiedenen State's an.
    
    //on({id:"system.adapter.admin.0.uptime",change:'any'}, function (obj) {
    on({id:"system.adapter.admin.0.uptime",change:'any'}, function (obj) {
        createState('Adapter.Anzahl', 0, { name: 'Anzahl', desc: 'Anzahl der Adapter', type: 'number', unit: '', min: '0', max: '255', role: '',read: true, write: true });
        createState('Adapter.AdapterNummer', 0, { name: 'Adapter zum schalten', desc: 'Adapter zum schalten', type: 'number', unit: '', min: '0', max: '255', role: '',read: true, write: true });    
        //var counterAlt = getState("javascript.0.Adapter.Anzahl").val;
        var counter =0;
    	var on = 0
    	var manuell=0	
    
        var cacheSelector = $('[id=system.adapter.*.alive]');    
        cacheSelector.each(function(id, i) {        
            var devicename = getObject(id).common.name; 
    		
    		//Instanzen ausklammern
    		instanz0 = devicename.indexOf('daswetter');
    		instanz1 = devicename.indexOf('dwd');
            instanz2 = devicename.indexOf('ical');
    		instanz3 = devicename.indexOf('feiertage');
    		instanz4 = devicename.indexOf('snmp');
            instanz5 = devicename.indexOf('synology');
            instanz6 = devicename.indexOf('vis');
    		if(instanz0 !=0 && instanz1 != 0 && instanz2 !=0 && instanz3 != 0 && instanz4 != 0 && instanz5 !=0 && instanz6 != 0){
    		
    			var devicenameName=devicename;
    			var instanzname=getObject(id).common.name;
    			var test = devicenameName;
    			var devicename_array = devicenameName.split(' ');        
    			devicenameName = devicename_array[0];
    			counter = counter+1; 
    				
    			var strStatePath = "system.adapter." + devicenameName + ".alive";
    			if (isState(strStatePath, true)) {
    				var uptime = getState("system.adapter." + devicenameName + ".uptime").val;
    				var tage = Math.floor(uptime / (24*3600));
    				var stunden = Math.floor((uptime % (24*3600))/3600);
    				var minuten = Math.floor((uptime % (3600))/60);
    				//var sekunden = Math.floor(uptime % 60);      
    				if (stunden < 10) {stunden = "0"+stunden};
                    if (minuten < 10) {minuten = "0"+minuten};				
    				if (tage == 1) {uptime = tage.toString()+" Tag, "+stunden.toString()+" Std, "+minuten.toString()+" Min ";};
    				if (tage != 1) {uptime = tage.toString()+" Tage, "+stunden.toString()+" Std, "+minuten.toString()+" Min ";}
    				//var total = getState("system.adapter." + devicenameName + ".memHeapTotal").val;
    				//var used = getState("system.adapter." + devicenameName + ".memHeapUsed").val;
    				//var rss = getState("system.adapter." + devicenameName + ".memRss").val;
    				var connect = getState("system.adapter." + devicenameName + ".alive").val;            
    
    				if(connect == false){var con = 0;}
    				else {                
    					var con = 1;
    					var strStatePath = devicenameName + ".info.connection";
    					if (isState(strStatePath, true)) {
    						var connectS = getState(devicenameName + ".info.connection").val;
    						if (connectS == false) {
    							con = 2;
    						}                                                                        
    					} 
    				}
    				if(con==1) {on = on + 1}
    									  
    			}       
    			
    			devicename="Adapter.Adapter"+counter.toString()+".KompletterNameAdapter";
    			createState(devicename, 'empty', { name: 'Kompletter Name des Adapters', desc: '', type: 'string', role: '',read: true, write: true }); 
    			setStateDelayed(devicename, devicenameName, 800);
    			
    			var contentstring = devicenameName;
    			var suchstring = /(ical)/g; 
    			var suchergebnis = suchstring.test( contentstring );
    			
    			if (suchergebnis != true) {
    				var devicename_array = devicenameName.split('.');        
    				devicenameName = devicename_array[0];
    			}    
    
    			if (devicenameName == "daswetter") {
    				var bild = "/" + devicenameName + ".admin/" + devicenameName + "com.png";
    			} else if (suchergebnis != false) {
    				var devicename_array = devicenameName.split('.');        
    				var icalName = devicename_array[0];        
    				var bild = "/" + icalName + ".admin/" + icalName + ".png";
    			} else {
    				var bild = "/" + devicenameName + ".admin/" + devicenameName + ".png";
    			}
    			
    			//Alexa2
    			if (devicenameName == 'alexa2') {var bild = "/" + devicenameName + ".admin/" + "alexa.png";}
    			//FritzDECT
    			if (devicenameName == 'fritzdect') {var bild = "/" + devicenameName + ".admin/" + "fritzdect_logo.png";}
    			//HM-Rega
    			//if (devicenameName == 'hm-rega') {var bild = "/" + devicenameName + ".admin/" + "homematic.png";}
    			if (devicenameName == 'hm-rega') {var bild = "/vis.0/VIS/Meine_Icons/Adapter_Icons/homematic.gif";}
    			//HomeMatic
    			//if (instanzname == 'hm-rpc.0 alive') {var bild = "/" + devicenameName + ".admin/" + "homematic.png";}
    			if (instanzname == 'hm-rpc.0 alive') {var bild = "/vis.0/VIS/Meine_Icons/Adapter_Icons/homematic.gif";}
    			//HomeMatic-IP
    			//if (instanzname == 'hm-rpc.1 alive') {var bild = "/" + devicenameName + ".admin/" + "homematic.png";}
    			if (instanzname == 'hm-rpc.1 alive') {var bild = "/vis.0/VIS/Meine_Icons/Adapter_Icons/homematic_ip.jpg";}
    			//UPNP
    			if (devicenameName == 'upnp') {var bild = "/" + devicenameName + ".admin/" + "upnp-discovery.png";}
                //Pushover.1
    			if (instanzname == 'pushover.1 alive') {var bild = "/mihome-vacuum.admin/mihome-vacuum.png";}
                //Pushover.2
    			if (instanzname == 'pushover.2 alive') {var bild = "/daswetter.admin/daswettercom.png";}
    			
    			//AdapterName anpassen
    			
    			//DasWetter
    			if (instanzname == 'daswetter.0 alive') {devicenameName='DasWetter'; manuell=1}
    			//DWD
    			if (instanzname == 'dwd.0 alive') {devicenameName='DWD'; manuell=1}
    			//HM-REGA
    			if (instanzname == 'hm-rega.0 alive') {devicenameName='HM-Rega'; manuell=1}			
    			//HM-RPC.0
    			if (instanzname == 'hm-rpc.0 alive') {devicenameName='HomeMatic'; manuell=1}
    			//HM-RPC.1
    			if (instanzname == 'hm-rpc.1 alive') {devicenameName='HM-IP'; manuell=1}
    			//Pushover
    			if (instanzname == 'pushover.0 alive') {devicenameName='Pushover.0'; manuell=1}
    			//Simple-API
    			if (instanzname == 'simple-api.0 alive') {devicenameName='Simple-API'; manuell=1}
    			//SNMP.0
    			if (instanzname == 'snmp.0 alive') {devicenameName='SNMP.0'; manuell=1}
    			//SNMP.1
    			if (instanzname == 'snmp.1 alive') {devicenameName='SNMP.1'; manuell=1}
    			//TR-064.0
    			if (instanzname == 'tr-064.0 alive') {devicenameName='TR-064.0'; manuell=1}
    						
    			
    			
    			//Instanz-Namen setzen
    			if(manuell!=1) {devicenameName = devicenameName.substring(0, 1).toUpperCase() + devicenameName.substring(1).toLowerCase();}	
                //devicenameName = devicenameName.substring(0, 1).toUpperCase() + devicenameName.substring(1).toLowerCase();
    			devicename="Adapter.Adapter"+counter.toString()+".NameInstanz";
    			createState(devicename, 'empty', { name: 'Name des Geräts', desc: '', type: 'string', role: '',read: true, write: true }); 
    			setStateDelayed(devicename, devicenameName, 800);
    			//Bild Pfad setzen
    			devicename="Adapter.Adapter"+counter.toString()+".Bild";
    			createState(devicename, 'empty', { name: 'Speicherort Bild', desc: '', type: 'string', role: '',read: true, write: true });
    			setStateDelayed(devicename, bild, 800);
    			//Uptime setzen
    			devicename="Adapter.Adapter"+counter.toString()+".Uptime";          
    			createState(devicename, 'empty', { name: 'Uptime', desc: '', type: 'string', role: '',read: true, write: true });
    			setStateDelayed(devicename, uptime, 800);
    			//MemUsed setzen
    			//devicename="Adapter.Adapter"+counter.toString()+".MemUsed";          
    			//createState(devicename, 0, { name: 'Link MemUsed', desc: '', type: 'number', role: '',read: true, write: true });
    			//setStateDelayed(devicename, used, 800);
    			//MemToal setzen
    			//devicename="Adapter.Adapter"+counter.toString()+".MemTotal";          
    			//createState(devicename, 0, { name: 'Link MemTotal', desc: '', type: 'number', role: '',read: true, write: true });
    			//setStateDelayed(devicename, total, 800);
    			//MemRSS setzen
    			//devicename="Adapter.Adapter"+counter.toString()+".MemRSS";          
    			//createState(devicename, 0, { name: 'Link MemRSS', desc: '', type: 'number', role: '',read: true, write: true });
    			//setStateDelayed(devicename, rss, 800);
    			//Connected setzen
    			devicename="Adapter.Adapter"+counter.toString()+".Connected";          
    			createState(devicename, 0, { name: 'Status Adapter', desc: '', type: 'number', role: '',read: true, write: true });
    			setStateDelayed(devicename, con, 800);
    			
                //Wert zurücksetzen
                var manuell=0
    		}
        });
        
    	//Adaptet Icon Übersicht
        visstatus="javascript.0.VIS-Status.alle_adapter_gestartet";
        if(on == counter){setState(visstatus, true);}
        if(on == counter -1){setState(visstatus, true);}
        if(on < counter -1){setState(visstatus, false);}
    	
    	
        setStateDelayed('Adapter.Anzahl', counter, 800);
    
        function isState(strStatePath, strict) {
            let mSelector;
            if (strict) {
                mSelector = $('state[id=' + strStatePath + '$]');
            } else {
                mSelector = $('state[id=' + strStatePath + ']');
            }
            if (mSelector.length > 0) {
                return true;
            } else {
                return false;
            }
        }  
    }); 
    
    on({id:"javascript.0.Adapter.AdapterNummer", change: 'any'}, function (dpobj) {
        if (getState("javascript.0.Adapter.AdapterNummer").val != 0) {        
            const instanz = "javascript." + instance;
            var adapterNummer = getState(instanz + ".Adapter.AdapterNummer").val;
            var adapter = getState(instanz + ".Adapter.Adapter" + adapterNummer + ".KompletterNameAdapter").val; // Name und Instanz des Adapters 
            var idAdapter = "system.adapter." + adapter;
            
            var obj = getObject(idAdapter);
            if (dpobj.state.val == false) {
                obj.common.enabled = true;  // Adapter einschalten
            } else if (dpobj.state.val == true) {
                obj.common.enabled = false;  // Adapter ausschalten
            }
            setObject(idAdapter, obj);
            setStateDelayed('javascript.0.Adapter.AdapterNummer', 0, 800);        
        }
    });   ```

Suggested Topics

2.2k
Online

35.1k
Users

41.1k
Topics

565.1k
Posts