Skip to content

Commit 8cc9724

Browse files
committed
Instantaneous cost display
- Nothing updated the graph. Call graph_draw from updater which is called every 5s. - Remove legacy viewcostenergy. - Add a currency symbol setting, defaults to £. - Update the power_now value with agile and consumption data for cost, if we have it.
1 parent e3316b9 commit 8cc9724

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

apps/OpenEnergyMonitor/octopus/octopus.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
// ----------------------------------------------------------------------
227227
config.app = {
228228
"title":{"type":"value", "default":"OCTOPUS AGILE", "name": "Title", "description":"Optional title for app"},
229+
"currency":{"type":"value", "default":"£", "name": "Currency", "description":"Currency symbol (£, $, ...)"},
229230
"import":{"optional":true, "type":"feed", "autoname":"import", "engine":"5"},
230231
"import_kwh":{"type":"feed", "autoname":"import_kwh", "engine":5},
231232
"use_kwh":{"optional":true, "type":"feed", "autoname":"use_kwh", "engine":5},
@@ -283,8 +284,6 @@
283284
var data = {};
284285
var graph_series = [];
285286
var previousPoint = false;
286-
var viewmode = "graph";
287-
var viewcostenergy = "energy";
288287
var panning = false;
289288
var period_text = "month";
290289
var period_average = 0;
@@ -413,17 +412,7 @@ function updater()
413412
if (config.app[key].value) feeds[key] = result[config.app[key].value];
414413
}
415414

416-
if (feeds["import"]!=undefined) {
417-
if (viewcostenergy=="energy") {
418-
if (feeds["import"].value<10000) {
419-
$("#power_now").html(Math.round(feeds["import"].value)+"<span class='units'>W</span>");
420-
} else {
421-
$("#power_now").html((feeds["import"].value*0.001).toFixed(1)+"<span class='units'>kW</span>");
422-
}
423-
} else {
424-
$("#power_now").html(config.app.currency.value+(feeds["import"].value*1*config.app.unitcost.value*0.001).toFixed(3)+"<span class='units'>/hr</span>");
425-
}
426-
}
415+
graph_draw()
427416
});
428417
}
429418

@@ -534,17 +523,6 @@ function updater()
534523
setTimeout(function() { panning = false; }, 100);
535524
});
536525

537-
$(".viewcostenergy").click(function(){
538-
var view = $(this).html();
539-
if (view=="VIEW COST") {
540-
$(this).html("VIEW ENERGY");
541-
viewcostenergy = "cost";
542-
} else {
543-
$(this).html("VIEW COST");
544-
viewcostenergy = "energy";
545-
}
546-
});
547-
548526
$(".energy").click(function() {
549527
view_mode = "energy";
550528
graph_draw()
@@ -961,8 +939,32 @@ function graph_draw()
961939
let unit_price = data["agile"][2*this_halfhour_index][1]*1.05;
962940
$("#unit_price").html(unit_price.toFixed(2)+"<span class='units'>p</span>");
963941

942+
if (feeds["import"]!=undefined) {
943+
if (view_mode=="energy") {
944+
if (feeds["import"].value<10000) {
945+
$("#power_now").html(Math.round(feeds["import"].value)+"<span class='units'>W</span>");
946+
} else {
947+
$("#power_now").html((feeds["import"].value*0.001).toFixed(1)+"<span class='units'>kW</span>");
948+
}
949+
} else {
950+
$("#power_now").html(config.app.currency.value+(unit_price*feeds["import"].value*1e-5).toFixed(3)+"<span class='units'>/hr</span>");
951+
}
952+
$("#power_now").show();
953+
}
954+
964955
$(".last_halfhour_stats").show();
965956
} else {
957+
if (feeds["import"]!=undefined && view_mode=="energy") {
958+
if (feeds["import"].value<10000) {
959+
$("#power_now").html(Math.round(feeds["import"].value)+"<span class='units'>W</span>");
960+
} else {
961+
$("#power_now").html((feeds["import"].value*0.001).toFixed(1)+"<span class='units'>kW</span>");
962+
}
963+
$("#power_now").show();
964+
} else {
965+
$("#power_now").hide();
966+
}
967+
966968
$(".last_halfhour_stats").hide();
967969
}
968970

0 commit comments

Comments
 (0)