Skip to content

Commit 0793660

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 0793660

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

apps/OpenEnergyMonitor/octopus/octopus.php

Lines changed: 27 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,8 @@ 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_load()
416+
graph_draw()
427417
});
428418
}
429419

@@ -534,17 +524,6 @@ function updater()
534524
setTimeout(function() { panning = false; }, 100);
535525
});
536526

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-
548527
$(".energy").click(function() {
549528
view_mode = "energy";
550529
graph_draw()
@@ -961,8 +940,32 @@ function graph_draw()
961940
let unit_price = data["agile"][2*this_halfhour_index][1]*1.05;
962941
$("#unit_price").html(unit_price.toFixed(2)+"<span class='units'>p</span>");
963942

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

0 commit comments

Comments
 (0)