Skip to content

Commit 943a405

Browse files
committed
Small fix to retain Manual KVS mode after script update
1 parent 82a2929 commit 943a405

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

SmartHeatingWidthShelly.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let _ = {
109109
scId: '', //schedule ID
110110
manu: false, //manual heating flag
111111
prov: "None", //network provider name
112-
newV: 4.3, //new script version
112+
newV: 4.4, //new script version
113113
sdOk: false, //system data OK
114114
cdOk: false, //configuration data OK
115115
};
@@ -253,6 +253,7 @@ function memC(dt) {
253253
c.rId = dt.RelayId;
254254
c.cnty = dt.Country;
255255
c.hCur = dt.HeatingCurve;
256+
c.mnKv = typeof dt.ManualKVS === "boolean" ? dt.ManualKVS : c.mnKv;
256257
return c;
257258
}
258259
// ConfigurationData data to KVS store
@@ -268,6 +269,7 @@ function kvsC() {
268269
cdat.RelayId = c.rId;
269270
cdat.Country = c.cnty;
270271
cdat.HeatingCurve = c.hCur;
272+
cdat.ManualKVS = c.mnKv;
271273
return cdat;
272274
}
273275
// Get KVS SystemData into memory
@@ -322,13 +324,8 @@ function inst() {
322324
gVc();
323325
}
324326
} else {
325-
if (_.cdOk && _.sdOk) {
326-
print(_.pId, "Existing KVS mode");
327-
main();
328-
} else {
329-
print(_.pId, "New KVS mode installation");
330-
tKvs();
331-
}
327+
print(_.pId, "Script in KVS mode");
328+
tKvs();
332329
}
333330
}
334331

@@ -382,7 +379,7 @@ function dVc(vCom) {
382379
if (vCom.length > 0) {
383380
Timer.set(1000, false, dVc, vCom);
384381
} else {
385-
wait([aVc, dtVc()]);
382+
wait([aVc, dtVc()]);
386383
}
387384
}
388385

@@ -520,7 +517,7 @@ function gFcs() {
520517
url = url + c.tPer + "&latitude=" + lat + "&longitude=" + lon;
521518
print(_.pId, "Forecast query: ", url)
522519
Shelly.call("HTTP.GET", { url: url, timeout: 5, ssl_ca: "*" }, function (res, err) {
523-
url = null;
520+
url = null;
524521
if (err != 0 || res === null || res.code != 200) {
525522
hErr("Get forecast HTTP.GET error, check again in " + _.freq / 60 + " min.");
526523
return;
@@ -530,7 +527,7 @@ function gFcs() {
530527
res = null;
531528
let sumT = 0;
532529
for (let i = 0; i < temp.length; i++) {
533-
sumT += temp[i];
530+
sumT += temp[i];
534531
}
535532

536533
const tFcs = Math.ceil(sumT / c.tPer); //AVG and round temperature up
@@ -545,7 +542,7 @@ function gFcs() {
545542
_.hTim = _.hTim > c.tPer ? c.tPer : _.hTim; //heating time can't be more than the period
546543

547544
print(_.pId, "Temperture forecast width windchill is ", tFcs, " °C, and heating enabled for ", _.hTim, " hours.");
548-
gEle();
545+
gEle();
549546
});
550547
}
551548
// Get electricity market price CSV file from Elering
@@ -566,17 +563,17 @@ function gEle() {
566563
print(_.pId, "Elering query: ", url);
567564

568565
Shelly.call("HTTP.GET", { url: url, timeout: 5, ssl_ca: "*" }, function (res, err) {
569-
url = null;
566+
url = null;
570567
if (err != 0 || res === null || res.code != 200 || !res.body_b64) {
571568
hErr("Elering HTTP.GET error, check again in " + _.freq / 60 + " min.");
572569
return;
573570
}
574571
c.pack = eval("pack()." + c.pack); //convert transfer fee to variable and load the data
575572

576573
// Convert base64 to text and discard header
577-
res.body_b64 = atob(res.body_b64);
574+
res.body_b64 = atob(res.body_b64);
578575
let body = res.body_b64.substring(res.body_b64.indexOf("\n") + 1);
579-
res = null;
576+
res = null;
580577
let raw = [];
581578
let eler = [];
582579
let aPos = 0;
@@ -589,12 +586,12 @@ function gEle() {
589586
break; // End of data
590587
}
591588
// Epoch
592-
row[0] = Number(body.substring(aPos, body.indexOf("\"", aPos)));
589+
row[0] = Number(body.substring(aPos, body.indexOf("\"", aPos)));
593590
// Skip "; after timestamp
594591
aPos = body.indexOf("\"", aPos) + 2;
595592
// Price
596593
aPos = body.indexOf(";\"", aPos) + 2;
597-
row[1] = Number(body.substring(aPos, body.indexOf("\"", aPos)).replace(",", "."));
594+
row[1] = Number(body.substring(aPos, body.indexOf("\"", aPos)).replace(",", "."));
598595
row[1] += fFee(row[0]); //add transfer fee
599596

600597
raw.push(row);
@@ -650,11 +647,11 @@ function gEle() {
650647
print(_.pId, "Current configuration does not permit heating during any hours; it is likely that the AlwaysOffPrice value is set too low.")
651648
}
652649
}
653-
c.pack, raw = null;
650+
c.pack, raw = null;
654651
_.manu = false;
655652
fTmr(); //set default timer
656653
fdSc(eler); //delete existing schedule and pass eler data to create schedule
657-
eler = null;
654+
eler = null;
658655
});
659656
}
660657

@@ -787,7 +784,7 @@ function fKvs() {
787784
function () {
788785
cntr--;
789786
});
790-
s.last = null;
787+
s.last = null;
791788
print(_.pId, "Script v", _.newV, (_.scId > 0 ? " created a schedule with ID:" + _.scId : "") + ", next heating calculation at", nxHr(1) + (_.updD < 10 ? ":0" : ":") + _.updD);
792789
wait(f_Wd);
793790
}
@@ -961,7 +958,7 @@ function putC(res, err, msg, data) {
961958
const id = res.id > 0 ? res.id : data.id; //get the script ID
962959
Shelly.call('Script.PutCode', { id: id, code: code }, function (res, err, msg, data) {
963960
if (err === 0) {
964-
a_St(data.id);
961+
a_St(data.id);
965962
} else {
966963
print(_.pId, "Code is not added to the script:", msg, ". Schedule will notbe deleted if heating script is stopped or deleted.")
967964
}

0 commit comments

Comments
 (0)