kh monitor + variable dosing

Requests for new functions or software apps
Post Reply
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

kh monitor + variable dosing

Post by lnevo »

So with all the new devices that are out to do KH monitoring, we have two choices so far that we can interface with...

Alkatronic - https://www.coralvue.com/alkatronic-alk ... controller
All in one device, 4 pumps, doses. Extensive software, lots of failsafes built in. Active development, good customer support. WiFi support, wall mountable, 2 bnc outputs (one can go to their doser), can control a bluetooth outlet and therefore 3rd party doser or co2 regulator - $899 - $999

KH Guardian Pro - https://www.coralvue.com/kh-guardian-pro or
KH Monitor - https://www.coralvue.com/kh-guardian-alkalinity-monitor
Simpler device. 2 or 3 pumps depending if you want dosing. Requires ethernet connection. Stand-alone just tests and provides logs. Pro will dose and auto-correct, etc. Dosing is always optional. Active developer and support. $499 - $599

These devices come with a BNC output that can be connected to a pH port and when calibrated can tell the RA what our dKH values are. So I'm trying to think about what failsafes and what enhancements to my existing dosing routine. From everything we've seen so far, the results have been extremely consistent and controlling our dosers based on this really helps bring out the stability.

My code already has a function to dose the appropriate amount of sodium bicarb if I input my current PPM into one of the Custom Variables. So my target is set to 150, if I input 145 it will dose enough alk to bring me to 150. Today it only does that with a few checks (adjustment is only 1-9ppm) and dependencies (another outlet is on).

What I'm thinking of doing is leaving my current dosing schedule alone and every 4 hours read the dkh and run that adjustment function. There's already a threshold there to avoid correcting too much, and I can alert if the threshold is approaching that. This way I can review and increase my static dosing.

What other checks would you do? Do you think I'm nuts? Should I just rely on the vendors code and hand-over the reigns to these other guys?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Oh and the nice thing about doing the corrections ourself is I can adjust calcium and magnesium to match and do a round of correction for them too based on the dkh reading.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

A sneak preview :)
alk.png
alk.png (3.14 KiB) Viewed 17665 times
After some more research I decided to go with the KH Guardian Monitor. While the forums seem quiet about this product, there's a pretty direct source of support from the inventor for the KH Guardian monitor. What I also found out was that the monitor only model may be discontinued so I jumped on it now while I could and the price while high, isn't as damaging as the alkatronic. This one does seem much less user friendly than the alkatronic, but I really want to do most of my code on the RA. Like I said, it's already there, I just need to add some tracking for the adjustments and to schedule the adjustments. I really look forward to adjusting my other supplements along with the changes in alk to hopefully really keep things stable.

Now I have to think about where I'm gonna put it...
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

kh monitor + variable dosing

Post by lnevo »

Ok, the stars aligned, my KH guardian came yesterday, the ph expansion module arrived today, I was able to get everything setup flawlessly. It was all almost too good to be true. The KH Guardian is not the most user friendly, but man it works nicely.

Here's what my test results look like so far.

Code: Select all

  12/22 15:04:41 W.116 %0 KH :8.10
  12/22 15:53:43 W.118 %0 KH :7.90
  12/22 16:12:56 W.113 %0 KH :8.00
  12/22 16:31:20 W.113 %1 KH :8.30
I'm going to run it for a while and see how it behaves before I start adjusting any code. I am planning to recalibrate the pH probe soon. I didn't receive calibration fluid and so used what I had on-hand, so just want to double check. Also, you can reverse calibrate the unit to another test kit. So with fresh Hanna reagent on hand, I will do some comparison tests tonight and possibly adjust the result. Based on the iDip tests I do, I'm quite lower, so it will be good to have a 3rd party in the results.

The pH input is working perfectly. The calibration went smoothly and the difference between the Guardian and the result on screen is quite close and consistent. It's not bouncing around at all, so it gets a steady signal and when my result was 8.10 the value was 8.09 on the RA, whereas its 8.30 on the Guardian, my RA is reading 8.26 (and 8->7.96, 7.9 -> 7.86). So basically the RA reads just a touch under.

ImageImageImage
rimai
Posts: 12880
Joined: Fri Mar 18, 2011 6:47 pm

Re: kh monitor + variable dosing

Post by rimai »

That is very cool!!!
Let us know how it compares to another test.
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Nice, it's even in my signature already :)
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Fresh batteries and reagents for the Hannas with the tests below. The iDip batteries and reagents were replaced in October.

Alk
Hanna - 135, 136, 137
Idip - 120, 120, 123
KH Guardian - 143, 148, 143

Just thought I’d share these as well. Nice performance from the iDip :)
Phosphate
Hanna .37, .38, .34
Idip .39, .38, .34

