@micklafisch Hallo Ja bei mir läuft es wieder.
Skript
/* FritzBox Presence Check
* created by Nickel - based on Network Status from Machinima
*
* Vorraussetztungen
* - Material Design Widgets
* - fb-checkpresence
*
* Versionshistorie:
* 1.0.0:
* - Initial Release
*/
// Skript Einstellungen *************************************************************************************************************************************************
let dpList = '0_userdata.0.vis.NetzwerkStatus.jsonList'; // Datenpunkt für IconList Widget (Typ: Zeichenkette (String))
let dpSortMode = '0_userdata.0.vis.NetzwerkStatus.sortMode'; // Datenpunkt für Sortieren (Typ: Zeichenkette (String))
let dpFilterMode = '0_userdata.0.vis.NetzwerkStatus.filterMode'; // Datenpunkt für Filter (Typ: Zeichenkette (String))
const checkInterval = 30; // Interval wie oft Status der Skripte aktualisiert werden soll (in Sekunden)
let defaultImage1 = 'ip-network-outline'
let defaultImage2 = 'wifi';
let defaultImage3 = 'network-off-outline';
let imagePath = '/vis.0/icons-TAR/Netzwerk/' // Pfad zu den verwendeten Bildern (bitte über den VIS Dateimanager hochladen)
// Das Bild (Dateiformat png) in der Mapping-Liste hinterlegen
let farbeGeraetOnline = 'green'; // Status Bar Farbe wenn Geräte online ist
let farbeGeraetOffline = 'FireBrick'; // Status Bar Farbe wenn Geräte offline ist
let sortResetAfter = 120; // Sortierung nach X Sekunden auf sortReset zurücksetzen (0=deaktiviert)
let sortReset = 'ipAddress' // Sortierung auf die zurückgesetzt werden soll
let filterResetAfter = 120; // Filter nach X Sekunden zurücksetzen (0=deaktiviert)
const deviceNames =
[
{ ip: "", alias: "Powerline 1220E", image: "1220E.png", link: "" },
{ ip: "192.168.178.1", alias: "FritzBox", image: "fritzbox_7590.png", link: "http://192.168.178.1" },
{ ip: "192.168.178.21", alias: "Dell_Latitude", image: "4zu3_Dell_Latitude_14_5414.png", link: "" },
{ ip: "192.168.178.24", alias: "reMarkable", image: "remarkablepng.png", link: "" },
{ ip: "192.168.178.27", alias: "Acces_Point", image: "hmip-access-point-l-os_140887-d2d2310e.png", link: "" },
{ ip: "192.168.178.28", alias: "CCU3", image: "ccu3-v_1.png", link: "http://192.168.178.28" },
{ ip: "192.168.178.29", alias: "Raspberry_PI4", image: "RASP_PI_4_B_01_ANW.png", link: "http://192.168.178.29:8082" },
{ ip: "192.168.178.50", alias: "Tobi_S21", image: "samsung-galaxy-s21-5g.png", link: "" },
{ ip: "192.168.178.51", alias: "Tobi_IPhone", image: "png-transparent-iphone-6.png", link: "" },
{ ip: "192.168.178.52", alias: "Franca_A51", image: "A51.jpg", link: "" },
{ ip: "192.168.178.59", alias: "Fire_TAB", image: "Amazon_Fire_HD_10_Alexa_03_screen.png", link: "" },
{ ip: "192.168.178.141", alias: "DENON X4000", image: "AVR-X4000.png", link: "http://192.168.178.141" },
{ ip: "192.168.178.143", alias: "TV Schlafzimmer", image: "Samsung_TV.png", link: "http://192.168.178.143" },
{ ip: "192.168.178.144", alias: "TV Wohnzimmer", image: "Samsung_TV.png", link: "http://192.168.178.144" },
{ ip: "192.168.178.151", alias: "Server DS916+ Lan1", image: "DS916+.jpg", link: "http://192.168.178.151" },
{ ip: "192.168.178.152", alias: "Server DS916+ Lan2", image: "DS916+.jpg", link: "http://192.168.178.152" },
{ ip: "192.168.178.204", alias: "Powerline 1260E Schlafzimmer", image: "1260E.png", link: "http://192.168.178.204" },
{ ip: "192.168.178.205", alias: "Powerline 1260E Keller", image: "1260E.png", link: "http://192.168.178.205" },
{ ip: "192.168.178.206", alias: "Fritz Repeater", image: "2400.png", link: "http://192.168.178.206" },
{ ip: "192.168.178.209", alias: "Philips-hue", image: "PHILIPS-51180000-Hue--Bridge--3-Watt.png", link: "http://192.168.178.209" },
];
// **********************************************************************************************************************************************************************
// Selector für LAN & WLAN Devices
let devices = $(`[id=fb-checkpresence.*.fb-devices.*.active]`);
// Funktion adapterStatus alle x Sekunden ausführen
schedule('*/' + checkInterval + ' * * * * *', netzwerkStatus);
// auf Änderungen der Sortieung hören
on({ id: dpSortMode, change: 'any' }, netzwerkStatus);
on({ id: dpSortMode, change: 'any' }, resetSort);
// // auf Änderungen der Filter hören
on({ id: dpFilterMode, change: 'any' }, netzwerkStatus);
on({ id: dpFilterMode, change: 'any' }, resetFilter);
// Hauptfunktion
function netzwerkStatus() {
try {
let deviceList = [];
for (var i = 0; i <= devices.length - 1; i++) {
let idDevice = devices[i].replace('.active', '');
let isConn = ((getState(devices[i]).val) == '1') ? true : false;
let ipAddress = getStateIfExist(idDevice + ".ipaddress", '-');
let mac = getStateIfExist(idDevice + ".macaddress");
let name = idDevice.replace(/fb-checkpresence\.[0-9]\.fb-devices\./i, "");
let nameGAST = idDevice.replace(/fb-checkpresence\.[0-9]\.fb-devices\./i, "");
let connection = getStateIfExist(idDevice + '.interfacetype', '-');
let speed = getStateIfExist(idDevice + '.speed', '0');
speed = (speed == "0") ? '-' : speed + ' MBit/s';
let isGuest = getState(idDevice + ".guest").val;
let isWired = true;
let listType = 'text';
let image = defaultImage3;
let buttonLink = '';
let statusBarColor = farbeGeraetOffline;
if (isConn === true) {
statusBarColor = farbeGeraetOnline;
image = defaultImage1
}
if (connection == "802.11") {
connection = "Wireless-Lan";
image = defaultImage2;
isWired = false;
}
let device = deviceNames.find(element => element.ip == ipAddress);
if (device) {
name = device.alias;
image = imagePath + device.image;
if (device.link) {
listType = 'buttonLink';
name = `<span style="text-decoration: underline">${name}</span>`
buttonLink = (device.link == 'http') ? 'http://${ipAddress}' : device.link
}
}
let text = name;
if (isGuest === true) {
text = `<span style="color: #ff9800;">${nameGAST} "GAST"</span>`
}
let subText = `<div style="display: flex; flex-direction: row; line-height: 1.3; padding-left: 1px; padding-right: 8px; align-items: center;">
<div style="flex: 1; width: 1px; text-overflow: ellipsis; overflow: hidden;">IP-Addresse</div>
<div style="color: grey; font-size: 14px; font-family: RobotoCondensed-LightItalic; text-align: right;">${ipAddress}</div>
</div>
<div style="display: flex; flex-direction: row; line-height: 1.3; padding-left: 1px; padding-right: 8px; align-items: center;">
<div style="flex: 1; width: 1px; text-overflow: ellipsis; overflow: hidden;">Verbindung</div>
<div style="color: grey; font-size: 14px; font-family: RobotoCondensed-LightItalic; text-align: right;">${connection}</div>
</div><div style="display: flex; flex-direction: row; line-height: 1.3; padding-left: 1px; padding-right: 8px; align-items: center;">
<div style="flex: 1; width: 1px; text-overflow: ellipsis; overflow: hidden;">Geschwindigkeit</div>
<div style="color: grey; font-size: 14px; font-family: RobotoCondensed-LightItalic; text-align: right;">${speed}</div>
</div>`
deviceList.push({
text: text,
subText: subText,
listType: listType,
buttonLink: buttonLink,
image: image,
statusBarColor: statusBarColor,
name: name,
ipAddress: ipAddress,
speed: parseFloat(getStateIfExist(idDevice + '.speed', '0')),
status: isConn,
isWired: isWired
});
}
let sortMode = existsState(dpSortMode) ? getState(dpSortMode).val : 'ipAddress';
if (sortMode === 'name') {
deviceList.sort(function (a, b) {
return a[sortMode].toLowerCase() == b[sortMode].toLowerCase() ? 0 : +(a[sortMode].toLowerCase() > b[sortMode].toLowerCase()) || -1;
});
} else if (sortMode === 'ipAddress') {
deviceList.sort(function (a, b) {
return a[sortMode].split('.')[0] - b[sortMode].split('.')[0] || a[sortMode].split('.')[1] - b[sortMode].split('.')[1] || a[sortMode].split('.')[2] - b[sortMode].split('.')[2] || a[sortMode].split('.')[3] - b[sortMode].split('.')[3]
});
} else if (sortMode === 'status' || sortMode === 'speed') {
deviceList.sort(function (a, b) {
return a[sortMode] == b[sortMode] ? 0 : +(a[sortMode] < b[sortMode]) || -1;
});
} else {
// default: nach name sortieren
sortMode = 'name'
deviceList.sort(function (a, b) {
return a[sortMode].toLowerCase() == b[sortMode].toLowerCase() ? 0 : +(a[sortMode].toLowerCase() > b[sortMode].toLowerCase()) || -1;
});
}
let filterMode = existsState(dpFilterMode) ? getState(dpFilterMode).val : '';
if (filterMode && filterMode !== null && filterMode !== '') {
if (filterMode === 'offline') {
deviceList = deviceList.filter(function (item) {
return item.status === false;
});
} else if (filterMode === 'online') {
deviceList = deviceList.filter(function (item) {
return item.status === true;
});
}
}
let result = JSON.stringify(deviceList);
if (existsState(dpList) && getState(dpList).val !== result) {
setState(dpList, result, true);
} else {
setState(dpList, result, true);
}
} catch (err) {
console.error(`[netzwerkStatus] error: ${err.message}, stack: ${err.stack}`);
}
// Funktionen
function getStateIfExist(id, nullValue = '', prepand = '', append = '') {
if (existsState(id)) {
return prepand + getState(id).val + append;
} else {
return nullValue;
}
}
}
// Beim Staren des Skriptes Status abrufen
netzwerkStatus();
function resetSort() {
let sortMode = existsState(dpSortMode) ? getState(dpSortMode).val : '';
if (sortResetAfter > 0) {
setTimeout(function () {
if (existsState(dpSortMode) && sortMode === getState(dpSortMode).val) {
setState(dpSortMode, sortReset);
}
}, sortResetAfter * 1000);
}
}
function resetFilter() {
let filterMode = existsState(dpFilterMode) ? getState(dpFilterMode).val : '';
if (filterResetAfter > 0) {
setTimeout(function () {
if (existsState(dpFilterMode) && filterMode === getState(dpFilterMode).val) {
setState(dpFilterMode, '');
}
}, filterResetAfter * 1000);
}
}