Browse Source

light scheduler working

rfm69
wysiwyng 6 years ago
parent
commit
3827ff37d2
6 changed files with 3260 additions and 3201 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +6
    -2
      code/espurna/scheduler.ino
  3. +3199
    -3189
      code/espurna/static/index.html.gz.h
  4. +2
    -1
      code/html/custom.css
  5. +10
    -5
      code/html/custom.js
  6. +43
    -4
      code/html/index.html

BIN
code/espurna/data/index.html.gz View File


+ 6
- 2
code/espurna/scheduler.ino View File

@ -26,6 +26,7 @@ void _schWebSocketOnSend(JsonObject &root){
scheduler["schEnabled"] = getSetting("schEnabled", i, 1).toInt() == 1; scheduler["schEnabled"] = getSetting("schEnabled", i, 1).toInt() == 1;
scheduler["schSwitch"] = getSetting("schSwitch", i, 0).toInt(); scheduler["schSwitch"] = getSetting("schSwitch", i, 0).toInt();
scheduler["schAction"] = getSetting("schAction", i, 0).toInt(); scheduler["schAction"] = getSetting("schAction", i, 0).toInt();
scheduler["schType"] = getSetting("schType", i, 0);
scheduler["schHour"] = getSetting("schHour", i, 0).toInt(); scheduler["schHour"] = getSetting("schHour", i, 0).toInt();
scheduler["schMinute"] = getSetting("schMinute", i, 0).toInt(); scheduler["schMinute"] = getSetting("schMinute", i, 0).toInt();
scheduler["schWDs"] = getSetting("schWDs", i, ""); scheduler["schWDs"] = getSetting("schWDs", i, "");
@ -53,6 +54,7 @@ void _schConfigure() {
delSetting("schHour", i); delSetting("schHour", i);
delSetting("schMinute", i); delSetting("schMinute", i);
delSetting("schWDs", i); delSetting("schWDs", i);
delSetting("schType", i);
} else { } else {
@ -120,12 +122,14 @@ void _schCheck() {
int minutes_to_trigger = _schMinutesLeft(sch_hour, sch_minute); int minutes_to_trigger = _schMinutesLeft(sch_hour, sch_minute);
if (minutes_to_trigger == 0) { if (minutes_to_trigger == 0) {
int sch_brightness = getSetting("schBrightness", i, -1).toInt();
if (sch_brightness > -1) {
if (getSetting("schType", i, "") == "light") {
int sch_brightness = getSetting("schAction", i, -1).toInt();
DEBUG_MSG_P(PSTR("[SCH] Switching light %d to %d\n"), sch_switch, sch_brightness);
lightChannel(sch_switch, sch_brightness); lightChannel(sch_switch, sch_brightness);
lightUpdate(true, true); lightUpdate(true, true);
} else { } else {
int sch_action = getSetting("schAction", i, 0).toInt(); int sch_action = getSetting("schAction", i, 0).toInt();
DEBUG_MSG_P(PSTR("[SCH] Switching switch %d to %d\n"), sch_switch, sch_action);
if (sch_action == 2) { if (sch_action == 2) {
relayToggle(sch_switch); relayToggle(sch_switch);
} else { } else {


+ 3199
- 3189
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 2
- 1
code/html/custom.css View File

@ -154,7 +154,8 @@ div.state {
.button-update, .button-update,
.button-update-password, .button-update-password,
.button-add-network, .button-add-network,
.button-add-schedule,
.button-add-switch-schedule,
.button-add-light-schedule,
.button-rfb-learn, .button-rfb-learn,
.button-upgrade-browse, .button-upgrade-browse,
.button-ha-add, .button-ha-add,


+ 10
- 5
code/html/custom.js View File

@ -166,7 +166,7 @@ function addValue(data, name, value) {
// These fields will always be a list of values // These fields will always be a list of values
var is_group = [ var is_group = [
"ssid", "pass", "gw", "mask", "ip", "dns", "ssid", "pass", "gw", "mask", "ip", "dns",
"schEnabled", "schSwitch","schAction","schHour","schMinute","schWDs",
"schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs",
"relayBoot", "relayPulse", "relayTime", "relayBoot", "relayPulse", "relayTime",
"mqttGroup", "mqttGroupInv", "mqttGroup", "mqttGroupInv",
"dczRelayIdx", "dczMagnitude", "dczRelayIdx", "dczMagnitude",
@ -612,14 +612,14 @@ function moreSchedule() {
$("div.more", parent).toggle(); $("div.more", parent).toggle();
} }
function addSchedule() {
function addSchedule(event) {
var numSchedules = $("#schedules > div").length; var numSchedules = $("#schedules > div").length;
if (numSchedules >= maxSchedules) { if (numSchedules >= maxSchedules) {
alert("Max number of schedules reached"); alert("Max number of schedules reached");
return null; return null;
} }
var tabindex = 200 + numSchedules * 10; var tabindex = 200 + numSchedules * 10;
var template = $("#scheduleTemplate").children();
var template = $("#" + event.data.schType + "ScheduleTemplate").children();
var line = $(template).clone(); var line = $(template).clone();
$(line).find("input").each(function() { $(line).find("input").each(function() {
$(this).attr("tabindex", tabindex); $(this).attr("tabindex", tabindex);
@ -803,6 +803,9 @@ function initChannels(num) {
line.appendTo("#channels"); line.appendTo("#channels");
$("select.islight").append(
$("<option></option>").attr("value",i).text("Light #" + i));
} }
} }
@ -1011,7 +1014,8 @@ function processData(data) {
if ("schedule" === key) { if ("schedule" === key) {
for (i in value) { for (i in value) {
var schedule = value[i]; var schedule = value[i];
var sch_line = addSchedule();
var sch_line = addSchedule({ data: {schType: schedule['schType'] }});
Object.keys(schedule).forEach(function(key) { Object.keys(schedule).forEach(function(key) {
var sch_value = schedule[key]; var sch_value = schedule[key];
$("input[name='" + key + "']", sch_line).val(sch_value); $("input[name='" + key + "']", sch_line).val(sch_value);
@ -1268,7 +1272,8 @@ $(function() {
$(".button-add-network").on("click", function() { $(".button-add-network").on("click", function() {
$(".more", addNetwork()).toggle(); $(".more", addNetwork()).toggle();
}); });
$(".button-add-schedule").on("click", addSchedule);
$(".button-add-switch-schedule").on("click", { schType: "switch" }, addSchedule);
$(".button-add-light-schedule").on("click", { schType: "light" }, addSchedule);
$(document).on("change", "input", hasChanged); $(document).on("change", "input", hasChanged);
$(document).on("change", "select", hasChanged); $(document).on("change", "select", hasChanged);


+ 43
- 4
code/html/index.html View File

@ -597,7 +597,8 @@
<div id="schedules"></div> <div id="schedules"></div>
<button type="button" class="pure-button button-add-schedule">Add schedule</button>
<button type="button" class="pure-button button-add-switch-schedule">Add switch schedule</button>
<button type="button" class="pure-button button-add-light-schedule">Add light schedule</button>
</fieldset> </fieldset>
@ -1081,17 +1082,17 @@
</div> </div>
<div id="scheduleTemplate" class="template">
<div id="switchScheduleTemplate" class="template">
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">When time is</label> <label class="pure-u-1 pure-u-lg-1-4">When time is</label>
<div class="pure-u-1-4 pure-u-lg-1-5"> <div class="pure-u-1-4 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schHour" type="number" min="0" step="1" max="23" />
<input class="pure-u-2-3" name="schHour" type="number" min="0" step="1" max="23" value="0" />
<div class="pure-u-1-4 hint center">&nbsp;h</div> <div class="pure-u-1-4 hint center">&nbsp;h</div>
</div> </div>
<div class="pure-u-1-4 pure-u-lg-1-5"> <div class="pure-u-1-4 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schMinute" type="number" min="0" step="1" max="59" />
<input class="pure-u-2-3" name="schMinute" type="number" min="0" step="1" max="59" value="0" />
<div class="pure-u-1-4 hint center">&nbsp;m</div> <div class="pure-u-1-4 hint center">&nbsp;m</div>
</div> </div>
<div class="pure-u-0 pure-u-lg-1-3"></div> <div class="pure-u-0 pure-u-lg-1-3"></div>
@ -1118,7 +1119,45 @@
<div class="pure-u-0 pure-u-lg-1-4"></div> <div class="pure-u-0 pure-u-lg-1-4"></div>
<button class="pure-button button-del-schedule" type="button">Delete schedule</button> <button class="pure-button button-del-schedule" type="button">Delete schedule</button>
<input type="hidden" name="schType" value="switch">
</div>
</div>
<div id="lightScheduleTemplate" class="template">
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">When time is</label>
<div class="pure-u-1-4 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schHour" type="number" min="0" step="1" max="23" value="0" />
<div class="pure-u-1-4 hint center">&nbsp;h</div>
</div>
<div class="pure-u-1-4 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schMinute" type="number" min="0" step="1" max="59" value="0" />
<div class="pure-u-1-4 hint center">&nbsp;m</div>
</div>
<div class="pure-u-0 pure-u-lg-1-3"></div>
<label class="pure-u-1 pure-u-lg-1-4">And weekday is one of</label>
<div class="pure-u-2-5 pure-u-lg-1-5">
<input class="pure-u-23-24 pure-u-lg-23-24" name="schWDs" type="text" maxlength="15" tabindex="0" value="1,2,3,4,5,6,7" />
</div>
<div class="pure-u-3-5 pure-u-lg-1-2 hint center">&nbsp;1 for Monday, 2 for Tuesday...</div>
<label class="pure-u-1 pure-u-lg-1-4">Brightness</label>
<div class="pure-u-1 pure-u-lg-1-5">
<input class="pure-u-2-3" name="schAction" type="number" min="0" step="1" max="255" value="0" />
</div>
<select class="pure-u-1 pure-u-lg-1-5 islight" name="schSwitch"></select>
<div class="pure-u-0 pure-u-lg-1-5"></div>
<label class="pure-u-1 pure-u-lg-1-4">Enabled</label>
<div class="pure-u-1 pure-u-lg-3-4"><input type="checkbox" name="schEnabled" /></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<button class="pure-button button-del-schedule" type="button">Delete schedule</button>
<input type="hidden" name="schType" value="light">
</div> </div>
</div> </div>


Loading…
Cancel
Save