Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You can support spot-hinta.fi service here: https://www.buymeacoffee.com/spothintafi
- // Supported Shelly firmwares: 1.0.3 - 1.1.0. Script version: 2024-01-18
- // 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
- let Relays = [0]; // Relays to control with this script. List relays as comma separated. For example: [0,1,2]
- let PriceLimit = 10; // Set the limit (euro cents) when relay is turned on. For example to stop heating by turning the relay on.
- let PriceLimitHours = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23]; // When price limit is checked?
- // Don't touch below!
- print("PriceLimit: Script has started succesfully. The first relay action happens in 30 seconds.");
- let cHour = -1; let Executed = false; let urlToCall = "https://api.spot-hinta.fi/JustNowRank/0/" + PriceLimit + "?region=" + Region;
- Timer.set(30000, true, function () {
- let hour = new Date().getHours();
- if (cHour !== hour) { cHour = hour; Executed = false; print("PriceLimit: The hour has now changed and a new relay action is going to be performed.") }
- if (cHour == hour && Executed == true) { print("PriceLimit: This hour has already been executed. Waiting for an hour change."); return; }
- if (PriceLimitHours.indexOf(cHour) > -1) { Shelly.call("HTTP.GET", { url: urlToCall, timeout: 15, ssl_ca: "*" }, RunResponse); }
- else {
- print("PriceLimit: This hour has not been listed in PriceLimitHours. Turning relay(s) off."); Executed = true;
- for (let i = 0; i < Relays.length; i++) {
- Shelly.call("Switch.Set", "{ id:" + Relays[i] + ", on:false}", null, null);
- }
- }
- });
- function RunResponse(result, error_code) {
- let relayStatus = false; Executed = true;
- if (error_code === 0 && result !== null && result.code === 400) { relayStatus = true; print("PriceLimit: This hour is expensive, turning relay on.");
- } else { print("PriceLimit: This hour is cheap, turning relay off"); }
- for (let i = 0; i < Relays.length; i++) { Shelly.call("Switch.Set", "{ id:" + Relays[i] + ", on:" + relayStatus + "}", null, null); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement