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
4 changes: 3 additions & 1 deletion demandshaper-module/demandshaper_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,14 @@ function demandshaper_controller()
$state->ctrl_mode = "timer";
}
}
else if ($ret[1]==1 || $ret[1]==3) {
else if ($ret[1]==1 || $ret[1]==2 || $ret[1]==3) {
if ($state->timer_start1==0 && $state->timer_stop1==0) {
$state->ctrl_mode = "on";
} else {
$state->ctrl_mode = "timer";
}
} else if ($ret[1]==255) {
$state->ctrl_mode = "disabled";
}
} else {
$valid = false;
Expand Down
8 changes: 8 additions & 0 deletions demandshaper-module/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function load_device(device_id, device_name, device_type)
// $(".device-name").html(" ("+device_name+")");

$(".node-scheduler").attr("node",device_name);

if (device_type=="openevse") {
$("#mode button[mode='disabled']").show();
}

// -------------------------------------------------------------------------
// Defaults
Expand Down Expand Up @@ -243,6 +247,7 @@ function load_device(device_id, device_name, device_type)
if (schedule.settings.ctrlmode=="smart") { $(".smart").show(); $(".timer").hide(); $(".repeat").show(); }
if (schedule.settings.ctrlmode=="on") { $(".smart").hide(); $(".timer").hide(); $(".repeat").hide(); }
if (schedule.settings.ctrlmode=="off") { $(".smart").hide(); $(".timer").hide(); $(".repeat").hide(); }
if (schedule.settings.ctrlmode=="disabled") { $(".smart").hide(); $(".timer").hide(); $(".repeat").hide(); }

// var elapsed = Math.round((new Date()).getTime()*0.001 - schedule.settings.last_update_from_device);
// $("#last_update_from_device").html(elapsed+"s ago");
Expand Down Expand Up @@ -645,6 +650,9 @@ function load_device(device_id, device_name, device_type)
case "off":
$(this).addClass("red").siblings().removeClass('red').removeClass('green');
break;
case "disabled":
$(this).addClass("red").siblings().removeClass('red').removeClass('green');
break;
case "timer":
// if (schedule.settings.period==0) schedule.settings.period = last_period;
// if (schedule.settings.end==0) schedule.settings.end = 8.0;
Expand Down
2 changes: 1 addition & 1 deletion demandshaper-module/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- CONTROLS -->
<!---------------------------------------------------------------------------------------------------------------------------->
<div id="mode" class="btn-group">
<button mode="on">On</button><button mode="off">Off</button><button mode="smart" class="active">Smart</button><button mode="timer">Timer</button>
<button mode="on">On</button><button mode="off">Off</button><button mode="disabled" style="display:none">Disabled</button><button mode="smart" class="active">Smart</button><button mode="timer">Timer</button>
</div><br><br>

<div class="openevse hide">
Expand Down
13 changes: 12 additions & 1 deletion demandshaper_run.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@

if ($schedule->settings->ctrlmode=="on") $status = 1;
if ($schedule->settings->ctrlmode=="off") $status = 0;
if ($schedule->settings->ctrlmode=="disabled") $status = -1;

if ($status) {
$log->info(" status: ON");
Expand Down Expand Up @@ -283,6 +284,9 @@
$timer[$device] = time_conv_dec_str($s1)." ".time_conv_dec_str($e1)." ".time_conv_dec_str($s2)." ".time_conv_dec_str($e2);
}
if ($device_type=="openevse") {
// in case it was disabled before
$mqtt_client->publish("$basetopic/$device/rapi/in/\$FE","",0);

$api = "rapi/in/\$ST";
$timer[$device] = time_conv_dec_str($s1," ")." ".time_conv_dec_str($e1," ");
}
Expand All @@ -303,14 +307,15 @@
if ($ctrlmode=="on") $ctrlmode_status = "On";
if ($ctrlmode=="smart") $ctrlmode_status = "Timer";
if ($ctrlmode=="timer") $ctrlmode_status = "Timer";
if ($ctrlmode=="disabled") $ctrlmode_status = "Disabled";

if ($device_type=="smartplug" || $device_type=="hpmon" || $device_type=="wifirelay") {
$mqtt_client->publish("$basetopic/$device/in/ctrlmode",$ctrlmode_status,0);
schedule_log("$device set ctrlmode $ctrlmode_status");
}

if ($device_type=="openevse") {
if ($ctrlmode=="on" || $ctrlmode=="off") {
if ($ctrlmode=="on" || $ctrlmode=="off" || $ctrlmode=="disabled") {
$mqtt_client->publish("$basetopic/$device/rapi/in/\$ST","00 00 00 00",0);
}
if ($ctrlmode=="on") {
Expand All @@ -321,6 +326,10 @@
$mqtt_client->publish("$basetopic/$device/rapi/in/\$FS","",0);
schedule_log("$device turning OFF");
}
if ($ctrlmode=="disabled") {
$mqtt_client->publish("emon/$device/rapi/in/\$FD","",0);
schedule_log("$device turning DISABLED");
}
}
}
$last_ctrlmode[$device] = $ctrlmode;
Expand Down Expand Up @@ -523,6 +532,7 @@ function message($message)
if (isset($p->ctrlmode)) {
if ($p->ctrlmode=="On") $schedules->$device->settings->ctrlmode = "on";
if ($p->ctrlmode=="Off") $schedules->$device->settings->ctrlmode = "off";
if ($p->ctrlmode=="Disabled") $schedules->$device->settings->ctrlmode = "disabled";
if ($p->ctrlmode=="Timer" && $schedules->$device->settings->ctrlmode!="smart") $schedules->$device->settings->ctrlmode = "timer";
}

Expand All @@ -545,6 +555,7 @@ function message($message)
else if ($message->topic=="$basetopic/$device/out/ctrlmode") {
if ($p=="On") $schedules->$device->settings->ctrlmode = "on";
if ($p=="Off") $schedules->$device->settings->ctrlmode = "off";
if ($p=="Disabled") $schedules->$device->settings->ctrlmode = "disabled";
if ($p=="Timer" && $schedules->$device->settings->ctrlmode!="smart") $schedules->$device->settings->ctrlmode = "timer";
$demandshaper->set($userid,$schedules);
}
Expand Down