From 1148694fbcdddda854556617f5e664990a854e14 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Sat, 4 Jan 2020 20:33:36 +0200 Subject: [PATCH 01/13] Add support for OpenEVSE Disabled mode --- demandshaper-module/demandshaper_controller.php | 2 ++ demandshaper-module/general.js | 7 ++++++- demandshaper-module/general.php | 2 +- demandshaper_run.php | 15 +++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/demandshaper-module/demandshaper_controller.php b/demandshaper-module/demandshaper_controller.php index f3cbe8f..58fc506 100644 --- a/demandshaper-module/demandshaper_controller.php +++ b/demandshaper-module/demandshaper_controller.php @@ -256,6 +256,8 @@ function demandshaper_controller() } else { $state->ctrl_mode = "timer"; } + } else if ($ret[1]==255) { + $state->ctrl_mode = "disabled"; } } else { $valid = false; diff --git a/demandshaper-module/general.js b/demandshaper-module/general.js index dd0a798..2102c70 100644 --- a/demandshaper-module/general.js +++ b/demandshaper-module/general.js @@ -15,7 +15,8 @@ function load_device(device_id, device_name, device_type) battery.draw(); battery.events(); $("#run_period").hide(); - $("#run_period").parent().addClass('span2').removeClass('span4'); + $("#run_period").parent().addClass('span2').removeClass('span4'); + $("#mode button[mode='disabled']").show(); } else if (device_type=="hpmon") { $(".heatpumpmonitor").show(); @@ -223,6 +224,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"); @@ -576,6 +578,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; diff --git a/demandshaper-module/general.php b/demandshaper-module/general.php index 434f15d..30059be 100644 --- a/demandshaper-module/general.php +++ b/demandshaper-module/general.php @@ -11,7 +11,7 @@
- +


diff --git a/demandshaper_run.php b/demandshaper_run.php index 351caeb..588acf7 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -279,14 +279,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("emon/$device/in/ctrlmode",$ctrlmode_status,0); schedule_log("$device set ctrlmode $ctrlmode_status"); } - if ($device_type=="openevse") { - if ($ctrlmode=="on" || $ctrlmode=="off") { + if ($device_type=="openevse") { + if ($ctrlmode=="on" || $ctrlmode=="off" || $ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$ST","00 00 00 00",0); } if ($ctrlmode=="on") { @@ -296,7 +297,11 @@ if ($ctrlmode=="off") { $mqtt_client->publish("emon/$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 disabled"); + } } } $last_ctrlmode[$device] = $ctrlmode; @@ -433,6 +438,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"; } @@ -455,6 +461,7 @@ function message($message) else if ($message->topic=="emon/$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); } From 73611f880f3aece508b98986d072a57424cf7f13 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 11:32:05 +0200 Subject: [PATCH 02/13] Remove extra spaces --- demandshaper_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index 588acf7..edd276a 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -286,7 +286,7 @@ schedule_log("$device set ctrlmode $ctrlmode_status"); } - if ($device_type=="openevse") { + if ($device_type=="openevse") { if ($ctrlmode=="on" || $ctrlmode=="off" || $ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$ST","00 00 00 00",0); } From dbc4d77024cdc1902e31101dd3f6b4a36ce89423 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 13:14:53 +0200 Subject: [PATCH 03/13] Fix turning Smart after Disabled --- demandshaper_run.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index edd276a..e54d93b 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -87,7 +87,7 @@ $last_timer = array(); $last_ctrlmode = array(); $last_flowtemp = array(); -$update_interval = 60; +$update_interval = 10; $last_state_check = 0; $schedules = array(); $firstrun = true; @@ -300,8 +300,12 @@ } if ($ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$FD","",0); - schedule_log("$device disabled"); - } + schedule_log("$device rutning DISABLED"); + } + if ($ctrlmode=="smart" && $last_ctrlmode[$device]=="disabled") { + $mqtt_client->publish("emon/$device/rapi/in/\$FS","",0); + schedule_log("$device turning OFF when disabled->smart"); + } } } $last_ctrlmode[$device] = $ctrlmode; From e2109a989d54a21509b7268cc558d318f5be5d50 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 13:16:55 +0200 Subject: [PATCH 04/13] Fix typo --- demandshaper_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index e54d93b..efad14b 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -300,7 +300,7 @@ } if ($ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$FD","",0); - schedule_log("$device rutning DISABLED"); + schedule_log("$device turning DISABLED"); } if ($ctrlmode=="smart" && $last_ctrlmode[$device]=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$FS","",0); From 43a101ddc4f1daa43fa9eb0631e5941fa63c9dec Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 13:18:52 +0200 Subject: [PATCH 05/13] Revert correct update_interval --- demandshaper_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index efad14b..d6c2ee3 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -87,7 +87,7 @@ $last_timer = array(); $last_ctrlmode = array(); $last_flowtemp = array(); -$update_interval = 10; +$update_interval = 60; $last_state_check = 0; $schedules = array(); $firstrun = true; From 9d78a7a63e1da355c71cb682ef03ea51075f1db3 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Sat, 4 Jan 2020 20:33:36 +0200 Subject: [PATCH 06/13] Add support for OpenEVSE Disabled mode --- demandshaper-module/demandshaper_controller.php | 2 ++ demandshaper-module/general.js | 7 ++++++- demandshaper-module/general.php | 2 +- demandshaper_run.php | 15 +++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/demandshaper-module/demandshaper_controller.php b/demandshaper-module/demandshaper_controller.php index 58d0d5d..b517c46 100644 --- a/demandshaper-module/demandshaper_controller.php +++ b/demandshaper-module/demandshaper_controller.php @@ -258,6 +258,8 @@ function demandshaper_controller() } else { $state->ctrl_mode = "timer"; } + } else if ($ret[1]==255) { + $state->ctrl_mode = "disabled"; } } else { $valid = false; diff --git a/demandshaper-module/general.js b/demandshaper-module/general.js index dd0a798..2102c70 100644 --- a/demandshaper-module/general.js +++ b/demandshaper-module/general.js @@ -15,7 +15,8 @@ function load_device(device_id, device_name, device_type) battery.draw(); battery.events(); $("#run_period").hide(); - $("#run_period").parent().addClass('span2').removeClass('span4'); + $("#run_period").parent().addClass('span2').removeClass('span4'); + $("#mode button[mode='disabled']").show(); } else if (device_type=="hpmon") { $(".heatpumpmonitor").show(); @@ -223,6 +224,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"); @@ -576,6 +578,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; diff --git a/demandshaper-module/general.php b/demandshaper-module/general.php index 434f15d..30059be 100644 --- a/demandshaper-module/general.php +++ b/demandshaper-module/general.php @@ -11,7 +11,7 @@
- +


diff --git a/demandshaper_run.php b/demandshaper_run.php index b19c995..61f209d 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -284,14 +284,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("emon/$device/in/ctrlmode",$ctrlmode_status,0); schedule_log("$device set ctrlmode $ctrlmode_status"); } - if ($device_type=="openevse") { - if ($ctrlmode=="on" || $ctrlmode=="off") { + if ($device_type=="openevse") { + if ($ctrlmode=="on" || $ctrlmode=="off" || $ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$ST","00 00 00 00",0); } if ($ctrlmode=="on") { @@ -301,7 +302,11 @@ if ($ctrlmode=="off") { $mqtt_client->publish("emon/$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 disabled"); + } } } $last_ctrlmode[$device] = $ctrlmode; @@ -438,6 +443,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"; } @@ -460,6 +466,7 @@ function message($message) else if ($message->topic=="emon/$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); } From 043966d23616db2399d474ddfff9781fa369687a Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 11:32:05 +0200 Subject: [PATCH 07/13] Remove extra spaces --- demandshaper_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index 61f209d..eb77b17 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -291,7 +291,7 @@ schedule_log("$device set ctrlmode $ctrlmode_status"); } - if ($device_type=="openevse") { + if ($device_type=="openevse") { if ($ctrlmode=="on" || $ctrlmode=="off" || $ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$ST","00 00 00 00",0); } From d7e2a8be29a03e957a8ae13fda7e7465dd7281b8 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 13:14:53 +0200 Subject: [PATCH 08/13] Fix turning Smart after Disabled --- demandshaper_run.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index eb77b17..0b4d993 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -92,7 +92,7 @@ $last_timer = array(); $last_ctrlmode = array(); $last_flowtemp = array(); -$update_interval = 60; +$update_interval = 10; $last_state_check = 0; $schedules = array(); $firstrun = true; @@ -305,8 +305,12 @@ } if ($ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$FD","",0); - schedule_log("$device disabled"); - } + schedule_log("$device rutning DISABLED"); + } + if ($ctrlmode=="smart" && $last_ctrlmode[$device]=="disabled") { + $mqtt_client->publish("emon/$device/rapi/in/\$FS","",0); + schedule_log("$device turning OFF when disabled->smart"); + } } } $last_ctrlmode[$device] = $ctrlmode; From 0bf7d46b0ac3ceaab3234d5b29ea164f43a1e888 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 13:16:55 +0200 Subject: [PATCH 09/13] Fix typo --- demandshaper_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index 0b4d993..1b64887 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -305,7 +305,7 @@ } if ($ctrlmode=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$FD","",0); - schedule_log("$device rutning DISABLED"); + schedule_log("$device turning DISABLED"); } if ($ctrlmode=="smart" && $last_ctrlmode[$device]=="disabled") { $mqtt_client->publish("emon/$device/rapi/in/\$FS","",0); From f3ddc8d2ba1981320938567ec275bc96fe5fb109 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 7 Jan 2020 13:18:52 +0200 Subject: [PATCH 10/13] Revert correct update_interval --- demandshaper_run.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index 1b64887..2bd56d7 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -92,7 +92,7 @@ $last_timer = array(); $last_ctrlmode = array(); $last_flowtemp = array(); -$update_interval = 10; +$update_interval = 60; $last_state_check = 0; $schedules = array(); $firstrun = true; From 922f3ee527a861bc55caeb91a39c28dc92b9e2c5 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 11 Feb 2020 22:54:43 +0200 Subject: [PATCH 11/13] Add support for EV charging state (2) --- demandshaper-module/demandshaper_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demandshaper-module/demandshaper_controller.php b/demandshaper-module/demandshaper_controller.php index b517c46..d5dff9a 100644 --- a/demandshaper-module/demandshaper_controller.php +++ b/demandshaper-module/demandshaper_controller.php @@ -252,7 +252,7 @@ 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 { From eca7b212dcb7e7d88ae7757bd287995fde57c14a Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Tue, 11 Feb 2020 23:27:19 +0200 Subject: [PATCH 12/13] Remove unused setting of ctrlmode_status as it is only used with OpenEVSE --- demandshaper_run.php | 1 - 1 file changed, 1 deletion(-) diff --git a/demandshaper_run.php b/demandshaper_run.php index 2bd56d7..9a43986 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -284,7 +284,6 @@ 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("emon/$device/in/ctrlmode",$ctrlmode_status,0); From 5ee99892ed029dd05ed93d3b967b392910752693 Mon Sep 17 00:00:00 2001 From: Jussi Palo Date: Thu, 23 Apr 2020 14:38:14 +0300 Subject: [PATCH 13/13] Update so support latest changes in master --- demandshaper_run.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/demandshaper_run.php b/demandshaper_run.php index ef37d4e..1803cf0 100644 --- a/demandshaper_run.php +++ b/demandshaper_run.php @@ -284,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," "); } @@ -304,6 +307,7 @@ 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);