@@ -109,7 +109,7 @@ let _ = {
109
109
scId : '' , //schedule ID
110
110
manu : false , //manual heating flag
111
111
prov : "None" , //network provider name
112
- newV : 4.3 , //new script version
112
+ newV : 4.4 , //new script version
113
113
sdOk : false , //system data OK
114
114
cdOk : false , //configuration data OK
115
115
} ;
@@ -253,6 +253,7 @@ function memC(dt) {
253
253
c . rId = dt . RelayId ;
254
254
c . cnty = dt . Country ;
255
255
c . hCur = dt . HeatingCurve ;
256
+ c . mnKv = typeof dt . ManualKVS === "boolean" ? dt . ManualKVS : c . mnKv ;
256
257
return c ;
257
258
}
258
259
// ConfigurationData data to KVS store
@@ -268,6 +269,7 @@ function kvsC() {
268
269
cdat . RelayId = c . rId ;
269
270
cdat . Country = c . cnty ;
270
271
cdat . HeatingCurve = c . hCur ;
272
+ cdat . ManualKVS = c . mnKv ;
271
273
return cdat ;
272
274
}
273
275
// Get KVS SystemData into memory
@@ -322,13 +324,8 @@ function inst() {
322
324
gVc ( ) ;
323
325
}
324
326
} 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 ( ) ;
332
329
}
333
330
}
334
331
@@ -382,7 +379,7 @@ function dVc(vCom) {
382
379
if ( vCom . length > 0 ) {
383
380
Timer . set ( 1000 , false , dVc , vCom ) ;
384
381
} else {
385
- wait ( [ aVc , dtVc ( ) ] ) ;
382
+ wait ( [ aVc , dtVc ( ) ] ) ;
386
383
}
387
384
}
388
385
@@ -520,7 +517,7 @@ function gFcs() {
520
517
url = url + c . tPer + "&latitude=" + lat + "&longitude=" + lon ;
521
518
print ( _ . pId , "Forecast query: " , url )
522
519
Shelly . call ( "HTTP.GET" , { url : url , timeout : 5 , ssl_ca : "*" } , function ( res , err ) {
523
- url = null ;
520
+ url = null ;
524
521
if ( err != 0 || res === null || res . code != 200 ) {
525
522
hErr ( "Get forecast HTTP.GET error, check again in " + _ . freq / 60 + " min." ) ;
526
523
return ;
@@ -530,7 +527,7 @@ function gFcs() {
530
527
res = null ;
531
528
let sumT = 0 ;
532
529
for ( let i = 0 ; i < temp . length ; i ++ ) {
533
- sumT += temp [ i ] ;
530
+ sumT += temp [ i ] ;
534
531
}
535
532
536
533
const tFcs = Math . ceil ( sumT / c . tPer ) ; //AVG and round temperature up
@@ -545,7 +542,7 @@ function gFcs() {
545
542
_ . hTim = _ . hTim > c . tPer ? c . tPer : _ . hTim ; //heating time can't be more than the period
546
543
547
544
print ( _ . pId , "Temperture forecast width windchill is " , tFcs , " °C, and heating enabled for " , _ . hTim , " hours." ) ;
548
- gEle ( ) ;
545
+ gEle ( ) ;
549
546
} ) ;
550
547
}
551
548
// Get electricity market price CSV file from Elering
@@ -566,17 +563,17 @@ function gEle() {
566
563
print ( _ . pId , "Elering query: " , url ) ;
567
564
568
565
Shelly . call ( "HTTP.GET" , { url : url , timeout : 5 , ssl_ca : "*" } , function ( res , err ) {
569
- url = null ;
566
+ url = null ;
570
567
if ( err != 0 || res === null || res . code != 200 || ! res . body_b64 ) {
571
568
hErr ( "Elering HTTP.GET error, check again in " + _ . freq / 60 + " min." ) ;
572
569
return ;
573
570
}
574
571
c . pack = eval ( "pack()." + c . pack ) ; //convert transfer fee to variable and load the data
575
572
576
573
// Convert base64 to text and discard header
577
- res . body_b64 = atob ( res . body_b64 ) ;
574
+ res . body_b64 = atob ( res . body_b64 ) ;
578
575
let body = res . body_b64 . substring ( res . body_b64 . indexOf ( "\n" ) + 1 ) ;
579
- res = null ;
576
+ res = null ;
580
577
let raw = [ ] ;
581
578
let eler = [ ] ;
582
579
let aPos = 0 ;
@@ -589,12 +586,12 @@ function gEle() {
589
586
break ; // End of data
590
587
}
591
588
// Epoch
592
- row [ 0 ] = Number ( body . substring ( aPos , body . indexOf ( "\"" , aPos ) ) ) ;
589
+ row [ 0 ] = Number ( body . substring ( aPos , body . indexOf ( "\"" , aPos ) ) ) ;
593
590
// Skip "; after timestamp
594
591
aPos = body . indexOf ( "\"" , aPos ) + 2 ;
595
592
// Price
596
593
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 ( "," , "." ) ) ;
598
595
row [ 1 ] += fFee ( row [ 0 ] ) ; //add transfer fee
599
596
600
597
raw . push ( row ) ;
@@ -650,11 +647,11 @@ function gEle() {
650
647
print ( _ . pId , "Current configuration does not permit heating during any hours; it is likely that the AlwaysOffPrice value is set too low." )
651
648
}
652
649
}
653
- c . pack , raw = null ;
650
+ c . pack , raw = null ;
654
651
_ . manu = false ;
655
652
fTmr ( ) ; //set default timer
656
653
fdSc ( eler ) ; //delete existing schedule and pass eler data to create schedule
657
- eler = null ;
654
+ eler = null ;
658
655
} ) ;
659
656
}
660
657
@@ -787,7 +784,7 @@ function fKvs() {
787
784
function ( ) {
788
785
cntr -- ;
789
786
} ) ;
790
- s . last = null ;
787
+ s . last = null ;
791
788
print ( _ . pId , "Script v" , _ . newV , ( _ . scId > 0 ? " created a schedule with ID:" + _ . scId : "" ) + ", next heating calculation at" , nxHr ( 1 ) + ( _ . updD < 10 ? ":0" : ":" ) + _ . updD ) ;
792
789
wait ( f_Wd ) ;
793
790
}
@@ -961,7 +958,7 @@ function putC(res, err, msg, data) {
961
958
const id = res . id > 0 ? res . id : data . id ; //get the script ID
962
959
Shelly . call ( 'Script.PutCode' , { id : id , code : code } , function ( res , err , msg , data ) {
963
960
if ( err === 0 ) {
964
- a_St ( data . id ) ;
961
+ a_St ( data . id ) ;
965
962
} else {
966
963
print ( _ . pId , "Code is not added to the script:" , msg , ". Schedule will notbe deleted if heating script is stopped or deleted." )
967
964
}
0 commit comments