So results are higher than expected, but it's completely normal. First I used questionable 4/7 ph calibration fluids, waiting for new ones to come in. Second, you mix the reagent yourself so some room for error and lastly it's a different methodology, so to be expected.

The alk appears to have increased slightly as well, however it's to be expected as I've been trying to increase from what was as low as 88pm via my iDip so I have my dosers a bit higher as I've been trying to stop what's been a dropping value.

I'd like to get it up enough that the iDip is reading at least 125 / 7dKH and then we'll see how things look, but so far everything has been consistent.

Here's the latest dump from the Guardian:
12/22 14:16:52 W.118 %0 AK. 0.00 KH :8.10
12/22 15:04:41 W.116 %0 KH :8.10
12/22 15:53:43 W.118 %0 KH :7.90
12/22 16:12:56 W.113 %0 KH :8.00
12/22 16:31:20 W.113 %1 KH :8.30
12/22 20:50:48 W.116 %0 KH :8.00
12/23 01:10:16 W.115 %0 KH :8.10
12/23 05:22:33 W.113 %0 KH :8.40
12/23 09:42:15 W.114 %0 KH :8.40
12/23 14:02:22 W.120 %0 KH :8.40
12/23 18:14:35 W.121 %0 KH :8.50
12/23 21:08:40 W.121 %0 KH :8.50
12/23 21:48:13 W.121 %0 KH :8.40
12/24 02:08:15 W.121 %0 KH :8.40
12/24 06:28:29 W.121 %0 KH :8.40

The earlier results that were lower could also be the lines flushing and everything getting settled in. Obviously still in observation phase :)
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Ok so I started preparing some code finally. The first goal is to have a more reliable way to track how long each dosing pump is used in order to set some thresholds and better log. Currently I have a log in volume through the CustomVariables. I could just move that to a memory field, but it changes at least once per hour now and I'd rather more accurately store the seconds run which could end up using more than a byte. So I'm trying something new and logging the data to a file on the SD card. When I start up, I initialize the timer that's been running and each day I reset the timer and the file. The saving of the log happens when the dosing pump switches off. The timer starts counting when the pump goes on.

Code: Select all

#define numDPumps 3 
byte pump[numDPumps]={ DPump1, DPump2, DPump3}; // Pump 3 is just for logging/calibration routine
byte varReport[numDPumps]={ Var_DPump1, Var_DPump2, Var_DPump3};

void LogDosingPumps() {
  static time_t pumpTimer[numDPumps];
  static boolean pumpStatus[numDPumps], initLog;
  static char* pumpLogfiles[] = { "dp1.txt", "dp2.txt", "dp3.txt" };
  float rate;
  File logfile;
  
  if (!initLog) {
    initLog=true;
    for (int i=0;i< numDPumps;i++) {
      logfile=SD.open(pumpLogfiles[i]);
      if (logfile) {
        while (logfile.available()) {
          pumpTimer[i] = read32(logfile);
        }
        logfile.close();
      } else {
        Serial.println("error opening logfile");
      }
    }
  }

  for (int i=0;i< numDPumps;i++) {
    if (ReefAngel.Relay.Status(pump[i])) {
      if (!pumpStatus[i]) {
        pumpTimer[i]=now()-pumpTimer[i]; // Pump was off, timer is now a time
        pumpStatus[i]=true;
      }
    } else {
      if (pumpStatus[i]) {
        pumpTimer[i]=now()-pumpTimer[i]; // Pump was on, timer is now a timer
        pumpStatus[i]=false;
    
        rate=(float)InternalMemory.read_int(memCalVol[i])/InternalMemory.read_int(memCalTime[i]);
        ReefAngel.CustomVar[varReport[i]]=pumpTimer[i]*rate;

        // Open file and save current pumpTimer[i] // seconds elapsed today
        logfile=SD.open(pumpLogfiles[i], FILE_WRITE);
        if (logfile) {
          while (logfile.available()) {
            logfile.print(pumpTimer[i]);
          }
          logfile.close();
        } else {
          Serial.println("error opening logfile");
        }
      }
    }

    if (now()%SECS_PER_DAY==SECS_PER_DAY-1) { 
      pumpTimer[i]=0; // Clear timer at end of day
      ReefAngel.CustomVar[varReport[i]]=0; // Clear portal variable
      
      // Clear files for pumpTimer
      for (int i=0;i< numDPumps;i++) {
        logfile=SD.open(pumpLogfiles[i], FILE_WRITE);
        if (logfile) {
          while (logfile.available()) {
            logfile.print((time_t)0);
          }
          logfile.close();
        } else {
         Serial.println("error opening logfile");
        }
      }
    }
  }  
}
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Ok, file operations were not working well for me. :) I've reverted to EEPROM :) No worries. Maybe I'll revisit if someone has some good experience with reading and writing files.

