diff --git a/README.md b/README.md index df8f96e..ff781e9 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,10 @@ NEED TO FIX FOR THIS RELEASE. * check rs serial adapter is active if light color mode 11 is used. --> + +# Updates in 2.5.1 (dev) +* Added scheduling of pump after events (Power On, Freeze Protect, Boost) + # Updates in 2.5.0 * PDA panel Rev 6.0 or newer that do not have a Jandy iAqualink device attached can use the AqualinkTouch protocol rather than PDA protocol. * This is faster, more reliable and does not intefear with the physical PDA device (like existing implimentation) diff --git a/release/aqualinkd-amd64 b/release/aqualinkd-amd64 index f7828ab..1d74ff0 100755 Binary files a/release/aqualinkd-amd64 and b/release/aqualinkd-amd64 differ diff --git a/release/aqualinkd-arm64 b/release/aqualinkd-arm64 index 1befbfb..9c2c011 100755 Binary files a/release/aqualinkd-arm64 and b/release/aqualinkd-arm64 differ diff --git a/release/aqualinkd-armhf b/release/aqualinkd-armhf index d22997c..784afa8 100755 Binary files a/release/aqualinkd-armhf and b/release/aqualinkd-armhf differ diff --git a/release/aqualinkd.conf b/release/aqualinkd.conf index 967299c..8e0fa60 100755 --- a/release/aqualinkd.conf +++ b/release/aqualinkd.conf @@ -161,6 +161,15 @@ rs485_frame_delay = 0 # If you used the install script and didn;t receive any cron warnings, you should be good to go. enable_scheduler = yes +# Check if button_01 (usually Pump) is scheduled to run after an event that may have turned it off, and set it to run. +# Only for RS panels, Will not work for PDA panles. +# Example below is if pump is off due to power reset, freezeprotect/swg boots turned off between 6am and 11pm turn the pump on. +#scheduler_check_pumpon_hour = 6 +#scheduler_check_pumpoff_hour = 23 +#scheduler_check_poweron = yes +#scheduler_check_freezeprotectoff = yes +#scheduler_check_boostoff = yes + # Put AqualinkD to sleep when in PDA mode after inactivity. # Ignore if you are not using PDA mode. # If you have Jandy PDA then this MUST be set to yes as the controller can only support one PDA. diff --git a/release/serial_logger-amd64 b/release/serial_logger-amd64 index 5ae1f43..01a22e3 100755 Binary files a/release/serial_logger-amd64 and b/release/serial_logger-amd64 differ diff --git a/release/serial_logger-arm64 b/release/serial_logger-arm64 index 6479c61..6c72b92 100755 Binary files a/release/serial_logger-arm64 and b/release/serial_logger-arm64 differ diff --git a/release/serial_logger-armhf b/release/serial_logger-armhf index 81d8661..11809e4 100755 Binary files a/release/serial_logger-armhf and b/release/serial_logger-armhf differ diff --git a/source/allbutton.c b/source/allbutton.c index 30dcdd3..f3c7531 100644 --- a/source/allbutton.c +++ b/source/allbutton.c @@ -9,6 +9,7 @@ #include "devices_jandy.h" #include "allbutton_aq_programmer.h" #include "color_lights.h" +#include "aq_scheduler.h" /* Below can also be called from serialadapter.c */ void processLEDstate(struct aqualinkdata *aq_data, unsigned char *packet, logmask_t from) @@ -223,8 +224,14 @@ void _processMessage(char *message, struct aqualinkdata *aq_data, bool reset) aq_data->last_display_message[1] = '\0'; // Anything that wasn't on during the last set of messages, turn off - if ((msg_loop & MSG_FREEZE) != MSG_FREEZE) - aq_data->frz_protect_state = default_frz_protect_state; + if ((msg_loop & MSG_FREEZE) != MSG_FREEZE) { + if (aq_data->frz_protect_state != default_frz_protect_state) { + LOG(ALLB_LOG,LOG_INFO, "Freeze protect turned off\n"); + event_happened_set_device_state(FREEZE_PROTECT_OFF, aq_data); + // Add code to check Pump if to turn it on (was scheduled) ie time now is inbetween ON / OFF schedule + } + aq_data->frz_protect_state = default_frz_protect_state; + } if ((msg_loop & MSG_SERVICE) != MSG_SERVICE && (msg_loop & MSG_TIMEOUT) != MSG_TIMEOUT ) { @@ -277,6 +284,11 @@ void _processMessage(char *message, struct aqualinkdata *aq_data, bool reset) } */ if ((msg_loop & MSG_BOOST) != MSG_BOOST) { + if (aq_data->boost == true) { + LOG(ALLB_LOG,LOG_INFO, "Boost turned off\n"); + event_happened_set_device_state(BOOST_OFF, aq_data); + // Add code to check Pump if to turn it on (was scheduled) ie time now is inbetween ON / OFF schedule + } aq_data->boost = false; aq_data->boost_msg[0] = '\0'; aq_data->boost_duration = 0; @@ -420,7 +432,8 @@ void _processMessage(char *message, struct aqualinkdata *aq_data, bool reset) else if (stristr(msg, LNG_MSG_FREEZE_PROTECTION_ACTIVATED) != NULL) { msg_loop |= MSG_FREEZE; - aq_data->frz_protect_state = default_frz_protect_state; + //aq_data->frz_protect_state = default_frz_protect_state; + aq_data->frz_protect_state = ON; //freeze_msg_count = 0; strcpy(aq_data->last_display_message, msg); // Also display the message on web UI } @@ -502,6 +515,7 @@ void _processMessage(char *message, struct aqualinkdata *aq_data, bool reset) { //LOG(ALLBUTTON,LOG_NOTICE, "Standard protocol initialization complete\n"); queueGetProgramData(ALLBUTTON, aq_data); + event_happened_set_device_state(POWER_ON, aq_data); //queueGetExtendedProgramData(ALLBUTTON, aq_data, _aqconfig_.use_panel_aux_labels); _initWithRS = true; } diff --git a/source/aq_scheduler.c b/source/aq_scheduler.c index eeb1e60..908eacd 100644 --- a/source/aq_scheduler.c +++ b/source/aq_scheduler.c @@ -27,6 +27,7 @@ #include "aqualink.h" #include "aq_scheduler.h" #include "config.h" +#include "aq_panel.h" //#include "utils.h" @@ -287,3 +288,47 @@ int build_schedules_js(char* buffer, int size) return length; } + +bool event_happened_set_device_state(reset_event_type type, struct aqualinkdata *aq_data) +{ + // Check time is between hours. + bool scheduledOn = false; + + time_t now = time(NULL); + struct tm *tm_struct = localtime(&now); + + int hour = tm_struct->tm_hour; + if (hour >= _aqconfig_.sched_chk_pumpon_hour && hour < _aqconfig_.sched_chk_pumpoff_hour ) { + scheduledOn = true; + } + + // Check event type. + switch(type){ + case POWER_ON: + if (scheduledOn && _aqconfig_.sched_chk_poweron && aq_data->aqbuttons[0].led->state == OFF) { + LOG(SCHD_LOG,LOG_INFO, "Powered on, schedule is set for pump running and pump is off, turning pump on\n"); + panel_device_request(aq_data, ON_OFF, 0, true, NET_TIMER); + } else { + LOG(SCHD_LOG,LOG_DEBUG, "Powered on, schedule is not set and/or pump is already on, leaving\n"); + } + break; + case FREEZE_PROTECT_OFF: + if (scheduledOn && _aqconfig_.sched_chk_freezeprotectoff && aq_data->aqbuttons[0].led->state == OFF) { + LOG(SCHD_LOG,LOG_INFO, "Freeze Protect off, schedule is set for pump running and pump is off, turning pump on\n"); + panel_device_request(aq_data, ON_OFF, 0, true, NET_TIMER); + } else { + LOG(SCHD_LOG,LOG_DEBUG, "Freeze Protect off, schedule is not set and/or pump is already on, leaving\n"); + } + break; + case BOOST_OFF: + if (scheduledOn && _aqconfig_.sched_chk_boostoff && aq_data->aqbuttons[0].led->state == OFF) { + LOG(SCHD_LOG,LOG_INFO, "Boost off, schedule is set for pump running and pump is off, turning pump on\n"); + panel_device_request(aq_data, ON_OFF, 0, true, NET_TIMER); + } else { + LOG(SCHD_LOG,LOG_DEBUG, "Boost off, schedule is not set and/or pump is already on, leaving\n"); + } + break; + } + + return true; +} diff --git a/source/aq_scheduler.h b/source/aq_scheduler.h index 8e28780..88804d2 100644 --- a/source/aq_scheduler.h +++ b/source/aq_scheduler.h @@ -25,6 +25,14 @@ typedef struct aqs_cron int build_schedules_js(char* buffer, int size); int save_schedules_js(const char* inBuf, int inSize, char* outBuf, int outSize); + +typedef enum reset_event_type{ + POWER_ON, + FREEZE_PROTECT_OFF, + BOOST_OFF +} reset_event_type; + +bool event_happened_set_device_state(reset_event_type type, struct aqualinkdata *aq_data); //void read_schedules(); //void write_schedules(); diff --git a/source/aqualink.h b/source/aqualink.h index e85d42c..9170bb2 100644 --- a/source/aqualink.h +++ b/source/aqualink.h @@ -228,7 +228,7 @@ typedef enum { NET_API, NET_WS, NET_DZMQTT, - NET_TIMER, // Not used yet, need to change aq_timer.c + NET_TIMER, // Timer or Scheduler (eg poweron/freezeprotect check) UNACTION_TIMER } request_source; diff --git a/source/config.c b/source/config.c index 7b54989..1665659 100644 --- a/source/config.c +++ b/source/config.c @@ -155,6 +155,13 @@ void init_parameters (struct aqconfig * parms) #endif parms->enable_scheduler = true; + + parms->sched_chk_poweron = false; + parms->sched_chk_freezeprotectoff = false; + parms->sched_chk_boostoff = false; + parms->sched_chk_pumpon_hour = 0; + parms->sched_chk_pumpoff_hour = 0; + parms->ftdi_low_latency = true; parms->frame_delay = 0; parms->device_pre_state = true; @@ -682,6 +689,21 @@ bool setConfigValue(struct aqualinkdata *aqdata, char *param, char *value) { } else if (strncasecmp (param, "enable_scheduler", 16) == 0) { _aqconfig_.enable_scheduler = text2bool(value); rtn=true; + } else if (strncasecmp (param, "scheduler_check_poweron", 23) == 0) { + _aqconfig_.sched_chk_poweron = text2bool(value); + rtn=true; + } else if (strncasecmp (param, "scheduler_check_freezeprotectoff", 32) == 0) { + _aqconfig_.sched_chk_freezeprotectoff = text2bool(value); + rtn=true; + } else if (strncasecmp (param, "scheduler_check_boostoff", 24) == 0) { + _aqconfig_.sched_chk_boostoff = text2bool(value); + rtn=true; + } else if (strncasecmp (param, "scheduler_check_pumpon_hour", 27) == 0) { + _aqconfig_.sched_chk_pumpon_hour = strtoul(value, NULL, 10); + rtn=true; + } else if (strncasecmp (param, "scheduler_check_pumpoff_hour", 28) == 0) { + _aqconfig_.sched_chk_pumpoff_hour = strtoul(value, NULL, 10); + rtn=true; } else if (strncasecmp (param, "ftdi_low_latency", 16) == 0) { _aqconfig_.ftdi_low_latency = text2bool(value); rtn=true; diff --git a/source/config.h b/source/config.h index 2d5dfc8..0c51acb 100644 --- a/source/config.h +++ b/source/config.h @@ -105,6 +105,11 @@ struct aqconfig bool mqtt_timed_update; bool sync_panel_time; bool enable_scheduler; + bool sched_chk_poweron; + bool sched_chk_freezeprotectoff; + bool sched_chk_boostoff; + int sched_chk_pumpon_hour; + int sched_chk_pumpoff_hour; bool ftdi_low_latency; int frame_delay; bool device_pre_state;