Skip to content

Commit

Permalink
Merge pull request #64 from Spot-hinta-fi/multi-relay-quick-code
Browse files Browse the repository at this point in the history
New version of "Shelly-pikakoodi.js" script. It now supports multiple relays with different quick codes. Also updated comment about supported Shelly firmwares. Added 1.2.0.
  • Loading branch information
Spot-hinta-fi authored Feb 17, 2024
2 parents 90afefa + 8cbdddb commit 57ecd53
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Scripts/Shelly-Minimal-Heating.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Thank you for your support: https://www.buymeacoffee.com/spothintafi
// Supported Shelly firmwares: 1.0.3 - 1.1.0. Script version: 2024-01-21
// Supported Shelly firmwares: 1.0.3 - 1.2.0. Script version: 2024-02-17

// Change these settings as you like
let Region = "FI"; // Supported regions: DK1, DK2, EE, FI, LT, LV, NO1, NO2, NO3, NO4, NO5, SE1, SE2, SE3, SE4
Expand Down
51 changes: 22 additions & 29 deletions Scripts/Shelly-Pikakoodi.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
// Kiitos tuestasi: https://www.buymeacoffee.com/spothintafi
// Tuetut Shelly ohjelmistot: 1.0.3 - 1.1.0. Skriptin versio: 2024-01-21
// Tuetut Shelly ohjelmistot: 1.0.3 - 1.2.0. Skriptin versio: 2024-02-17

// Asetukset
let Pikakoodi = 103; // Hae sopiva pikakoodi: https://spot-hinta.fi/pikakoodit
let Releet = [0]; // Releen tai releiden numero. Arvoa ei tarvitse vaihtaa, jos Shelly on yksireleinen. Useampi rele määritellään pilkulla eroteltuna. Esim. [0,1,2]
// OHJE: Anna "pikakoodi" kullekin ohjattavalle releelle. Koodilla 999 voit ohittaa releen.
// Esimerkki 1: Ohjaa releitä 2 ja 3. Aseta pikakoodit näin: [999, 103, 125]
// Esimerkki 2: Ohjaa vain yhtä relettä. Aseta pikakoodi näin: [103]
// Hae sopivat pikakoodit täältä: https://spot-hinta.fi/pikakoodit