Code: Select all

#define numDPumps 3 
byte pump[numDPumps]={ DPump1, DPump2, DPump3}; // Pump 3 is just for logging/calibration routine
byte varReport[numDPumps]={ Var_DPump1, Var_DPump2, Var_DPump3};

void LogDosingPumps() {
  static time_t pumpTimer[numDPumps];
  static boolean pumpStatus[numDPumps], initLog;
  byte memDPLogs[numDPumps]={ Mem_I_DP1Log, Mem_I_DP2Log, Mem_I_DP3Log};
  float rate;

  if (!initLog) {
    initLog=true;
    for (int i=0;i< numDPumps;i++) {
      pumpTimer[i] = InternalMemory.read_int(memDPLogs[i]);
      Serial.print("Init Pump ");
      Serial.print(i);
      Serial.print(":");
      Serial.println(pumpTimer[i]);
      rate=(float)InternalMemory.read_int(memCalVol[i])/InternalMemory.read_int(memCalTime[i]);
      ReefAngel.CustomVar[varReport[i]]=pumpTimer[i]*rate;
    }
  }

  for (int i=0;i< numDPumps;i++) {

    if (ReefAngel.Relay.Status(pump[i])) {
      if (!pumpStatus[i]) {
        pumpTimer[i]=now()-pumpTimer[i]; // Pump was off, timer is now a time
        pumpStatus[i]=true;
      }
    } else {
      if (pumpStatus[i]) {
        pumpTimer[i]=now()-pumpTimer[i]; // Pump was on, timer is now a timer
        pumpStatus[i]=false;
        rate=(float)InternalMemory.read_int(memCalVol[i])/InternalMemory.read_int(memCalTime[i]);
        ReefAngel.CustomVar[varReport[i]]=pumpTimer[i]*rate;
        InternalMemory.write_int(memDPLogs[i],pumpTimer[i]);
        Serial.print("Writing Pump ");
        Serial.print(i);
        Serial.print(":");
        Serial.println(pumpTimer[i]);
      }
    }

    if (now()%SECS_PER_DAY==SECS_PER_DAY-1) { 
      pumpTimer[i]=0; // Clear timer at end of day
      ReefAngel.CustomVar[varReport[i]]=0; // Clear portal variable
      InternalMemory.write_int(memDPLogs[i],pumpTimer[i]);
    }
  }  
}
rimai
Posts: 12880
Joined: Fri Mar 18, 2011 6:47 pm

Re: kh monitor + variable dosing

Post by rimai »

May I ask why SD file didn't work?
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

I wasn't getting the values expected. I suspect because of string to integer conversions, I'm not sure at all. I just know I wasn't getting odd numbers even when explicitly writing the same value to three files. I saw we have a read32 function, that didn't help me much as I wasn't sure if my write was even working properly. I have to look for my mini sd conversion thing so I can actually look at the files that were created and see what they hold.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Ok, so today I have devised how I will affect the variable dosing.

Since I'm dosing by volume currently, what I've decided I will do is if the ALK is over or under the threshold that I'll make a micro adjustment to the dosing time.

So let's say the target alk is 155ppm (byte set in Memory Mem_B_AlkTarget) which converts to 868 by the PHE meter. If the ALK reading is 20 above this (so 888 or 159ppm) then I will reduce the dosing by X amount. Other people using other controllers are simply putting in a if ALK > N don't dose anything which I would worry would cause more of a swing.
Conversely, if the ALK is 20 below the threshold (.20dkH) then I will increase the dosing by X amount.

X in these cases will only be a few ml. Basically for my tank, i need 10ml to increase .2dKH (the +/- threshold I mentioned earlier). So let's say we start with the example above and my alk measures 890. I'm currently dosing 18ml a day which comes to .75ml per hour. My function will add 1/24th of a dose to each hour until the alk drops back in the range. If I set the adjustment value (Mem_B_AlkAdjVol) to 4ml, it would add .16ml to the dosage for those hours, but it won't be able to ever dose more than +/-4ml extra per day.

Next, need to add monitoring for the adjustments and maybe some more checks

