Skip to content

Commit

Permalink
## [2.11.1] - 01.02.2024 (2)
Browse files Browse the repository at this point in the history
- Bugikorjaus: Skripti ei aina käynnistynyt oikein Shellyn bootatessa / herätessä
  • Loading branch information
jisotalo committed Feb 1, 2024
1 parent 39b3b33 commit 9fbbbc7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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.11.1] - 01.02.2024 (2)
- Bugikorjaus: Skripti ei aina käynnistynyt oikein Shellyn bootatessa / herätessä

## [2.11.0] - 01.02.2024
- Seuraavan päivän hinnat ja toteutuva ohjaus etusivulla
- Uusi asetus: Lähdön ohjaus
Expand Down Expand Up @@ -136,6 +139,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Versio 2 julkaistu (tehty täysin uusiksi)

# In English
## [2.11.1] - 01.02.2024 (2)
- Bug fix: Script didn't always start after boot / power reset

## [2.11.0] - 01.02.2024
- Next day prices and control at the frontpage
- New setting to select if output should be always written or only when changed
Expand Down
2 changes: 1 addition & 1 deletion dist/shelly-porssisahko-addon-temp-hours.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/shelly-porssisahko-addon-temp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/shelly-porssisahko-ht-sensor-temp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/shelly-porssisahko-override-avg-price.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/shelly-porssisahko-user-config.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/shelly-porssisahko.js

Large diffs are not rendered by default.

105 changes: 45 additions & 60 deletions src/shelly-porssisahko.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let C_DEF = {
let _ = {
s: {
/** version number */
v: "2.11.0",
v: "2.11.1",
/** Device name */
dn: '',
/** status as number */
Expand Down Expand Up @@ -358,7 +358,7 @@ function getConfig(isLoop) {

if (isLoop) {
loopRunning = false;
loop();
Timer.set(1000, false, loop);
}
});

Expand Down Expand Up @@ -433,7 +433,7 @@ function pricesNeeded(dayIndex) {
if (dateChanged && _.s.p[1].ts > 0 && getDate(new Date(_.s.p[1].ts * 1000)) !== getDate(now)) {
//Copy tomorrow data
_.p[0] = _.p[1];

_.s.p[0] = Object.assign({}, _.s.p[1]);
_.s.p[0].ts = epoch();

Expand Down Expand Up @@ -627,14 +627,14 @@ function getPrices(dayIndex) {
_.s.p[dayIndex].ts = 0;
_.p[dayIndex] = [];
}

if (dayIndex == 1) {
loopRunning = false;
return;
}

//Today prices -> run logic now
logic();
//Today prices -> run logic ASAP
Timer.set(1000, false, logic);
});

} catch (err) {
Expand All @@ -644,57 +644,11 @@ function getPrices(dayIndex) {

if (dayIndex == 1) {
loopRunning = false;
return;
return;
}

//Today prices -> run logic now
logic();
}
}

/**
* Sets outputs to cmd
* If callback given, its called with success status, like cb(true)
*
* @param {Function} cb callback (optional)
*/
function setOutputs(cb) {
//Invert?
if (_.c.inv) {
cmd = !cmd;
}

if (_.c.oc == 1 && _.s.cmd == cmd) {
//No need to write
log("setOutputs(): lähtö on jo oikeassa tilassa");
addHistory();
_.s.cmd = cmd ? 1 : 0;
cb(true);
return;
}

let cnt = 0;
let success = 0;

for (let i = 0; i < _.c.outs.length; i++) {
setRelay(_.c.outs[i], function (res) {
cnt++;

if (res) {
success++;
}

if (cnt == _.c.outs.length) {
//All done
if (success == cnt) {
addHistory();
_.s.cmd = cmd ? 1 : 0;
cb(true);
} else {
cb(false);
}
}
});
//Today prices -> run logic ASAP
Timer.set(1000, false, logic);
}
}

Expand Down Expand Up @@ -812,15 +766,46 @@ function logic() {

cmd = finalCmd;

setOutputs(function (ok) {
if (ok) {
_.s.chkTs = epoch();
}
//Invert?
if (_.c.inv) {
cmd = !cmd;
}

if (_.c.oc == 1 && _.s.cmd == cmd) {
//No need to write
log("logic(): lähtö on jo oikeassa tilassa");
addHistory();
_.s.cmd = cmd ? 1 : 0;
_.s.chkTs = epoch();
loopRunning = false;
});
}

let cnt = 0;
let success = 0;

for (let i = 0; i < _.c.outs.length; i++) {
setRelay(_.c.outs[i], function (res) {
cnt++;

if (res) {
success++;
}

if (cnt == _.c.outs.length) {
//All done
if (success == cnt) {
addHistory();
_.s.cmd = cmd ? 1 : 0;
_.s.chkTs = epoch();
}

loopRunning = false;
}
});
}
}


//User script
if (typeof USER_OVERRIDE == 'function') {
USER_OVERRIDE(cmd, _, logicFinalize);
Expand Down

0 comments on commit 9fbbbc7

Please sign in to comment.