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
3 changes: 2 additions & 1 deletion demandshaper-module/demandshaper_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function demandshaper_controller()
if (!isset($schedule->settings->end)) return array("content"=>"Missing end parameter in schedule object");
if (!isset($schedule->settings->period)) return array("content"=>"Missing period parameter in schedule object");
if (!isset($schedule->settings->interruptible)) return array("content"=>"Missing interruptible parameter in schedule object");
if (!isset($schedule->settings->rununtilcompleteby)) return array("content"=>"Missing rununtilcompleteby parameter in schedule object");
if (!isset($schedule->settings->runonce)) return array("content"=>"Missing runonce parameter in schedule object");
if ($schedule->settings->runonce) $schedule->settings->runonce = time();
$device = $schedule->settings->device;
Expand Down Expand Up @@ -114,7 +115,7 @@ function demandshaper_controller()

if ($schedule->settings->ctrlmode=="smart") {
$forecast = get_forecast($redis,$schedule->settings->signal,$timezone);
$schedule->runtime->periods = schedule_smart($forecast,$schedule->runtime->timeleft,$schedule->settings->end,$schedule->settings->interruptible,900,$timezone);
$schedule->runtime->periods = schedule_smart($forecast,$schedule->runtime->timeleft,$schedule->settings->end,$schedule->settings->interruptible,900,$timezone,$schedule->settings->rununtilcompleteby);
$schedule_log_output = "smart ".($schedule->runtime->timeleft/3600)." ".$schedule->settings->end;

} else if ($schedule->settings->ctrlmode=="timer") {
Expand Down
6 changes: 4 additions & 2 deletions demandshaper-module/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function load_device(device_id, device_name, device_type)
period:3,
end:8,
interruptible:0,
rununtilcompleteby:0,
// Timer mode
timer_start1:0,
timer_stop1:0,
Expand Down Expand Up @@ -173,7 +174,7 @@ function load_device(device_id, device_name, device_type)

if (js_calc) {
if (schedule.settings.ctrlmode=="smart") {
schedule.runtime.periods = schedule_smart(forecast,schedule.settings.period*3600,schedule.settings.end,schedule.settings.interruptible,resolution)
schedule.runtime.periods = schedule_smart(forecast,schedule.settings.period*3600,schedule.settings.end,schedule.settings.interruptible,resolution,schedule.settings.rununtilcompleteby)
} else if (schedule.settings.ctrlmode=="timer") {
schedule.runtime.periods = schedule_timer(forecast,schedule.settings.timer_start1,schedule.settings.timer_stop1,schedule.settings.timer_start2,schedule.settings.timer_stop2,resolution)
} else {
Expand Down Expand Up @@ -265,7 +266,8 @@ function load_device(device_id, device_name, device_type)
$(".weekly-scheduler[day="+i+"]").attr("val",schedule.settings.repeat[i]);
}

$(".scheduler-checkbox[name='interruptible']").attr("state",schedule.settings.interruptible);
$(".scheduler-checkbox[name='interruptible']").attr("state", schedule.settings.interruptible);
$(".scheduler-checkbox[name='rununtilcompleteby']").attr("state",schedule.settings.rununtilcompleteby);

draw_forecast_category_select();
draw_forecast_select(forecast_list[schedule.settings.signal].category);
Expand Down
6 changes: 6 additions & 0 deletions demandshaper-module/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@
<button>-</button><input type="time" val="00:00"><button>+</button>
</div>
</div>
</div>
<div class="row" style="max-width:700px; margin: 0 auto;">
<div class="span4" style="margin-bottom:20px">
<p>Ok to interrupt:</p>
<div name="interruptible" state=0 class="input scheduler-checkbox" style="margin:0 auto"></div>
</div>
<div class="span4" style="margin-bottom:20px">
<p>Run until Complete by:</p>
<div name="rununtilcompleteby" state=0 class="input scheduler-checkbox" style="margin:0 auto"></div>
</div>
</div>

<br>
Expand Down
25 changes: 15 additions & 10 deletions demandshaper-module/scheduler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -------------------------------------------------------------------------------------------------------
// SMART SCHEDULE
// -------------------------------------------------------------------------------------------------------
function schedule_smart(forecast,timeleft,end,interruptible,resolution)
function schedule_smart(forecast,timeleft,end,interruptible,resolution,rununtilcompleteby)
{
var MIN = 0
var MAX = 1
Expand Down Expand Up @@ -110,16 +110,21 @@ function schedule_smart(forecast,timeleft,end,interruptible,resolution)
}
let end_hour = start_hour
let tend = tstart

if(rununtilcompleteby) {
// if selected to run until complete by, let end time loop run until complete by
period = 24;
}

for (let i=0; i<period*(divisions/24); i++) {
if (profile[pos+i]!=undefined) {
profile[pos+i][3] = 1
end_hour+=resolution/3600
tend+=resolution
if (end_hour>=24) end_hour -= 24
// dont allow to run past end time
if (tend==end_timestamp) break
}
for (let i = 0; i < period * (divisions / 24); i++) {
if (!profile[pos + i]) break

profile[pos+i][3] = 1
end_hour+=resolution/3600
tend+=resolution
if (end_hour>=24) end_hour -= 24
// dont allow to run past end time
if (tend==end_timestamp) break
}

let periods = []
Expand Down
10 changes: 6 additions & 4 deletions demandshaper_run.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@
if (isset($schedule->settings->device_type)) $device_type = $schedule->settings->device_type;
$ctrlmode = false;
if (isset($schedule->settings->ctrlmode)) $ctrlmode = $schedule->settings->ctrlmode;

$rununtilcompleteby = false;
if (isset($schedule->settings->rununtilcompleteby)) $rununtilcompleteby = $schedule->settings->rununtilcompleteby;

if ($device_type && $ctrlmode)
{
$log->info(date("Y-m-d H:i:s")." Schedule:$device ".$schedule->settings->ctrlmode);
Expand Down Expand Up @@ -353,9 +355,9 @@

schedule_log("$device schedule complete");
}

if (!isset($schedule->runtime->started) || $schedule->settings->interruptible) {

if ($schedule->settings->ctrlmode=="smart") {

// -------------------------------------------------------------------
Expand Down Expand Up @@ -391,7 +393,7 @@
// -------------------------------------------------------------------

$forecast = get_forecast($redis,$schedule->settings->signal,$timezone);
$schedule->runtime->periods = schedule_smart($forecast,$schedule->runtime->timeleft,$schedule->settings->end,$schedule->settings->interruptible,900,$timezone);
$schedule->runtime->periods = schedule_smart($forecast,$schedule->runtime->timeleft,$schedule->settings->end,$schedule->settings->interruptible,900,$timezone,$rununtilcompleteby);

} else if ($schedule->settings->ctrlmode=="timer") {
$forecast = get_forecast($redis,$schedule->settings->signal,$timezone);
Expand Down
6 changes: 6 additions & 0 deletions devices/Control/openevse.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"description": "interruptible",
"processList": []
},
{
"name": "rununtilcompleteby",
"description": "rununtilcompleteby",
"processList": []
},
{
"name": "status",
"description": "status",
Expand All @@ -35,6 +40,7 @@
"end": {"name":"Complete by", "type":"time","default":0,"resolution":0.5},
"repeat": {"type":"weekly-scheduler","default":[1,1,1,1,1,0,0]},
"interruptible": {"name":"Ok to interrupt schedule","type":"checkbox","default":0},
"rununtilcompleteby": {"name":"Run until Complete by","type":"checkbox","default":0},
"runonce": {"type":"","default":true},
"basic": {"type":"","default":0}
}
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Submit schedule:
"end":16,
"repeat":[1,1,1,1,1,1,1],
"interruptible":0,
"rununtilcompleteby":0,
"runonce":false,
"basic":0,
"signal":"carbonintensity",
Expand All @@ -104,6 +105,7 @@ Response:
"end":16,
"repeat":[1,1,1,1,1,1,1],
"interruptible":0,
"rununtilcompleteby":0,
"runonce":false,
"basic":0,
"signal":"carbonintensity",
Expand Down
13 changes: 10 additions & 3 deletions scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function get_forecast($redis,$signal,$timezone) {
// SCHEDULE
// -------------------------------------------------------------------------------------------------------

function schedule_smart($forecast,$timeleft,$end,$interruptible,$resolution,$timezone)
function schedule_smart($forecast,$timeleft,$end,$interruptible,$resolution,$timezone,$rununtilcompleteby)
{
$debug = 0;

Expand Down Expand Up @@ -349,16 +349,23 @@ function schedule_smart($forecast,$timeleft,$end,$interruptible,$resolution,$tim
}
$end_hour = $start_hour;
$tend = $tstart;


if($rununtilcompleteby) {
// if selected to run until complete by, let end time loop run until complete by
$period = 24;
}

for ($i=0; $i<$period*($divisions/24); $i++) {
if (!isset($profile[$pos+$i])) break;

$profile[$pos+$i][3] = 1;
$end_hour+=$resolution/3600;
$tend+=$resolution;
if ($end_hour>=24) $end_hour -= 24;
// dont allow to run past end time
if ($tend==$end_timestamp) break;
}

$periods = array();
if ($period>0) {
$periods[] = array("start"=>array($tstart,$start_hour), "end"=>array($tend,$end_hour));
Expand Down