/* 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 imagePath = '/vis.0/main/icons/' // Pfad zu den verwendeten Bildern (bitte über den VIS Dateimanager hochladen)
// Das Bild (Dateiformat png) in der Mapping-Liste hinterlegen
let defaultImage1 = 'ip-network-outline'; // Standardbild, Ethernet (Material Design Icons)
let defaultImage2 = 'wifi'; // Standardbild, Wifi (Material Design Icons)
let defaultImage3 = 'network-off-outline'; // Standardbild, Offline (Material Design Icons)
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 = 'name' // Sortierung auf die zurückgesetzt werden soll
let filterResetAfter = 120; // Filter nach X Sekunden zurücksetzen (0=deaktiviert)
const deviceNames =
[
{ ip: "10.0.1.3", alias: "Router-Daddy", image: "router.png", link: "10.0.1.3"}
{ ip: "10.0.1.1", alias: "FritzBox", image: "fritzbox_6590_left_de_640x400.png", link: "10.0.1.1"}
{ ip: "10.0.1.2", alias: "Router-Dina", image: "router.png", link: "10.0.1.2"}
{ ip: "10.0.1.5", alias: "Repeater-Gang-EG", image: "router.png", link: "10.0.1.5"}
{ ip: "10.0.1.14", alias: "Drucker-Color-LaserJet-Max", image: "mfc9332cdw_main.png", link: "10.0.1.14"}
{ ip: "10.0.1.15", alias: "Drucker-Nega", image: "mfc9332cdw_main.png", link: "10.0.1.15"}
{ ip: "10.0.1.20", alias: "Synology-Nega-1", image: "ds718.png", link: "10.0.1.20"}
{ ip: "10.0.1.21", alias: "Synology-Nega-2", image: "ds718.png", link: "10.0.1.21"}
{ ip: "10.0.1.22", alias: "Synology-Nega-3-1", image: "ds718.png", link: "10.0.1.22"}
{ ip: "10.0.1.23", alias: "Synology-Nega-3-2", image: "ds718.png", link: "10.0.1.23"}
{ ip: "10.0.1.27", alias: "Laptop-Margret", image: "laptop.png", link: "http"}
{ ip: "10.0.1.31", alias: "PC-Nega", image: "Medion Akoya E 2070 D.png", link: "http"}
{ ip: "10.0.1.33", alias: "Laptop-Max", image: "laptop.png", link: "http"}
{ ip: "10.0.1.34", alias: "Receiver-Max", image: "vuplus.png", link: "10.0.1.34"}
{ ip: "10.0.1.35", alias: "Receiver-Nega", image: "vuplus.png", link: "10.0.1.35"}
{ ip: "10.0.1.36", alias: "TV-Nega", image: "LG_TV_2.png", link: "http"}
{ ip: "10.0.1.38", alias: "Denon-AVR-2113", image: "yamaha-rx-v481_klein.png", link: "10.0.1.38"}
{ ip: "10.0.1.51", alias: "Handy-Nega", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.52", alias: "Handy-Lisi", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.53", alias: "Handy-Max", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.54", alias: "Handy-Margret", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.56", alias: "Handy-Dina", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.57", alias: "Handy-Neli", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.59", alias: "Handy-Buz", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.65", alias: "Tablet-Nega", image: "tablet.png", link: "http"}
{ ip: "10.0.1.69", alias: "Philips-Hue", image: "PHILIPS-51180000-Hue--Bridge--3-Watt.png", link: "http"}
{ ip: "10.0.1.70", alias: "Harmony-Hub", image: "logitechharmony.png", link: "http"}
{ ip: "10.0.1.71", alias: "TV-Buz", image: "LG_TV_2.png", link: "http"}
{ ip: "10.0.1.73", alias: "Amazon-Echo-Schlafzimmer", image: "echo_dot3.png", link: "http"}
{ ip: "10.0.1.76", alias: "TP-LINK-Smart-Plug-Pelletsofen", image: "TPLINK_HS110_01.png", link: "http"}
{ ip: "10.0.1.77", alias: "TP-LINK-Smart-Plug-Aquarium", image: "TPLINK_HS110_01.png", link: "http"}
{ ip: "10.0.1.78", alias: "TP-LINK-Smart-Plug-Kinderzimmer", image: "TPLINK_HS110_01.png", link: "http"}
{ ip: "10.0.1.79", alias: "TP-LINK-Smart-Plug-PC", image: "TPLINK_HS110_01.png", link: "http"}
{ ip: "10.0.1.80", alias: "TP-LINK-Smart-Plug-Serverschrank", image: "TPLINK_HS110_01.png", link: "http"}
{ ip: "10.0.1.81", alias: "Xiaomi-Mijia-Gateway-1", image: "Xiaomi-Mijia-Gateway.png", link: "http"}
{ ip: "10.0.1.83", alias: "XboxOneS", image: "XboxOneS.png", link: "http"}
{ ip: "10.0.1.84", alias: "Doorbird", image: "Doorbird.png", link: "http"}
{ ip: "10.0.1.85", alias: "Handy-Laura", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.87", alias: "Amazon-Echo-Küche", image: "echo_dot3.png", link: "http"}
{ ip: "10.0.1.88", alias: "Amazon-Echo-Kinderzimmer", image: "echo_dot3.png", link: "http"}
{ ip: "10.0.1.89", alias: "Amazon-Echo-Wohnzimmer", image: "echostudio.png", link: "http"}
{ ip: "10.0.1.90", alias: "Photovoltaik-Max", image: "Photovoltaik.png", link: "10.0.1.90"}
{ ip: "10.0.1.93", alias: "Volkszähler", image: "Raspberry_Pi_3_Model_B.png", link: "10.0.1.93"}
{ ip: "10.0.1.94", alias: "Photovoltaik-Buz-1-1", image: "Photovoltaik.png", link: "10.0.1.94"}
{ ip: "10.0.1.95", alias: "Photovoltaik-Buz-2-1", image: "Photovoltaik.png", link: "10.0.1.95"}
{ ip: "10.0.1.97", alias: "CCU3", image: "ccu3-v_1.png", link: "10.0.1.97"}
{ ip: "10.0.1.100", alias: "TV-Max", image: "LG_TV_2.png", link: "http"}
{ ip: "10.0.1.101", alias: "LAN-Switch-Buero-Max", image: "TP-Link TL-SG105E.png", link: "10.0.1.101"}
{ ip: "10.0.1.112", alias: "Photovoltaik-Akku-Buz", image: "fronius-Akku.png", link: "10.0.1.112"}
{ ip: "10.0.1.150", alias: "DietPi", image: "DietPi.png", link: "10.0.1.150"}
{ ip: "10.0.1.167", alias: "Froggit-WS4000", image: "Froggit-WS4000.png", link: "http"}
{ ip: "10.0.1.200", alias: "ioBroker-Admin", image: "ioBroker-Admin.png", link: "10.0.1.200"}
{ ip: "10.0.1.4", alias: "Router-Nega-Wohnzimmer", image: "router.png", link: "10.0.1.4"}
{ ip: "10.0.1.12", alias: "Drucker-Dina", image: "mfc9332cdw_main.png", link: "10.0.1.12"}
{ ip: "10.0.1.30", alias: "Laptop-Lisi", image: "laptop.png", link: "http"}
{ ip: "10.0.1.37", alias: "Laptop-Dina", image: "laptop.png", link: "http"}
{ ip: "10.0.1.39", alias: "Receiver-Nega-Schlafzimmer", image: "vuplus.png", link: "10.0.1.39"}
{ ip: "10.0.1.55", alias: "Handy-Emely", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.58", alias: "Handy-Kloane", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.60", alias: "Handy-Marcel", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.61", alias: "Handy-Tamara", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.62", alias: "Tablet-Buz", image: "tablet.png", link: "http"}
{ ip: "10.0.1.63", alias: "Laptop-Neli", image: "laptop.png", link: "http"}
{ ip: "10.0.1.64", alias: "Powerline-Nega", image: "Powerline.png", link: "10.0.1.64"}
{ ip: "10.0.1.67", alias: "Laptop-Nega", image: "laptop.png", link: "http"}
{ ip: "10.0.1.68", alias: "Tablet-Laura", image: "tablet.png", link: "http"}
{ ip: "10.0.1.72", alias: "LED-Controller-Aquarium", image: "sunriser8.png", link: "10.0.1.72"}
{ ip: "10.0.1.82", alias: "Xiaomi-Mijia-Gateway-2", image: "Xiaomi-Mijia-Gateway.png", link: "http"}
{ ip: "10.0.1.86", alias: "Laptop-Emely", image: "laptop.png", link: "http"}
{ ip: "10.0.1.91", alias: "Photovoltaik-Buz-1", image: "Photovoltaik.png", link: "10.0.1.91"}
{ ip: "10.0.1.92", alias: "Photovoltaik-Buz-2", image: "Photovoltaik.png", link: "10.0.1.92"}
{ ip: "10.0.1.98", alias: "Instar-3011", image: "Instar-3011.png", link: "10.0.1.98"}
{ ip: "10.0.1.151", alias: "PC-Marcel", image: "Medion Akoya E 2070 D.png", link: "http"}
{ ip: "10.0.1.152", alias: "Handy-Ramon", image: "Galaxy_S6.png", link: "http"}
{ ip: "10.0.1.156", alias: "Laptop-Ramon", image: "laptop.png", link: "http"}
{ ip: "10.0.1.161", alias: "Tablet-Lisi", image: "tablet.png", link: "http"}
{ ip: "10.0.1.165", alias: "Handy-Kloane-Arbeit", image: "Galaxy_S6.png", link: "http"}
];
// **********************************************************************************************************************************************************************
// 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 = (getStateIfExist(devices[i]) == '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 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 = (connection == "802.11") ? defaultImage2 : defaultImage1
}
if (connection == "802.11") {
connection = "Wireless-Lan";
isWired = false;
}
let device = deviceNames.find(element => element.ip == ipAddress);
if (device) {
name = device.alias;
if (device.image.search("png") > 0) {
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 class="mdi mdi-account-box" style="color: #ff9800;"> ${name}</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);
}
}