//schedule('*/10 * * * * *', function (obj) {
schedule('* * * * *', function (obj) {
createState('Sonoff-Devices.Anzahl', 0, { name: 'Anzahl', desc: 'Anzahl der Devices', type: 'number', unit: '', min: '0', max: '255', role: '',read: true, write: true });
var counter =0;
var cacheSelector = $('[id=sonoff.0.*.INFO.Hostname]');
counter = counter+1;
cacheSelector.each(function(id, i) {
var devicename = getObject(id).common.name;
var devicenameName=devicename;
var devicename_array = devicenameName.split(' ');
devicenameName = devicename_array[0];
//Gerätetatus
var connected_devices = getState("sonoff.0.info.connection").val;
if(connected_devices.includes(devicenameName)){var status = true}
else{var status = false}
//Infos abfragen
if(status == true ) {
var status = "1"
//Version
var version = getState("sonoff.0." + devicenameName + ".INFO" + ".Version").val;
if(version.indexOf("(sonoff)")){var version = version.replace("(sonoff)", "")}
if(version.indexOf("(tasmota)")){var version = version.replace("(tasmota)", "")}
// Version als INT für den Vergleich
var version_1 = parseInt(version)
//Uptime aus dem DP UptimeSec (ab Tasmota 7.x)
if(version_1 > 6) {
var uptime = getState("sonoff.0." + devicenameName + ".UptimeSec").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 ";}
}
//Uptime für Gartenbewässerung (Tasmota 6)
if(devicenameName == "Bewaesserung") {uptime = getState("javascript.0.uptime.sonoff_bewaesserung").val;}
//IP-Adresse
var ip = getState("sonoff.0." + devicenameName + ".INFO" + ".IPAddress").val;
//Typ
var geraet = getState("sonoff.0." + devicenameName + ".INFO" + ".Module").val;
//Powerschalter für Sonoff S20 / Sonoff Basic
if(geraet == "Sonoff S2X" || geraet == "Sonoff Basic"){var powerschalter = "sonoff.0." + devicenameName + ".POWER"};
}
if(status == false){
var status = "0"
var uptime = ""
var version = ""
var ip = ""
var geraet = ""
var powerschalter = ""
}
//DPs befüllen
// Device-Name
devicename="Sonoff-Devices.Device_"+counter.toString()+".Device-Name";
createState(devicename, 'empty', { name: 'Device-Name', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, devicenameName, 800);
// Uptime
devicename="Sonoff-Devices.Device_"+counter.toString()+".Uptime";
createState(devicename, 'empty', { name: 'Uptime', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, uptime, 800);
// Status
devicename="Sonoff-Devices.Device_"+counter.toString()+".Status";
createState(devicename, 'empty', { name: 'Status', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, status, 800);
// Version
devicename="Sonoff-Devices.Device_"+counter.toString()+".Version";
createState(devicename, 'empty', { name: 'Version', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, version, 800);
// IP
devicename="Sonoff-Devices.Device_"+counter.toString()+".IP";
createState(devicename, 'empty', { name: 'IP', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, ip, 800);
// Gereatetyp
devicename="Sonoff-Devices.Device_"+counter.toString()+".Geraet";
createState(devicename, 'empty', { name: 'Geraet', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, geraet, 800);
//Powerschalter
if(geraet == "Sonoff S2X" || geraet == "Sonoff Basic") {
devicename="Sonoff-Devices.Device_"+counter.toString()+".Powerschalter";
createState(devicename, 'empty', { name: 'Powerschalter', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, powerschalter, 800);
}
counter = counter+1;
//console.log(devicenameName + " - " + uptime);
});
// Wegen sonoff.0.info muss vom Counter 1 abgezogen werden
counter = counter - 1
setStateDelayed('Sonoff-Devices.Anzahl', counter, 800);
//Letzte aktualisierung
var datum = new Date();
var heute = datum.getDate()+ "." + (datum.getMonth()+ 1)+"." + datum.getFullYear()+" " +datum.getHours() +":" + datum.getMinutes() +":" + datum.getSeconds() + " Uhr" ;
createState('Sonoff-Devices.Letztes_Update', 0, { name: 'Letztes_Update', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed('Sonoff-Devices.Letztes_Update', heute, 800);
});