diff --git a/.gitignore b/.gitignore index 1bb3020..faaf3fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ cli/settings.php +.vscode/launch.json \ No newline at end of file diff --git a/demandshaper-module/demandshaper_model.php b/demandshaper-module/demandshaper_model.php index f07a291..9fed049 100644 --- a/demandshaper-module/demandshaper_model.php +++ b/demandshaper-module/demandshaper_model.php @@ -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); + } + } + } } } } diff --git a/demandshaper_run.php b/demandshaper_run.php index aea662d..e81638f 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -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); diff --git a/forecasts/nordpool.php b/forecasts/nordpool.php index b84ca9f..9c6e5af 100644 --- a/forecasts/nordpool.php +++ b/forecasts/nordpool.php @@ -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"), @@ -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); @@ -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,'.',''); } } @@ -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; }