Code: Select all

    // If any of these are on
    if (ReefAngel.Relay.Status(VO_Calibrate) || ReefAngel.DisplayedMenu==FEEDING_MODE || ReefAngel.DisplayedMenu==WATERCHANGE_MODE) {
       // Do nothing
    } else {
      // Only apply to pumps 0 and 1 when Adjustment value is between 1-9ml and PHExp value is not in Error (500)
      if (InternalMemory.read(Mem_B_AlkAdjVol)>0 && InternalMemory.read(Mem_B_AlkAdjVol)<10 && i<2 && ReefAngel.Params.PHExp>600) { 
        if (ReefAngel.Params.PHExp < (InternalMemory.read(Mem_B_AlkTarget) / .1786) - 20) { // Convert AlkTarget PPM to DKH and subtract our threshold
          // Increase dosage time if we're under our threshold
          doseTime[i]+=(InternalMemory.read(Mem_B_AlkAdjVol)/rate)/(1440/dpRepeat);
        }
        if (ReefAngel.Params.PHExp > (InternalMemory.read(Mem_B_AlkTarget) / .1786)  + 20) { // Convert AlkTarget PPM to DKH and add our threshold. 
          // Decrease dosage time if we're over our threshold
          doseTime[i]-=(InternalMemory.read(Mem_B_AlkAdjVol)/rate)/(1440/dpRepeat);
        }
      }
      ReefAngel.DosingPumpRepeat(pump[i], i*5, dpRepeat, doseTime[i]);
    }
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

I think the nice thing about the approach is that it should smooth the natural curve of alk consumption on an adaptive basis. I would just have to tune the amount of adjustment I allow to compensate for the natural plus/minus that occurs. Also seeing how long an adjustment is in effect for can help me determine how often I will need to test. I've currently increased it from every 4 hours back to the 2 hour default in order to get more data and not miss any trends.

I just need to figure out how I will track the adjustments made. *scratch* that... I think I just figured that out :) So I currently report my dosing log in the actual amount based on seconds the pump has run. I record that in a CustomVar so I can see throughout the day how much has been dosed. I can then use another CustomVariable to store what should have been dosed without adjustment. That would allow me to overlay the two in a graph nicely and see the affect. I can also set an alarm to trigger at the end of the day if we've hit the limit of the threshold that's been set. So basically if I'm increasing every dosage, then it's time to increase the baseline setting on the dosers.

And thus an alert is born:

Code: Select all

      if (i=0 && abs(ReefAngel.CustomVar[1]-ReefAngel.CustomVar[7])>=InternalMemory.read(Mem_B_AlkAdjVol)) { 
        alkAlert.Send("Alk+usage+alert."); 
      }
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

So I've had some instability with the readings, but after installing the lab grade ph probe they sell for it, it's working much better. In the meantime I have a shipment on the way for a new reaction chamber which has an upgraded level sensor, float switch, and motor for the magnetic stirrer which are all supposed to really help with consistency and accuracy. As of now I still get some outliers around 30% of the time. The challenge now will be how to compensate...

Roberto, may need to revisit logging to a file and reading the results :)

01/04 08 52 09 W.145 %0 KH 7.47 / 133 ppm
01/04 12 39 14 W.150 %0 KH 7.44 / 132 ppm
01/04 16 16 38 W.147 %2 KH 7.07 / 126 ppm
01/04 16 41 29 W.146 %0 KH 7.45 / 133 ppm
01/04 17 25 12 W.145 %0 KH 7.06 / 126 ppm
01/04 18 30 47 W.151 %0 KH 7.44 / 132 ppm
01/04 19 16 06 W.151 %0 KH 7.16 / 127 ppm
01/04 19 32 28 W.152 %0 KH 7.48 / 133 ppm
01/04 19 44 25 W.148 %0 KH 7.85 / 140 ppm
01/04 20 08 06 W.149 %0 KH 7.89 / 140 ppm
01/04 22 03 11 W.148 %0 KH 7.49 / 133 ppm
01/04 23 31 48 W.147 %1 KH 7.48 / 133 ppm
01/05 00 02 37 W.149 %0 KH 7.62 / 136 ppm
01/05 00 46 52 W.150 %0 KH 7.59 / 135 ppm
01/05 01 08 02 W.150 %0 KH 7.58 / 135 ppm
01/05 02 40 06 W.150 %0 KH 7.59 / 135 ppm
01/05 04 39 15 W.153 %0 KH 7.19 / 128 ppm
01/05 06 47 15 W.150 %1 KH 7.48 / 133 ppm
01/05 08 46 40 W.152 %0 KH 7.32 / 130 ppm
01/05 12 39 56 W.151 %0 KH 7.57 / 135 ppm
01/05 14 39 49 W.150 %1 KH 7.59 / 135 ppm
01/05 16 46 45 W.147 %0 KH 7.58 / 135 ppm
01/05 18 46 47 W.151 %1 KH 7.60 / 135 ppm
01/05 20 46 41 W.151 %1 KH 7.60 / 135 ppm
01/05 22 39 51 W.155 %0 KH 7.58 / 135 ppm
01/06 00 46 41 W.156 %1 KH 7.59 / 135 ppm
01/06 02 46 15 W.150 %0 KH 7.16 / 127 ppm
01/06 04 39 30 W.147 %0 KH 7.61 / 135 ppm
01/06 06 39 38 W.146 %0 KH 7.59 / 135 ppm
01/06 08 46 50 W.147 %0 KH 7.90 / 141 ppm
rimai
Posts: 12880
Joined: Fri Mar 18, 2011 6:47 pm