// Alla olevaa koodia ei tarvitse muokata. Se suorittaa kyselyn rajapintaan ja ohjaa releiden toimintaa.
// Ohjaus tapahtuu tunnoin vaihduttua noin puolen minuutin aikana. Virheen tapahtuessa rele suljetaan, eli ohjaus sallitaan.
let cHour = -1; let Executed = false; let pAction = ""; let url = "https://api.spot-hinta.fi/QuickCode/" + Pikakoodi;
print("Pikakoodi: Skripti suoritetaan...");
Timer.set(30000, true, function () {
let hour = new Date().getHours();
if (cHour !== hour) { cHour = hour; Executed = false; print("Pikakoodi: Ensiohjaus tai tunti vaihtui. Suoritetaan ohjaus.") }
if (cHour == hour && Executed == true) { print("Pikakoodi: Kuluva tunti on jo suoritettu onnistuneesti."); return; }
Shelly.call("HTTP.GET", { url: url, timeout: 15, ssl_ca: "*" }, function (result, error_code) {
if (error_code === 0 && result !== null) {
if ((result.code === 400 || result.code === 200) && pAction === result.code) { print("Releiden tila pysyy samana kuin aiemmalla tunnilla."); Executed = true; return; }
if (result.code === 400 || result.code === 200) {
print("Pikakoodi: Onnistunut vastaus palvelimelta: " + result.body);
for (let i = 0; i < Releet.length; i++) {
if (result.code === 400) { Shelly.call("Switch.Set", "{ id:" + Releet[i] + ", on:false}", null, null); pAction = result.code; print("Pikakoodi: Tunti on liian kallis. Rele " + Releet[i] + " avataan."); Executed = true; }
if (result.code === 200) { Shelly.call("Switch.Set", "{ id:" + Releet[i] + ", on:true}", null, null); pAction = result.code; print("Pikakoodi: Tunti on tarpeeksi halpa. Rele " + Releet[i] + " suljetaan."); Executed = true; }
}
return;
}
}
print("Pikakoodi: Virheellinen vastaus palvelimelta. Koodi: " + result.code + " - Vastaus: " + result.body);
for (let i = 0; i < Releet.length; i++) {
Shelly.call("Switch.Set", "{ id:" + Releet[i] + ", on:true}", null, null); print("Pikakoodi: Virhe ohjauksessa, rele " + Releet[i] + " suljetaan."); pAction = ""; Executed = false;
}
})
// PIKAKOODIT: Aseta tähän parametriin haluamasi pikakoodit
let Pikakoodit = [103];

// SKRIPTI. Älä muokkaa alla olevaa koodia
let rr = -1; let tunti = -1; let vtila = false; print("Pikakoodi: Skripti käynnistyy.");
Timer.set(15000, true, function () {
if (tunti == new Date().getHours()) { return; } else {
rr--; rr = (rr < 0) ? Pikakoodit.length - 1 : rr; if (Pikakoodit[rr] == 999) { return; }
Shelly.call("HTTP.GET", { url: "https://api.spot-hinta.fi/QuickCode/" + Pikakoodit[rr], timeout: 5, ssl_ca: "*" }, function (res, err) {
let tila = (err == 0 && res != null && res.code == 400) ? false : true;
let virhe = (err == 0 && res != null && res.code == 200 || res.code == 400) ? false : true; if (virhe) { vtila = true; }
Shelly.call("Switch.Set", "{ id:" + rr + ", on:" + tila + "}", null, null);
print("Pikakoodi: Rele " + rr + " on kytketty " + (tila ? "päälle" : "pois päältä") + (!virhe ? "." : " (virhetilanne)."));
if (virhe && res != null && res.body != null) { print("Pikakoodi: Rele " + rr + " virheviesti: " + res.body) }
if (rr == 0) { tunti = (vtila) ? -1 : new Date().getHours(); print("Pikakoodi: Tunti suoritettu? " + !vtila); vtila = (tunti > -1) ? false : true; }
});
}
});
2 changes: 1 addition & 1 deletion Scripts/Shelly-PlusPlugS-StreetLight.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Thank you for your support: https://www.buymeacoffee.com/spothintafi
// Supported Shelly firmwares: 1.0.3 - 1.1.0. Script version: 2024-01-21
// Supported Shelly firmwares: 1.0.3 - 1.2.0. Script version: 2024-02-17

// NOTE! This script works only with "Shelly Plus Plug S" -smart plug

Expand Down
2 changes: 1 addition & 1 deletion Scripts/Shelly-Rank-and-Price.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Thank you for your support: https://www.buymeacoffee.com/spothintafi
// Supported Shelly firmwares: 1.0.3 - 1.1.0. Script version: 2024-01-21
// Supported Shelly firmwares: 1.0.3 - 1.2.0. Script version: 2024-02-17

// Region to use
let Region = "FI"; // Supported regions: DK1, DK2, EE, FI, LT, LV, NO1, NO2, NO3, NO4, NO5, SE1, SE2, SE3, SE4
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Shelly-SmartHeating.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Thank you for your support: https://www.buymeacoffee.com/spothintafi
// Supported Shelly firmwares: 1.0.3 - 1.1.0. Script version: 2024-01-21
// Supported Shelly firmwares: 1.0.3 - 1.2.0. Script version: 2024-02-17

// SmartHeating: outdoor temperature controlled heating with a possibility to control multiple relays with the same rules.
// Note! At the worst case temperature is off by 10-15c degrees as the measuring station is not at your home, so make your own measurements if precision is required.
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Shelly-SmartMonitoring.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Thank you for your support: https://www.buymeacoffee.com/spothintafi
// Supported Shelly firmwares: 1.0.3 - 1.1.0. Script version: 2024-01-21
// Supported Shelly firmwares: 1.0.3 - 1.2.0. Script version: 2024-02-17

// Common settings
const Region = "FI"; // Supported regions: DK1, DK2, EE, FI, LT, LV, NO1, NO2, NO3, NO4, NO5, SE1, SE2, SE3, SE4
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Shelly-Vesivaraaja.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Kiitos tuestasi: https://www.buymeacoffee.com/spothintafi
// Tuetut Shelly ohjelmistot: 1.0.3 - 1.1.0. Skriptin versio: 2024-01-21
// Tuetut Shelly ohjelmistot: 1.0.3 - 1.2.0. Skriptin versio: 2024-02-17

// ASETUKSET
let TUNNIT_YO = 3; // Yötuntien lukumäärä 22:00 - 06:59?
Expand Down

0 comments on commit 57ecd53

Please sign in to comment.