Coder Social home page Coder Social logo

spot-hinta-fi / shelly Goto Github PK

View Code? Open in Web Editor NEW
31.0 6.0 10.0 177 KB

Shelly smart relay scripts to utilize api.spot-hinta.fi API's

Home Page: https://spot-hinta.fi

License: MIT License

JavaScript 100.00%
home-automation shelly spot-price spot-hinta

shelly's Introduction

API.SPOT-HINTA.FI / For Shelly Plus smart relays

Spot-hinta.fi Shelly Plus scripts automate relays according to the electricity spot-prices, which are read from the api.spot-hinta.fi. Scripts works in Finland, Sweden, Norway, Denmark, Estonia, Latvia and Lithuania. See API Swagger documentation for details: https://api.spot-hinta.fi/swagger/ui

Study scripts and read comments to select which script suits the best for your needs.

Installation instructions

  1. Open web browser and go to Shelly Web Admin aka device's web user interface.
  2. Update Shelly firmware to the latest version: Settings > Firmware > Update.
  3. Go to Scripts > Library > Configure URL and insert library URL: http://api.spot-hinta.fi/Shelly/scripts
  4. Choose the script you like and press "Insert code".
  5. Adjust script settings according to your needs. Scripts have comments in English.
  6. Test script: Change the settings and verify that the relay is does the expected thing.
  7. Use SmartMonitoring script to monitor script execution. Test Monitoring script by manually stopping monitored script(s) - monitoring script should restart the script shortly.

Enjoy automatic control of your relays when the electricity price is cheap (or maybe not cheap, but at least not the most expensive)

Shelly scripts in this package

Vesivaraaja

For Finland, designed especially for water boiler heating during night and afternoon hours. NOTE! This does NOT always use the day's cheapest hours - use Minimal Heating script for maximum effiency.

Pikakoodi

For Finland, to use simple pre-defined rules, see https://spot-hinta.fi/pikakoodit/

Minimal Heating

Excellent choice for many cases, for example for water boiler and floor heating. Very versatile.

Smart Heating

Can control heating based on outdoor temperature and much more.

Rank and Price Limit

Can control two relays according to the fixed price, average price and cheapest price

Smart Monitoring

Monitors internet connection and script execution. Stores relay status change history to spot-hinta.fi cloud.

Street light

Only for Shelly Plus Plug S as those it has the RGB led. Makes the led green/yellow/red depending on electricity price.

shelly's People

Contributors

frspp avatar lisoant avatar ml-bw avatar spot-hinta-fi avatar teme-v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

shelly's Issues

Outdoor temperature adjusted heating - details?

Not an issue but more of a question.

This is not directly related to Shelly script but to /JustNowRankDynamic endpoint.

Could it be possible to have a little bit more information how the ranking hours are decided in the backend? I mean if it's possible to do that in a few sentences.

What's the time frame for ranking system? Is it something like minimum temperature for the whole day or for the next 48 hours or something like that?

Anyway I'm going to test it soon. Thanks again for these superb scripts!

FR: Persentiili

Feature request:
_API voisi ilmoittaa Rank:in lisäksi myös persentiilin (kuinka suuri osa hinnoista on yhtä suuria tai pienempiä kuin kyseinen hinta).

Jos haluaisi lämmittää puolet vuorokaudesta, niin ehto "currentPrice.Percentile <= 50" hoitaisi homman. Vastaava Rank:ia käyttävä ehto on "currentPrice.Rank <= 12".

Tuota persentiiliä voisi käyttää, oli hinnat ilmoitettu sitten tunnin tai vartin jaksoille.

Vartin jaksoja on vuorokaudessa 96 kpl, joten "persentiili" kääntyy arkikielessä melkein suoraan jaksojen lukumääräksi._
source: https://lampopumput.info/foorumi/threads/spot-hinta-fi-yksinkertainen-p%C3%B6rssiohjaus-api-ja-sit%C3%A4-k%C3%A4ytt%C3%A4v%C3%A4t-automaatioskriptit.33938/page-36

Shelly-Minimal_water_heating.js - lacks comments

Hi! Thanks for all so far!

Few things in Shelly-Minimal_water_heating.js could use clarification:

let Rank = "4"; // How many hours relay is on (cheapest hours)
More descriptive name would be good. Such as HowManyHours.

let PriceAllowed = "3"; // Heating is always on, when price is below this (Euro cents)
More descriptive name would be good. Such as PriceLimitAO.

let PriorityHoursRank = "3"; // This limits how many hours are prioritized (i.e. 3 cheapest hours from priority hours)

  • More descriptive name would be good. Such as HowManyPriorityHours
  • What if none wanted?

let PriorityHours = "00,01,02,03,04,05,06"; // These hours are prioritized (smallest ranks to these hours, f.ex. if you want to heat boiler during night)
What if I do not want any priority hours - should this be left empty? Or "99" like "boosterhours"? Comment does not tell this. IMO empty "" would be best if none wanted.

Use "99" if none wanted.
Same as above.

Security: check the response

Shelly.call("HTTP.GET", { url: urlToCall, timeout: 15, ssl_ca: "*" }, RunResponse);

function RunResponse(result) {

I guess the script should check the response so it accepts only integer number (the hour/rank or such) OR force the response to be an integer number, yes? Currently it seems to trust the response 'blindly', which is huge security flaw?

​/JustNowRankDynamic and minimumRank

If minimumRank is set to 24 should the endpoint always return with 200 OK?

If not, could you give some hints why not... 😅

Having some hard time understanding how 'minimumRank` should work.

Here's the URL I'm playing with:
https://api.spot-hinta.fi/JustNowRankDynamic?rankAtZeroDegrees=4&rankAdjusterPercentage=10&minimumRank=24&priceAlwaysAllowed=0&postalCode=20100&priorityHours=0%2C1%2C2%2C3%2C4%2C5%2C6&priceModifier=-100&debugMode=true

Thanks again for these scripts! 💯

FR: prefer cheapest hours

Feature request:
_hieman "ongelmana" se että jos on määritellyt 4 halvinta tuntia esim LVV:lle ja käytännössä varaaja suoriutuu työstään 2 tunnissa, niin se käyttää ne kaksi kalleinta tuntia, jos sähkön hinta on jokaisella tunnilla aina naksun halvempi kuin edellisellä.

Lisäksi tuo tuntuu tapahtuvan aika usein pe-la välillä, kun pörssihinta yleens perjantai-iltana laskee, jolloin perjantain halvimmat tunnit asettuvat sinne iltaan, ja sitten uusi pörssipäivä lauantainen kyykkää usein selkeästi alemmas, niin sitten kun se kyykännyt hinta olisi käytössä varaja on lämmin._

-->
_Suurempi äly vaatisi tiedon varaajan lämpötilasta tai tarkemmin ottaen tiedon kuinka pitkä aika lämmitykseen tarkasti ottaen tarvitaan. Se onnistuisi jos tietäisi 1) lämpötilan nyt 2) varaajan tilavuus 3) vastuksen teho 4) haluttu loppulämpö.

Eli oikeastaan tärkein tieto olisi varaajan lämpötila. Sitä vain helposti suurimmasta osasta varaajia ei saa._

source: https://lampopumput.info/foorumi/threads/spot-hinta-fi-yksinkertainen-p%C3%B6rssiohjaus-api-ja-sit%C3%A4-k%C3%A4ytt%C3%A4v%C3%A4t-automaatioskriptit.33938/page-36

On/off

Hi.

Is it possible to invert the I/O status(?) for ”Shelly-Minimal_water_heating.js”? So when price is high, shelly turns on.

With current script it’s the other way around: Low price = shelly on.

Thanks

Update procedure clarification

Hi,
at first thank you for your hard work.

I would like to ask about the proper way of updating your scripts on a Shelly device. I use provided URL (http://api.spot-hinta.fi/Shelly/library) to download/install scripts on the Shelly.

So when there is a new version of the script, should I delete the existing script and then use "Insert code" to install the newest version and then I would need to manually set parameters again?

Minimal heating not working?

Hi!

I upgraded to Shelly Plus 1PM to fw 1.2.2 and then copied latest Minimal-heating from Github. In past 1,5 days (8.4. 00-) it has turned relay on only for one hour; not all today even if now 15:00 is cheapest 3 hours (should turn on for cheapest 5 hours):
Screenshot 2024-04-09 at 15 11 02

Shelly has correct time:
Screenshot 2024-04-09 at 15 16 48

It worked fine with older FW with older code, before I updated.

Shelly Plus 1PM, fw 1.2.2 (latest stable available)

Settings:

// Thank you for your support: https://www.buymeacoffee.com/spothintafi
// Supported Shelly firmwares: 1.0.3 - 1.2.3. Script version: 2024-03-03

// 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. For example: [0,1,2]
let CheapestHours = "5";  // How many cheapest hours relay will be turned on? To ONLY use a price limit, put CheapestHours to "0".
let OnlyNightHours = false; // If true, cheapest hours are only searched from the night hours (22:00 - 07:00), false == all hours
let PriceAlwaysAllowed = "0"; // Below what hour price the relay can be always on (or off, if inverted)? Value is in full euro cents. Use "-999" to disable.
let BackupHours = [3, 4, 5, 6]; // If Internet connection is down, turn relay ON during these hours (0...23). Use [99], if you don't want any backup hours.
let Inverted = false; // If "true", relay logic is inverted (= relay is turned ON when price is too exepensive and OFF when cheap)

LOG:

SmartMonitoring: Monitored script 1 is running. All good. 15:09:32
SmartMonitoring: Monitored script 8 is running. All good. 15:09:32
Minimal-Heating: This hour has already been executed. Waiting for an hour change. 15:09:51
SmartMonitoring: Testing Internet connection... 15:10:01
SmartMonitoring: Internet connection is OK 15:10:04

Feature request: Ignore last hours of the day, if hours after midnight are cheaper

Add a configuration option to the script (e.g., rank and price) that allows you to ignore the last hours of the day if there are cheaper hours after midnight.

Problem: When the cheapest hours are checked for each day, there come situations when the relay is turned on for the last hours of the day, but just after midnight, there are even cheaper hours. I use Shelly with a water boiler, and water is getting heated up during the last "expensive" hours of the day, even if it would be okay to delay the heating to the next day as there is not much water usage before midnight.

This picture illustrates the problem.
image

Possible solution: Make a configuration switch that ignores X last hours of the day (even if they're the cheapest) if there are cheaper hours after midnight. The number of hours checked after midnight should be, e.g., 5-6 (or configurable). I want the heating to be completed during the night.

Prices are VAT0

Hi!

Please add to introduction, help, documentation and all scripts information that prices are VAT0.

Yösähkö tunnit

Yösähkön tunnit taitaa olla oletusarvoisesti väärin. "PriceModifier_Hours: [22, 23, 0, 1, 2, 3, 4, 5, 6, 7]" pitäisi olla "PriceModifier_Hours: [22, 23, 0, 1, 2, 3, 4, 5, 6]".

Feature request: optimize last hours of day

Last hours of today (2023-02-10) are cheaper than any hours of tomorrow (2023-02-11).

Would be cool if we could take advantage of this and, for example, start heating a little bit earlier during the cheaper hours.

Something like optimizeLastHours=2 would allow today's 22.00-23.59 to be used for next day's ranking.

I'm not sure if this is even possible as we would probably need to take yesterday's ranking also in to account.

Anyway, just wanted to drop the idea here if smarter minds can work this through and you feel this would be worth doing.

Monitoring - Does the internet monitor work?

Hi! I think my Shelly 1PM Mini Plus has a working internet connection as it shows time right. The monitoring script says internet connection is not working - can it be trusted?

FYI: I have another 1PM Mini Plus running Minimal Heating script and also a script that HTTP POST's the data to cloud server. It has had a robust internet during past few days and latest data was stored to the cloud 1 minute ago.

Bug report: `/JustNowRankNight`

Sorry to bother again.

I was testing /JustNowRankNight endpoint at some point at 2023-02-23 22.00-23.59 and everything seemed to be working fine (/JustNowRankNight?Rank=9 returned 200).

However, during next day, at 3AM I'm only getting error 400. Even without Rank parameter. Is there something I'm missing here (again)?

Few sample requests and responses:

Request URL: https://api.spot-hinta.fi/JustNowRankNight
Request Method: GET
Status Code: 400 Bad Request
Remote Address: 20.107.224.17:443
Referrer Policy: strict-origin-when-cross-origin
Content-Length: 3
Content-Type: application/json; charset=utf-8
Date: Fri, 24 Feb 2023 00:59:33 GMT
Request-Context: appId=cid-v1:bcaa7eb9-5ac3-497d-9ac5-397bee643201
Request URL: https://api.spot-hinta.fi/JustNowRankNight?rank=4
Request Method: GET
Status Code: 400 Bad Request
Remote Address: 20.107.224.17:443
Referrer Policy: strict-origin-when-cross-origin
Content-Length: 3
Content-Type: application/json; charset=utf-8
Date: Fri, 24 Feb 2023 01:03:33 GMT
Request-Context: appId=cid-v1:bcaa7eb9-5ac3-497d-9ac5-397bee643201
Request URL: https://api.spot-hinta.fi/JustNowRankNight?rank=5
Request Method: GET
Status Code: 400 Bad Request
Remote Address: 20.107.224.17:443
Referrer Policy: strict-origin-when-cross-origin
Content-Length: 3
Content-Type: application/json; charset=utf-8
Date: Fri, 24 Feb 2023 00:59:09 GMT
Request-Context: appId=cid-v1:bcaa7eb9-5ac3-497d-9ac5-397bee643201
Request URL: https://api.spot-hinta.fi/JustNowRankNight?rank=4
Request Method: GET
Status Code: 400 Bad Request
Remote Address: 20.107.224.17:443
Referrer Policy: strict-origin-when-cross-origin
Content-Length: 3
Content-Type: application/json; charset=utf-8
Date: Fri, 24 Feb 2023 00:56:19 GMT
Request-Context: appId=cid-v1:bcaa7eb9-5ac3-497d-9ac5-397bee643201
Request URL: https://api.spot-hinta.fi/JustNowRankNight?Rank=9
Request Method: GET
Status Code: 400 Bad Request
Remote Address: 20.107.224.17:443
Referrer Policy: strict-origin-when-cross-origin
Content-Length: 3
Content-Type: application/json; charset=utf-8
Date: Fri, 24 Feb 2023 01:25:23 GMT
Request-Context: appId=cid-v1:bcaa7eb9-5ac3-497d-9ac5-397bee643201

JustNowRankDynamic and negative PriceAlwaysAllowed

Are negative values allowed for PriceAlwaysAllowed?

I tried to use negative value but seems that relay still got turned on when price hit zero.

This is a bit problematic for us with a bad electricity deal... 😅

Changes in `/CheapestPeriodTodayCheck` endpoint?

Has there been some changes in /CheapestPeriodTodayCheck endpoint?

I'm calling the API like this:

https://api.spot-hinta.fi/CheapestPeriodTodayCheck/2?priorityHours=0,1,2,3,4,5,6

For some reason this failed to start my boiler today. I was expecting it to start at 02:00.

Am I missing something here?

FpfVIrGWAAITTE1

Säätöviiveen kompensoiminen

Olen testaillut tuota skriptiä "Shelly-Rank-and-Price.js" muutaman poäivän ajan ja pörssisähkäsopimus astuu voimaa vajaan viikonn päästä.

Kun Shelly muuttaa releen statusta, menee siinä ainakin oman lämpöpumpun (IVT) tapauksessa parikin minuuttia, ennen kuin pumppu sammuttaa itsensä, jos sillä on aktiivinen hetki päällänsä. Tällöin pumppu saattaa syödä tuon pari minuuttia kallista sähköä. Voisiko siis skriptiin asjatella lisättävän jonkun uuden parametrin tyyliin "MachineDelay_min" jonka asettavamlla vaikka itseni tapuksessa arvoon "2" Shelly osaisi aikaistaa noita avaa-sulje ja sulje-avaa toimenpiteitä tuon viiveen verran? Ei menisi senttiäkään ylimääräistä sähköyhtiölle... ;)

Muuten kyllä näyttä oikein hyvältä ja eiköhän täsdtä kahvirahat lähde matkaan...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.