Re: kh monitor + variable dosing

Post by rimai »

What is that you are trying to log?
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

That's the log of alk tests. Since then I've been working with the inventor and scouring the facebook group. I've managed to improve the accuracy and number of outliers quite significantly, plus I"m logging more frequency. Previously if the guardian got a bad value it would re-run the test. Since I've gotten it down, it hasn't re-run any of the tests and the largest outlier was .33dKH off, but typically it's .01-.05dKH between tests, which I'm doing every 90 minutes right now, so that's pretty significant.

I'm going to revise my approach a little bit. I want to gently nudge the alk so I'm planning right now to test with an external script before making the RA autonomous. I'm going to adjust by 1ppm when the value exceeds +/-2ppm. The last column in my report shows when I would have dosed and if it were to reduce or increase the supplement. The column before that is a running net total of addition or subtraction. The goal is to stay as net neutral as possible to stick with what I've set the doser to do.

Here's the last 5 days of testing. You can see how tight the values have been.

02/07/19 17:34:58 7.76 / 138 0
02/07/19 17:44:53 7.76 / 138 0
02/07/19 18:09:43 7.72 / 137 0
02/07/19 21:10:35 7.67 / 136 0
02/07/19 21:27:20 7.62 / 136 0
02/07/19 21:44:54 7.59 / 135 0
02/07/19 22:02:54 7.62 / 136 0
02/07/19 22:20:32 7.61 / 135 0
02/07/19 22:40:11 7.57 / 135 0
02/07/19 22:58:33 7.59 / 136 0
02/08/19 01:08:24 7.59 / 136 0
02/08/19 01:15:04 7.58 / 135 0
02/08/19 01:50:56 7.75 / 138 0
02/08/19 04:08:07 7.58 / 135 0
02/08/19 06:25:47 7.68 / 137 0
02/08/19 09:14:39 7.68 / 137 0
02/08/19 11:32:00 7.71 / 138 0
02/08/19 13:48:10 7.73 / 138 0
02/08/19 16:05:20 7.73 / 138 0
02/08/19 19:40:45 7.71 / 138 0
02/08/19 21:57:30 7.58 / 135 0
02/09/19 00:07:49 7.62 / 136 0
02/09/19 02:22:19 7.61 / 136 0
02/09/19 04:09:20 7.75 / 138 0
02/09/19 05:56:41 7.72 / 138 0
02/09/19 09:24:20 7.82 / 140 -1 Dose -1
02/09/19 11:04:41 7.77 / 139 -1
02/09/19 12:45:13 7.71 / 138 -1
02/09/19 14:25:21 7.72 / 138 -1
02/09/19 16:12:09 7.72 / 138 -1
02/09/19 17:52:18 7.73 / 138 -1
02/09/19 19:32:28 7.72 / 138 -1
02/09/19 21:19:04 7.67 / 137 -1
02/09/19 22:57:43 7.62 / 136 -1
02/10/19 00:37:56 7.57 / 135 -1
02/10/19 02:18:13 7.59 / 136 -1
02/10/19 04:05:06 7.59 / 136 -1
02/10/19 05:52:07 7.57 / 135 -1
02/10/19 07:32:25 7.90 / 141 -2 Dose -1
02/10/19 08:56:53 7.76 / 139 -2
02/10/19 10:36:59 7.77 / 139 -2
02/10/19 12:17:04 7.71 / 138 -2
02/10/19 13:57:10 7.71 / 138 -2
02/10/19 15:44:10 7.72 / 138 -2
02/10/19 17:24:18 7.72 / 138 -2
02/10/19 19:04:28 7.71 / 138 -2
02/10/19 20:50:46 7.63 / 136 -2
02/10/19 22:30:54 7.53 / 134 -1 Dose + 1
02/11/19 01:37:52 7.46 / 133 0 Dose + 1
02/11/19 03:24:53 7.58 / 135 0
02/11/19 05:03:32 7.53 / 134 1 Dose + 1
02/11/19 06:43:48 7.58 / 135 1
02/11/19 08:30:50 7.57 / 135 1
02/11/19 10:17:49 7.59 / 136 1
02/11/19 12:04:50 7.62 / 136 1
02/11/19 13:45:00 7.68 / 137 1
02/11/19 15:25:08 7.73 / 138 1
02/11/19 17:05:17 7.73 / 138 1
02/11/19 18:45:29 7.71 / 138 1
02/11/19 20:32:02 7.67 / 137 1
02/11/19 22:19:00 7.67 / 137 1
02/12/19 00:06:14 7.67 / 137 1
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

