Skip to content

Commit

Permalink
## [2.7.0] - 05.11.2023
Browse files Browse the repository at this point in the history
- Uusi ominaisuus: automaattinen aikavyöhyke (eli myös autom. kesä/talviaika)
  - Shelly laskee aikaeron UTC-ajan ja paikallisen ajan välillä -> Käytetään aina oikeaa aikavyöhykettä hintojen haussa
  - Jos aikaero muuttuu, haetaan hinnat uusiksi (esim. kun kesä/talviaika vaihtuu)
  - Lisätiedot: [Issue #7](#7)
- Firmware-vaatimus on 1.0.7. Vanhemmille ei luvata tukea.
  - Tässä firmisversiossa parannettiin skriptien muistinhallintaa
  • Loading branch information
jisotalo committed Nov 5, 2023
1 parent 6675f1e commit f308359
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 10 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# Suomeksi
## [2.7.0] - 05.11.2023
- Uusi ominaisuus: automaattinen aikavyöhyke (eli myös autom. kesä/talviaika)
- Shelly laskee aikaeron UTC-ajan ja paikallisen ajan välillä -> Käytetään aina oikeaa aikavyöhykettä hintojen haussa
- Jos aikaero muuttuu, haetaan hinnat uusiksi (esim. kun kesä/talviaika vaihtuu)
- Lisätiedot: [Issue #7](https://github.com/jisotalo/shelly-porssisahko/issues/7)
- Firmware-vaatimus on 1.0.7. Vanhemmille ei luvata tukea.
- Tässä firmisversiossa parannettiin skriptien muistinhallintaa

## [2.6.1] - 29.10.2023
- Bugikorjaus: Pikainen paikkaus jotta toimii kellojen siirron jälkeen
- Koodiin on valitettavasti unohtunut kiinteä aikavyöhyke
Expand Down Expand Up @@ -69,6 +77,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Versio 2 julkaistu (tehty täysin uusiksi)

# In English
## [2.7.0] - 05.11.2023
- New feature: automatic timezone detection (also automatic DST)
- Calculating time difference between UTC and local time -> if time difference changes, prices are updated
- Handles changing of DST automatically
- Firmware requirement: 1.0.7 or newer

## [2.6.1] - 29.10.2023
- Bugfix: Quick patch to fix problem with DST
- Better fix under development
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
[![License](https://img.shields.io/badge/License-AGPLv3-orange)](https://choosealicense.com/licenses/agpl-3.0/)
[![GitHub](https://img.shields.io/badge/View%20on-GitHub-brightgreen)](https://github.com/jisotalo/shelly-porssisahko)
[![Support](https://img.shields.io/badge/Support_with-PayPal-yellow)](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0&currency_code=EUR)




*In English - see bottom of the page.*

Shelly-laitteisiin selaimella ohjattava pörssisähkösovellus, joka venyttää laitteen skriptien rajoja. Pyörittää käyttöliittymää omalla web-serverillä ja tallentaa asetuksensa Shellyn muistiin.
Expand Down Expand Up @@ -59,7 +61,10 @@ Käyttää suoraan Viron kantaverkkoyhtiön [elering.ee](https://dashboard.eleri
Katso päivitysten sisältö [CHANGELOG.md-tiedostosta](https://github.com/jisotalo/shelly-porssisahko/blob/master/CHANGELOG.md).

## Asennus
1. Ota Shelly käyttöön, yhdistä se wifi-verkkoon ja päivitä sen firmware (ainakin varmista että se on 1.0.0 tai uudempi)
1. Ota Shelly käyttöön, yhdistä se wifi-verkkoon ja päivitä sen firmware.

**HUOMIO: Firmware 1.0.7 tai uudempi vaaditaan versiosta 2.7.0 eteenpäin.**

2. Valinnainen: Laita **Websocket debug** päälle (Settings -> Debug -> Enable websocket debug). Näin näet suoraan hallintapaneelin osoitteen skriptin alla.
3. Avaa **Scripts**-sivu Shellyn hallinnasta. Poista olemassaolevat skriptit, jos niitä on.
4. Paina **Library**-painiketta
Expand Down
2 changes: 1 addition & 1 deletion dist/shelly-porssisahko.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shelly-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const createDistFile = async (filePath, distPath, isShellyScript) => {
'DBG',
'me'
],
//unsafe: true
unsafe: true
},
});

Expand Down
7 changes: 6 additions & 1 deletion shelly-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{
"fname": "dist/shelly-porssisahko.js",
"title": "Pörssisähköohjaus (shelly-porssisahko.js)",
"description": "Pörssisähköohjaus Shellyyn. Klikaa Insert code -painiketta skriptin asentamiseksi. Github-sivu: https://github.com/jisotalo/shelly-porssisahko"
"description": "Pörssisähköohjaus Shellyyn (uusin versio - firmware 1.0.7 tai uudempi). Klikaa Insert code -painiketta skriptin asentamiseksi. Github-sivu: https://github.com/jisotalo/shelly-porssisahko"
},
{
"fname": "https://raw.githubusercontent.com/jisotalo/shelly-porssisahko/v.2.6.1/dist/shelly-porssisahko.js",
"title": "Pörssisähköohjaus v. 2.6.1 (shelly-porssisahko.js)",
"description": "VANHA VERSIO 2.6.1. Tukee firmwareja 1.0.0-1.0.6."
}
]
55 changes: 50 additions & 5 deletions src/shelly-porssisahko.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let C_DEF = {
let _ = {
s: {
/** version number */
v: "2.6.1",
v: "2.7.0",
/** status as number */
st: 0,
/** active command */
Expand All @@ -101,6 +101,8 @@ let _ = {
configOK: 0,
/** If forced manually to ON, then this is the timestamp until cmd shall be on */
fCmdTs: 0,
/** Active time zone as string (URL encoded - such as %2b02:00 = +02:00)*/
tz: "%2b02:00",
/** current price info */
p: {
/** time when prices were read */
Expand Down Expand Up @@ -176,6 +178,46 @@ function getDate(dt) {
return dt.getDate();
}

/**
* Updates current timezone to state as hh:mm string format (url encoded)
* For example if UTC time is 04:55 and local time is 06:55, tz is %2b02:00
*
* NOTE: Technically incorrect, only handles timezones with full hour offsets
*
* @param {Date} now Current time
* @returns
*/
function updateTz(now) {
//Get UTC time as string (e.g. Sun, 29 Oct 2023 04:55:00 GMT)
let utc = now.toUTCString();

//Extract time from UTC time string (e.g. "04:55:00 GMT")
utc = utc.substring(utc.indexOf("" + now.getFullYear()) + 5);

//Extract hours (e.g. "04")
utc = Number(utc.substring(0, utc.indexOf(":")));

//Calculate time difference
let diff = now.getHours() - utc;

let tz = padStart(Math.abs(diff), 2, "0") + ":00";

if (diff < 0) {
tz = "-" + tz;
} else if (diff > 0) {
tz = "%2b" + tz;
} else {
tz = "Z";
}

if (tz !== _.s.tz) {
//Timezone has changed -> we should get prices
_.s.p.ts = 0;
}

_.s.tz = tz;
}

/**
* Adds new log line row
* @param {*} str
Expand Down Expand Up @@ -372,6 +414,7 @@ function logicRunNeeded() {
*/
function getPrices() {
let now = new Date();
updateTz(now);

try {
//let me = "getPrices()";
Expand All @@ -383,7 +426,7 @@ function getPrices() {
+ "-"
+ padStart(getDate(now), 2, "0")
+ "T00:00:00"
+ "%2b02:00";
+ _.s.tz;

let end = start.replace("T00:00:00", "T23:59:59");

Expand All @@ -399,7 +442,6 @@ function getPrices() {
end = null;

//log("URL:" + req.url, me);

Shelly.call("HTTP.GET", req, function (res, err, msg) {
req = null;

Expand Down Expand Up @@ -529,13 +571,15 @@ function getPrices() {
logic();

});

} catch (err) {
log(err);
//Run logic no matter what happened
logic();
}
}


/**
* Sets relay output to cmd
* If callback given, its called with success status, like cb(true)
Expand Down Expand Up @@ -577,8 +621,9 @@ function setRelay(cb) {
function logic() {
//let me = "logic()";
let now = new Date();
updateTz(now);
cmd = false;

try {
if (_.s.timeOK && (_.s.p.ts > 0 && getDate(new Date(_.s.p.ts * 1000)) === getDate(now))) {
//We have time and we have price data for today
Expand Down Expand Up @@ -687,7 +732,7 @@ function logic() {
* This worked!
*
*/
let _perStart = 0;
let _perStart = 0;
let _ind = 0;
let _ind2 = 0;
function isCheapestHour() {
Expand Down

0 comments on commit f308359

Please sign in to comment.