Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cli/settings.php
.vscode/launch.json
24 changes: 17 additions & 7 deletions demandshaper-module/demandshaper_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,23 @@ public function get_combined_forecast($config,$timezone) {
// Clone first, combine 2nd, 3rd etc
if ($combined==false) {
$combined = clone $forecast;
for ($td=0; $td<$profile_length; $td++) $combined->profile[$td] = 0;
}

// Combine
for ($td=0; $td<$profile_length; $td++) {
$combined->profile[$td] += ($forecast->profile[$td]*$config_item->weight);
}

// do not set NordPool nulls to 0 as the values don't really exist
if($name!="nordpool") {
for ($td=0; $td<$profile_length; $td++) $combined->profile[$td] = 0;
}
}
else {
for ($td=0; $td<$profile_length; $td++) {
if(isset($forecast->profile[$td])) {
if($combined->profile[$td] == null) {
$combined->profile[$td] = 0;
}

$combined->profile[$td] += ($forecast->profile[$td]*$config_item->weight);
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demandshaper_run.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
if ($schedule->settings->ctrlmode=="smart") {

// If the schedule has not yet started it is ok to recalculate the schedule periods to find a more optimum time
if (!isset($schedule->runtime->started) || $schedule->settings->interruptible) {
if (!isset($schedule->runtime->started) || !$schedule->runtime->started || $schedule->settings->interruptible) {

// Automatic update of time left for schedule e.g take into account updated battery SOC of electric car, home battery, device
$schedule = $device_class[$device_type]->auto_update_timeleft($schedule);
Expand Down
26 changes: 15 additions & 11 deletions forecasts/nordpool.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function get_forecast_nordpool($redis,$params)
"DK1"=>array("currency"=>"DKK","vat"=>"25"),
"DK2"=>array("currency"=>"DKK","vat"=>"25"),
"EE"=>array("currency"=>"EUR","vat"=>"20"),
"FI"=>array("currency"=>"EUR","vat"=>"24"),
"FI"=>array("currency"=>"EUR","vat"=>0,"tax"=>2.79372,"sellermargin"=>0.17),
"LT"=>array("currency"=>"EUR","vat"=>"21"),
"NO1"=>array("currency"=>"NOK","vat"=>"25"),
"NO2"=>array("currency"=>"NOK","vat"=>"25"),
Expand Down Expand Up @@ -75,8 +75,12 @@ function get_forecast_nordpool($redis,$params)
"t"=>time()
);
if ($result = http_request("GET","http://datafeed.expektra.se/datafeed.svc/spotprice",$req_params)) {
$redis->set($key,$result);
$redis->expire($key,3600);
$ob = json_decode($result);
// only store valid JSON
if($ob != null) {
$redis->set($key,$result);
$redis->expire($key,3600);
}
}
}
$result = json_decode($result);
Expand All @@ -86,11 +90,13 @@ function get_forecast_nordpool($redis,$params)
$timevalues = array();
if ($result!=null && isset($result->data)) {
$vat = (100.0+$nordpool[$params->area]["vat"])/100.0;
$tax = isset($nordpool[$params->area]["tax"]) ? $nordpool[$params->area]["tax"] : 0;
$sellermargin = isset($nordpool[$params->area]["sellermargin"]) ? $nordpool[$params->area]["sellermargin"] : 0;
foreach ($result->data as $row) {
$date = new DateTime($row->utc);
$date->setTimezone($timezone);
$timestamp = $date->getTimestamp();
$timevalues[$timestamp] = number_format($row->value*$vat*0.1,3,'.','');
$timevalues[$timestamp] = number_format($row->value*$vat*0.1+$tax+$sellermargin,3,'.','');
}
}

Expand All @@ -100,14 +106,12 @@ function get_forecast_nordpool($redis,$params)
$forecast_time = floor($time / $forecast_interval) * $forecast_interval;

if (isset($timevalues[$forecast_time])) {
$value = $timevalues[$forecast_time];
} else if (isset($timevalues[$forecast_time-(24*3600)])) { // if not available try to use value 24h in past
$value = $timevalues[$forecast_time-(24*3600)];
} else if (isset($timevalues[$forecast_time+(24*3600)])) { // if not available try to use value 24h in future
$value = $timevalues[$forecast_time+(24*3600)];
$value = $timevalues[$forecast_time];
} else {
$value = null;
}
$profile[] = 1*$value;

$profile[] = $value == null ? null : 1*$value;
}


Expand Down