So, I implemented this in two parts. Right now I have a script running externally that queries the guardian and if it’s reading after a new test. If it’s +/-2ppm it will set a cvar to either my target + 1 or - 1. If it’s over my target, this tells the RA that it should reduce or slip the dose. If it’s above then the RA should increase the dose.

On the RA side, I start by looking at the PHE reading. It also has to be +/-2ppm and the cvar has to be set appropriately to match. I also keep track of a “delta” and track the number of times we add or reduce the supplement. So if we max out the increases, the RA will not increase until we have a reduction in order to prevent constantly adding or reducing.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

So some success and some failures, although the failures are quite minor. First failure was the RA did not reset the CustomVar after the pumped turned off. That means any action that was due to do something was going to repeat it every hour, unless I override (or automate overriding...) Anyway that was an easy fix. I was doing my test wrong it seems.

Second failure that happened was pretty basic. I've been having ATO problems lately. My gravity feed ATO depends on a siphon I guess and it's been stopping about halfway, I guess air is getting in there. I need to come up with something better and more permanent for that. I did not get an alarm when my pump shut off and so my return pump was off the whole day. The guardian continued to do tests and the alk was climbing, and I couldn't figure it out because the code I was using pretty much was supposed to stop the dosing when it reached the high point. I'm assuming because the return was down the alk wasn't being consumed. In any case, I now have some other alarms set to capture that.

So after that whole debacle, my alk has been super stable :) My last 14 tests were all within .01dkh! As I was looking to raise my alk anyway, I changed my target alk to match where I hit, and now my RA has dosed some extra as the alk has started dropping.

02/13/19 19:22:46 7.73 dKH / 138 ppm
02/13/19 21:02:57 7.72 dKH / 138 ppm
02/13/19 22:43:06 7.72 dKH / 138 ppm
02/14/19 00:23:12 7.72 dKH / 138 ppm
02/14/19 02:10:20 7.72 dKH / 138 ppm
02/14/19 03:57:21 7.73 dKH / 138 ppm
02/14/19 05:37:31 7.72 dKH / 138 ppm
02/14/19 07:24:50 7.73 dKH / 138 ppm
02/14/19 09:12:02 7.73 dKH / 138 ppm
02/14/19 10:52:14 7.72 dKH / 138 ppm
02/14/19 12:32:26 7.72 dKH / 138 ppm
02/14/19 14:12:36 7.73 dKH / 138 ppm
02/14/19 14:24:56 7.72 dKH / 138 ppm
02/14/19 16:05:07 7.72 dKH / 138 ppm
02/14/19 17:51:44 7.67 dKH / 137 ppm +

I can see in the graph that my alk did dose more this hour. The value reset properly and the delta was updated in memory. So we're off. My only concern is that my threshold is too wide now based on the accuracy of this thing, but obviously want to go gently. Let's see how this is for a bit and I can tighten up the controls once I'm happy with it.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

For the record, I like having the external factor in addition to the RA doing it's own thing. Since this is such a vital factor, if for some reason the monitor stopped doing tests, the RA might do something that doesn't match. The script I run externally keeps track of the time of the last test and it will only submit if no errors detected and if it were a new test. So pretty happy with the overall interaction.

The other nice thing now is that my Calcium is now raised alongside my alk keeping everything in proportion.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Ok the experiment continues :)

What I'm seeing right now is I'm needing more alk at certain times and at present I'm not getting to the point where I need to skip. So the delta system I have isn't going to work, unless I'm purposely dosing high which I'd prefer not to do.

