Tässä olisi kolmen skriptin kokonaisuus, jossa ensimmäinen skripti on varsinainen "äly". Keskimmäinen skripti on paniikkinappi jos on hirmuhinnat. Ja kolmas skripti valvoo että paniikkinappi pyörii. Ja paniikkinappi taas pitää ensimmäisen käynnissä.
EDIT: Skriptit on nyt testatty Shelly Plus 1 releessä ja tuntuvat toimivilta.
SKRIPTI 1: PÖRSSIHINTAHAKU
********************************
let CONFIG = { Paivitystaajuus: 2 * 60000, }; // kaksi minuuttia
function Ohjaus(){
Shelly.call("HTTP.GET", { url: "
https://api.spot-hinta.fi/JustNowRank/6/3"},
function (res, error_code, error_msg, ud)
{
if (res.code === 200){
Shelly.call("Switch.Set","{ id:0, on:true}", null,null); // Rele päälle. Huom! id:0 on rele. Jos useampi rele niin Id:1..3.
}
else if (res.code === 400) {
Shelly.call("Switch.Set","{ id:0, on:false}", null,null); // Rele pois päältä
}
else {
Shelly.call("Switch.Set","{ id:0, on:false}", null,null); // Virhetilanne. Mitä tehdään?
};
}, null);
}
Timer.set(CONFIG.Paivitystaajuus, true, function (ud) { Ohjaus(); }, null);
SKRIPTI 2: PANIIKKINAPPI karmeiden hintojen varalta
********************************************************
let CONFIG = { Paivitystaajuus: 2 * 60000, }; // kaksi minuuttia
function Ohjaus(){
Shelly.call("HTTP.GET", { url: "
https://api.spot-hinta.fi/JustNow/30"},
function (res, error_code, error_msg, ud)
{
if (res.code === 200){
Shelly.call("Script.Start", { id:"1"}, null, null); // Käynnistä pörssihinta-skripti.
}
else if (res.code === 400) {
Shelly.call("Script.Stop", { id:"1"}, null, null); // Pysäytä pörssihinta-skripti.
Shelly.call("Switch.Set","{ id:0, on:false}", null,null); // Suljetaan rele
}
else {
Shelly.call("Switch.Set","{ id:0, on:true}", null,null); // Virhetilanne. Mitä tehdään?
};
}, null);
}
Timer.set(CONFIG.Paivitystaajuus, true, function (ud) { Ohjaus(); }, null);
SKRIPTI 3: VALVO ETTÄ PANIIKKINAPPI toimii
************************************************
let CONFIG = {
Paivitystaajuus: 1 * 60000,
};
function Valvonta(){
Shelly.call("Script.GetStatus", { id:"2"},
function (res, error_code, error_msg, ud)
{
if (res.running === true){
print("Scripti toimii");
}
else {
print("Scripti EI toimi");
Shelly.call("Script.Start", { id:"2"}, null, null);
};
},
null); }
Timer.set(
CONFIG.Paivitystaajuus,
true,
function (ud) {
Valvonta();
},
null
);