VM-Tracker auf Shelly Geräten¶
go to Settings → Scripts → Add Script and create:
Change the domainname!
function registerDevice() {
// Device Info abrufen
Shelly.call("Shelly.GetDeviceInfo", {}, function(deviceInfo) {
let hostname = deviceInfo.id || "unknown-shelly"; // z.B. "shellyplus1pm-a1b2c3d4"
Shelly.call("Shelly.GetStatus", {}, function(result) {
let ip_address = null;
let interface_name = null;
if (result.eth && result.eth.ip) {
ip_address = result.eth.ip;
interface_name = "eth0";
} else if (result.wifi && result.wifi.sta_ip) {
ip_address = result.wifi.sta_ip;
interface_name = "wlan0";
}
if (!ip_address) {
print("Keine IP gefunden!");
return;
}
Shelly.call(
"HTTP.POST",
{
url: "https://vm-tracker.example.com/api/register",
content_type: "application/json",
body: JSON.stringify({
hostname: hostname,
ip_address: ip_address,
interface: interface_name
})
},
function(result, error_code, error_message) {
if (error_code === 0) {
print("✓ Registriert: ", hostname, " - ", ip_address);
} else {
print("✗ Fehler: ", error_message);
}
}
);
});
});
}
// Bei Netzwerk-Verbindung ausführen
Shelly.addEventHandler(function(event) {
if (event.component === "wifi" && event.info.status === "got ip") {
print("WiFi verbunden, registriere...");
Timer.set(2000, false, registerDevice); // 2s Verzögerung
}
if (event.component === "eth" && event.info.status === "up") {
print("Ethernet verbunden, registriere...");
Timer.set(2000, false, registerDevice);
}
});
// Zusätzlich alle 10 Minuten
Timer.set(30000, true, registerDevice);
You can simply create the script on each Shelly and they will then automatically register themselves.