So, what I've done now is add a natural decay. I increased the value of "adding" and "subtracting" doses to "2" and so when one of those events happen it will bump the delta up or down. But every hour where nothing is done, the delta will decay back down to 0. So now I can increase the ceiling if I want to give more flexibility, but it also reduces the chance I'll skip a dosage. So we'll have to see how this works in practicality.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Last 24 results:
02/15/19 04:10:39 7.82 dKH / 140 ppm
02/15/19 05:50:55 7.87 dKH / 141 ppm
02/15/19 07:31:13 7.86 dKH / 140 ppm
02/15/19 09:11:34 7.86 dKH / 140 ppm
02/15/19 10:51:57 7.87 dKH / 141 ppm
02/15/19 12:32:18 7.87 dKH / 141 ppm
02/15/19 14:19:06 7.82 dKH / 140 ppm
02/15/19 15:59:18 7.77 dKH / 139 ppm
02/15/19 17:45:24 7.67 dKH / 137 ppm +
02/15/19 19:31:43 7.63 dKH / 136 ppm +
02/15/19 21:18:03 7.58 dKH / 135 ppm +
02/15/19 23:04:23 7.58 dKH / 135 ppm +
02/16/19 00:49:43 7.64 dKH / 136 ppm +
02/16/19 02:29:39 7.68 dKH / 137 ppm +
02/16/19 04:09:42 7.71 dKH / 138 ppm
02/16/19 05:56:21 7.72 dKH / 138 ppm
02/16/19 07:43:33 7.76 dKH / 139 ppm
02/16/19 09:23:55 7.82 dKH / 140 ppm
02/16/19 11:04:18 7.86 dKH / 140 ppm
02/16/19 12:44:39 7.86 dKH / 140 ppm
02/16/19 14:24:54 7.86 dKH / 140 ppm
02/16/19 16:05:22 7.86 dKH / 140 ppm
02/16/19 17:45:43 7.86 dKH / 140 ppm
02/16/19 19:26:03 7.86 dKH / 140 ppm
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

So, both my hanna and idip measure 20-30ppm below the KHG. Both the hanna and idip are within 9ppm consistently which is approx .5 dkh. My goal the past few days has been to increase the alkalinity until the idip value should be at 130 which would have the KHG reading at 155-160ppm. I've been using my variable dosing code to bring me up to that point. So far it's doing it very smoothly, the controls I have put in place are working. I've steadily increased over the past two days going from 138 ppm to 156 today at peak. That's pretty much .5dkh which was my target. I still have a bit of supplementing to go because I'm at the low end of my threshold and my tank is currently at it's peak consumption so I gave it some headroom to keep dosing otherwise its' going to start dropping back down and I'd rather level off than have a spike. Pretty pleased with how this is working so far.

Anyway, once I get to the target alk I want, I'm going to calibrate the KHG to match my other testers. Maybe I'll average the two :) I haven't decided which to calibrate it to. From there my goal will be to maintain as tight and steady alkalinity on the tank.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

So far I like what I've seen. I've been extremely stable since I've raised the alk and calibrated. At this point I'm going to try and loosen up the corrections I make in case I'm over-compensating or my dosing needs more time to take affect. I've increased my daily dose. My "target" is 140ppm, but I've been averaging 138 or 139 so I definitely need to get 1-2ppm higher in order for my average to be at my target. I've also changed the KH guardian to 120 minutes from 90. I may go to 180. It's doubtful that I'll ever go to 240 which is the max. I like seeing the granularity. So since I do one action per test stretching out the time I will need to dose. Currently I get ~3 tests that have me increase my dosage per day. We'll see if that number goes down or increases. The other parameter I can play with is how much of a dose I make when it's needed, but for now I'm leaving that at 3ml (+1ppm).

Here's some graphs to show how it's going. In the charts, alk is the blue line. The green is either ph or calcium. You can see where I increased the alk and calibrated. The variance you see in the alk each day is ~5-6ppm swing.
ph-week.png
ph-week.png (2.69 KiB) Viewed 20690 times
dosing-week-1.png
dosing-week-1.png (3.49 KiB) Viewed 20690 times
ph-month.png
ph-month.png (2.94 KiB) Viewed 20690 times
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Ok so I extended the frequency of the testing to 2 hours from 90 minutes. And after it made a few adjustments my alk was as stable as I'd try and make it. The variance was .17 dkh and essentially 3ppm.

Today though, because of the extended frequency, the delta system I'm using didn't kick in and it caused my alk to jump a bit more than expected. It does take a while for adjustments to mix thoroughly. I increased the impact an action will make so it will take longer to decay.

Then I realized I had another issue because skipping a dose caused an issue because I would clear the state of the adjustment after the adjustment was over. Well skipping makes the pump stop much earlier lol and then usual code would kick in so I had to change how I did that a bit. Right now I'm just doing it at half past when dosing should be finished.

I was able to realize the last bug was happening when I graphed my dosing log and saw calcium was still increasing but alkalinity was not. After reviewing it all, I realized what I did. Even with that slight swing, we're only talking about a 5ppm difference between high and low.

Also, I feel like the instinct when it's doing too many extra dosings would be to reduce the amount I dose each time, but on the contrary, I think increasing it would be a better approach. It's taking too many doses to make a correction, maybe a slight bit more would help balance it faster.

