shelly:skriptid
Shelly Gen2 BLE Gateway Script for BLU Button1 Integration
Gemini tehtud script 15 lülitus
// SEADISTUSED
let config = {
// Hind, millest ODAVAMAL juhul lülitatakse relee SISSE (senti/kWh koos KM-ga)
minPrice: 5.0,
// Hind, millest KALLIMAL juhul lülitatakse relee VÄLJA (senti/kWh koos KM-ga)
maxPrice: 20.0,
// Shelly relee number (tavaliselt 0)
relayId: 0,
// Käibemaks (1.22 tähendab 22%) - Elering annab hinna ilma käibemaksuta
vat: 1.22,
// Kui tihti kontrollida hinda (millisekundites). 15 min = 900000
interval: 900000
};
// Eleringi API URL (praegune hind)
let url = "https://dashboard.elering.ee/api/nps/price/EE/current";
function checkPriceAndSwitch() {
Shelly.call("HTTP.GET", { url: url }, function (response, error_code, error_message) {
if (error_code !== 0) {
print("Viga andmete saamisel Eleringist!");
return;
}
let json = JSON.parse(response.body);
if (json.success && json.data && json.data.length > 0) {
// Elering annab hinna EUR/MWh, teisendame senti/kWh ja lisame käibemaksu
let rawPrice = json.data[0].price; // EUR/MWh
let finalPrice = (rawPrice / 10) * config.vat; // senti/kWh koos KM
print("Praegune börsihind: " + finalPrice.toFixed(2) + " senti/kWh");
// Loogika lülitamiseks
if (finalPrice <= config.minPrice) {
print("Hind on odav. Lülitan relee SISSE.");
Shelly.call("Switch.Set", { id: config.relayId, on: true });
}
else if (finalPrice >= config.maxPrice) {
print("Hind on kallis. Lülitan relee VÄLJA.");
Shelly.call("Switch.Set", { id: config.relayId, on: false });
}
else {
print("Hind on vahemikus (" + config.minPrice + " - " + config.maxPrice + "). Olekut ei muudeta.");
Shelly.call("Switch.Set", { id: config.relayId, on: true });
}
} else {
print("Viga andmete lugemisel vastusest.");
}
});
}
// Käivita kohe skripti startimisel
checkPriceAndSwitch();
// Käivita taimer iga 15 minuti järel
Timer.set(config.interval, true, function () {
checkPriceAndSwitch();
});
shelly/skriptid.txt · Viimati muutnud: persoon sa
