Skip to content

Commit f308359

Browse files
committed
## [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](#7) - Firmware-vaatimus on 1.0.7. Vanhemmille ei luvata tukea. - Tässä firmisversiossa parannettiin skriptien muistinhallintaa
1 parent 6675f1e commit f308359

File tree

6 files changed

+79
-10
lines changed

6 files changed

+79
-10
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
# Suomeksi
8+
## [2.7.0] - 05.11.2023
9+
- Uusi ominaisuus: automaattinen aikavyöhyke (eli myös autom. kesä/talviaika)
10+
- Shelly laskee aikaeron UTC-ajan ja paikallisen ajan välillä -> Käytetään aina oikeaa aikavyöhykettä hintojen haussa
11+
- Jos aikaero muuttuu, haetaan hinnat uusiksi (esim. kun kesä/talviaika vaihtuu)
12+
- Lisätiedot: [Issue #7](https://github.com/jisotalo/shelly-porssisahko/issues/7)
13+
- Firmware-vaatimus on 1.0.7. Vanhemmille ei luvata tukea.
14+
- Tässä firmisversiossa parannettiin skriptien muistinhallintaa
15+
816
## [2.6.1] - 29.10.2023
917
- Bugikorjaus: Pikainen paikkaus jotta toimii kellojen siirron jälkeen
1018
- Koodiin on valitettavasti unohtunut kiinteä aikavyöhyke
@@ -69,6 +77,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6977
- Versio 2 julkaistu (tehty täysin uusiksi)
7078

7179
# In English
80+
## [2.7.0] - 05.11.2023
81+
- New feature: automatic timezone detection (also automatic DST)
82+
- Calculating time difference between UTC and local time -> if time difference changes, prices are updated
83+
- Handles changing of DST automatically
84+
- Firmware requirement: 1.0.7 or newer
85+
7286
## [2.6.1] - 29.10.2023
7387
- Bugfix: Quick patch to fix problem with DST
7488
- Better fix under development

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
[![License](https://img.shields.io/badge/License-AGPLv3-orange)](https://choosealicense.com/licenses/agpl-3.0/)
33
[![GitHub](https://img.shields.io/badge/View%20on-GitHub-brightgreen)](https://github.com/jisotalo/shelly-porssisahko)
44
[![Support](https://img.shields.io/badge/Support_with-PayPal-yellow)](https://www.paypal.com/donate/?business=KUWBXXCVGZZME&no_recurring=0&currency_code=EUR)
5-
5+
6+
7+
68
*In English - see bottom of the page.*
79

810
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.
@@ -59,7 +61,10 @@ Käyttää suoraan Viron kantaverkkoyhtiön [elering.ee](https://dashboard.eleri
5961
Katso päivitysten sisältö [CHANGELOG.md-tiedostosta](https://github.com/jisotalo/shelly-porssisahko/blob/master/CHANGELOG.md).
6062

6163
## Asennus
62-
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)
64+
1. Ota Shelly käyttöön, yhdistä se wifi-verkkoon ja päivitä sen firmware.
65+
66+
**HUOMIO: Firmware 1.0.7 tai uudempi vaaditaan versiosta 2.7.0 eteenpäin.**
67+
6368
2. Valinnainen: Laita **Websocket debug** päälle (Settings -> Debug -> Enable websocket debug). Näin näet suoraan hallintapaneelin osoitteen skriptin alla.
6469
3. Avaa **Scripts**-sivu Shellyn hallinnasta. Poista olemassaolevat skriptit, jos niitä on.
6570
4. Paina **Library**-painiketta

dist/shelly-porssisahko.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shelly-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ const createDistFile = async (filePath, distPath, isShellyScript) => {
229229
'DBG',
230230
'me'
231231
],
232-
//unsafe: true
232+
unsafe: true
233233
},
234234
});
235235

shelly-library.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
{
33
"fname": "dist/shelly-porssisahko.js",
44
"title": "Pörssisähköohjaus (shelly-porssisahko.js)",
5-
"description": "Pörssisähköohjaus Shellyyn. Klikaa Insert code -painiketta skriptin asentamiseksi. Github-sivu: https://github.com/jisotalo/shelly-porssisahko"
5+
"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"
6+
},
7+
{
8+
"fname": "https://raw.githubusercontent.com/jisotalo/shelly-porssisahko/v.2.6.1/dist/shelly-porssisahko.js",
9+
"title": "Pörssisähköohjaus v. 2.6.1 (shelly-porssisahko.js)",
10+
"description": "VANHA VERSIO 2.6.1. Tukee firmwareja 1.0.0-1.0.6."
611
}
712
]

src/shelly-porssisahko.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ let C_DEF = {
8282
let _ = {
8383
s: {
8484
/** version number */
85-
v: "2.6.1",
85+
v: "2.7.0",
8686
/** status as number */
8787
st: 0,
8888
/** active command */
@@ -101,6 +101,8 @@ let _ = {
101101
configOK: 0,
102102
/** If forced manually to ON, then this is the timestamp until cmd shall be on */
103103
fCmdTs: 0,
104+
/** Active time zone as string (URL encoded - such as %2b02:00 = +02:00)*/
105+
tz: "%2b02:00",
104106
/** current price info */
105107
p: {
106108
/** time when prices were read */
@@ -176,6 +178,46 @@ function getDate(dt) {
176178
return dt.getDate();
177179
}
178180

181+
/**
182+
* Updates current timezone to state as hh:mm string format (url encoded)
183+
* For example if UTC time is 04:55 and local time is 06:55, tz is %2b02:00
184+
*
185+
* NOTE: Technically incorrect, only handles timezones with full hour offsets
186+
*
187+
* @param {Date} now Current time
188+
* @returns
189+
*/
190+
function updateTz(now) {
191+
//Get UTC time as string (e.g. Sun, 29 Oct 2023 04:55:00 GMT)
192+
let utc = now.toUTCString();
193+
194+
//Extract time from UTC time string (e.g. "04:55:00 GMT")
195+
utc = utc.substring(utc.indexOf("" + now.getFullYear()) + 5);
196+
197+
//Extract hours (e.g. "04")
198+
utc = Number(utc.substring(0, utc.indexOf(":")));
199+
200+
//Calculate time difference
201+
let diff = now.getHours() - utc;
202+
203+
let tz = padStart(Math.abs(diff), 2, "0") + ":00";
204+
205+
if (diff < 0) {
206+
tz = "-" + tz;
207+
} else if (diff > 0) {
208+
tz = "%2b" + tz;
209+
} else {
210+
tz = "Z";
211+
}
212+
213+
if (tz !== _.s.tz) {
214+
//Timezone has changed -> we should get prices
215+
_.s.p.ts = 0;
216+
}
217+
218+
_.s.tz = tz;
219+
}
220+
179221
/**
180222
* Adds new log line row
181223
* @param {*} str
@@ -372,6 +414,7 @@ function logicRunNeeded() {
372414
*/
373415
function getPrices() {
374416
let now = new Date();
417+
updateTz(now);
375418

376419
try {
377420
//let me = "getPrices()";
@@ -383,7 +426,7 @@ function getPrices() {
383426
+ "-"
384427
+ padStart(getDate(now), 2, "0")
385428
+ "T00:00:00"
386-
+ "%2b02:00";
429+
+ _.s.tz;
387430

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

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

401444
//log("URL:" + req.url, me);
402-
403445
Shelly.call("HTTP.GET", req, function (res, err, msg) {
404446
req = null;
405447

@@ -529,13 +571,15 @@ function getPrices() {
529571
logic();
530572

531573
});
574+
532575
} catch (err) {
533576
log(err);
534577
//Run logic no matter what happened
535578
logic();
536579
}
537580
}
538581

582+
539583
/**
540584
* Sets relay output to cmd
541585
* If callback given, its called with success status, like cb(true)
@@ -577,8 +621,9 @@ function setRelay(cb) {
577621
function logic() {
578622
//let me = "logic()";
579623
let now = new Date();
624+
updateTz(now);
580625
cmd = false;
581-
626+
582627
try {
583628
if (_.s.timeOK && (_.s.p.ts > 0 && getDate(new Date(_.s.p.ts * 1000)) === getDate(now))) {
584629
//We have time and we have price data for today
@@ -687,7 +732,7 @@ function logic() {
687732
* This worked!
688733
*
689734
*/
690-
let _perStart = 0;
735+
let _perStart = 0;
691736
let _ind = 0;
692737
let _ind2 = 0;
693738
function isCheapestHour() {

0 commit comments

Comments
 (0)