03/07/19 17:01:51 7.86 dKH / 140 ppm (+0.00/+0)
03/07/19 19:12:42 7.81 dKH / 139 ppm (-0.05/-1)
03/07/19 21:23:53 7.82 dKH / 140 ppm (+0.01/+0)
03/07/19 23:35:15 7.82 dKH / 140 ppm (+0.00/+0)
03/08/19 01:46:14 7.82 dKH / 140 ppm (+0.00/+0)
03/08/19 03:57:26 7.82 dKH / 140 ppm (+0.00/+0)
03/08/19 06:08:39 7.82 dKH / 140 ppm (+0.00/+0)
03/08/19 08:19:53 7.86 dKH / 140 ppm (+0.04/+1)
03/08/19 10:31:20 7.90 dKH / 141 ppm (+0.04/+1)
03/08/19 12:42:38 7.90 dKH / 141 ppm (+0.00/+0)
03/08/19 14:52:26 7.90 dKH / 141 ppm (+0.00/+0)
03/08/19 17:03:28 7.86 dKH / 140 ppm (-0.04/-1)
03/08/19 19:14:35 7.86 dKH / 140 ppm (+0.00/+0)
03/08/19 21:25:40 7.81 dKH / 139 ppm (-0.05/-1)
03/08/19 23:36:43 7.77 dKH / 139 ppm (-0.04/-1)
03/08/19 23:36:43 7.77 dKH / 139 ppm (-0.04/-1)
03/09/19 01:47:34 7.71 dKH / 138 ppm (-0.06/-1) +
03/09/19 03:58:35 7.70 dKH / 138 ppm (-0.01/-0) +
03/09/19 06:09:48 7.73 dKH / 138 ppm (+0.03/+1) +
03/09/19 08:21:04 7.87 dKH / 141 ppm (+0.14/+3)
03/09/19 10:32:32 7.94 dKH / 142 ppm (+0.07/+1) -
03/09/19 12:44:00 7.98 dKH / 143 ppm (+0.04/+1) -
03/09/19 14:55:15 7.94 dKH / 142 ppm (-0.04/-1) -
03/09/19 17:06:25 7.95 dKH / 142 ppm (+0.01/+0) -
03/09/19 19:17:17 7.90 dKH / 141 ppm (-0.05/-1)

Average: 7.85 dKH / 140 ppm (+0.04/+1)

Minimum: 7.70 dKH / 138 ppm
Maximum: 7.98 dKH / 143 ppm
Deviation: 0.28 dKH / 5 ppm
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: kh monitor + variable dosing

Post by lnevo »

Ok, looks like I worked out all the kinks. I also discovered that when I was increasing my cal and alk, I was also increasing mag which I currently have disabled so I added a check that a supplement needs to be at least 1 before it's dosage get's increased. I fixed the delta issue and also another bug where I was updating my baseilne tracking. Because I was skipping a dose, it would never increase the baseline either, so my baseline was skipping and then when it was calculated again, it would come back to the correct value making it looked like the baseline was getting a dosing increase! Argh.
dosing-bl.png
dosing-bl.png (36.48 KiB) Viewed 20554 times
Anyway, it looks much better today. Here's some raw data tracking the delta and the actions I'm taking. I need to have my external script grab the value from the RA to track that too. On the RA I'm also comparing the value I receive from the KHG because there's a device and an analog to digital conversion going on to get that signal. I've had miss on that in the past.

03/15/19;20:12:40;7.78;7.8;139;READY;NONE;3
03/15/19;20:12:40;7.78;7.8;139;READY;NONE;2
03/15/19;22:23:30;7.74;7.7;138;READY;DOSE1;1
03/15/19;22:23:30;7.74;7.7;138;READY;NODOSE1;5
03/16/19;00:34:38;7.73;7.7;138;READY;NODOSE1;4
03/16/19;00:34:38;7.73;7.7;138;READY;NODOSE1;3
03/16/19;02:45:47;7.74;7.7;138;READY;DOSE1;2
03/16/19;02:45:47;7.74;7.7;138;READY;NODOSE1;6
03/16/19;02:45:47;7.74;7.7;138;READY;NODOSE1;5
03/16/19;04:56:48;7.78;7.8;139;READY;NONE;4
03/16/19;04:56:48;7.78;7.8;139;READY;NONE;3
03/16/19;07:06:21;7.78;7.8;139;READY;NONE;2
03/16/19;07:06:21;7.78;7.8;139;READY;NONE;1
03/16/19;09:17:27;7.82;7.8;140;READY;NONE;0
03/16/19;11:28:21;7.82;7.8;140;READY;NONE;0

It skipped the dose at 00:34 because the delta (4) was not less than my max which was also 4. I'm probably going to have to play with that as the time between tests is still too far apart to maybe rarely cause a skip yet. Still trying to rationalize the best way to get this part to function to prevent too many dosings or skippings.
sesame
Posts: 71
Joined: Sun Aug 04, 2013 2:29 am

Re: kh monitor + variable dosing

Post by sesame »

very interesting investgation.
a further more idea if its possible to control KH by RA by its own. :)
Post Reply