Author Topic: Pool chlorine pump control  (Read 297 times)

Offline jmassination

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Pool chlorine pump control
« on: July 25, 2017, 06:15:06 pm »
Hi, I just purchased a chlorine pump for my pool which basically pumps bleach into the pool (liquid chlorine). It is very precise/consistent, as in I know exactly how much bleach will be going in per minute of pump run time. My desire is to run this with Vera (I have a zwave switch on the way) and likely use the PLEG plugin to somehow intelligently control how long it runs. Here is the challenge....I need to have it run a different amount of time throughout the pool season. As in, in May, I plan to run it about 55 minutes, in June about 81 minutes, etc. I also sometimes will buy different bleach concentrations, sometimes with 6% chlorine, sometimes 8.25%, so the time it runs would need to be adjusted based on the concentration.

For the concentration, I've thought about using a virtual switch that I can toggle. So 6% on/off toggle. A 8.25% on/off toggle. So like if I currently am running 6%, I would have 6% toggle switch on, and 8.25% off.

As for the schedule, I'm struggling to think of the best way to do this in PLEG. One option would be to create a schedule for each month and each bleach concentration (6, 8.25). So in May I would have 2 schedules, one that runs for 55 minutes (6% bleach) and one that runs for say 45 minutes (8.25% bleach). Then I would have two conditions that would each only be true when the May schedule was on, and that particular bleach concentration was toggled on. But I'm also thinking of having it run the chlorine pump half the time in the morning, and the other half in the evening. So this could quickly get crazy with tons of schedules.

It seems it would be a lot cleaner to somehow create a single morning schedule and single evening schedule who's runtime is based upon the month and bleach concentration. Basically I would want it to do something like this in code:

if (month=May)
    if (bleach=6%)
        then run_time=55 min
    else run_time=45 min
elseif (month=June)
    if (bleach=6%)
        then run_time=81 min
    else.......etc

I dont believe you can have LUA code in a schedule, but I'm wonder if there would be a way to do this in LUA, but somewhere else. Like perhaps have one schedule that runs for the maximum time that I would ever need, but delay turning on the switch for a while based on the month. Ex: say the schedule runs like 90 minutes in July, but its May, so even though the schedule is "true" in PLEG for 90 minutes, the action delays getting triggered for 35 minutes into the schedule due to it being May.

Just thinking out load. Any ideas?

Offline Mike Yeager

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +6/-12
Re: Pool chlorine pump control
« Reply #1 on: July 26, 2017, 10:42:48 am »
You only need one virtual switch. If it's on, it's one concentration, off it's the other. This is actually quite easy for PLEG and there's no real need for LUA. Have you considered running the pump in short bursts every hour during a given time frame (schedule)? This would keep the pool much better balanced as well. My pool runs 24/7 but most don't so I can do things at 3am that others can't. I'd be happy to work with you on the logic once you decide for certain which way you want to go. One thing to keep in mind is that you will want a watchdog on the switch for the pump to ensure it isn't left running forever by a Vera restart. Unfortunately, they tend to occur without warning.... This is an easy task as well....

Offline jmassination

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Pool chlorine pump control
« Reply #2 on: July 26, 2017, 04:32:40 pm »
You only need one virtual switch. If it's on, it's one concentration, off it's the other. This is actually quite easy for PLEG and there's no real need for LUA. Have you considered running the pump in short bursts every hour during a given time frame (schedule)? This would keep the pool much better balanced as well. My pool runs 24/7 but most don't so I can do things at 3am that others can't. I'd be happy to work with you on the logic once you decide for certain which way you want to go. One thing to keep in mind is that you will want a watchdog on the switch for the pump to ensure it isn't left running forever by a Vera restart. Unfortunately, they tend to occur without warning.... This is an easy task as well....

Mike, I definitely welcome any help you have for me. A couple of details:
My pool runs from ~8-11am and then 4-7pm, so just 6 hours total. Its controlled by an intermatic mechanical timer. I have the chlorine pump wired to the same timer, so that the chlorine pump can only possibly be on when the pool pump is. So that would be my fail-safe in case Vera doesnt properly send the signal to turn off the chlorine pump. But that would still be bad if the chlorine pump ran for 6 hrs one day (dumping in about 2.5 gallons of bleach), so having a watchdog is a great idea. So I'd like to know what that takes.

As far as when to run the chlorine pump, my first idea was to run it in one burst during the 8-11am timeframe and a 2nd burst during the 4-7pm timeframe. But having a burst every hour like you mentioned would be just fine and maybe more ideal. Either way, I've got to come up with a strategy to limit the run time of each burst, whether it be the 2 bursts, or 6 bursts. And that limit would be based upon time of year, and chlorine concentration. Without using LUA of some sorts, the only thing I could think of would be to create lots of schedules like I mentioned. Which I guess isnt that big of a deal, but would require lots of re-work later (having to adjust each schedule) if I ended up having to adjust run times later.

Thanks for the help in this. I look forward to hearing what your ideas are.

Offline jmassination

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Pool chlorine pump control
« Reply #3 on: July 27, 2017, 04:55:18 pm »
Mike,
Here is my thoughts so far on how to use PLEG to have 6 dosages per day, one for each hour that the pool pump is running. I dont see a way to avoid lots of schedules and conditions. One thought is to use the "NOW > X.00" feature in the conditions to have it cut the pump off based on how long its been on...and a condition for each month/chlorine concentration.... but thats more processor intensive, and less precise since it only checks once per minute.

So I came up with this....

Create a few schedule types:

1. Create an "absolute" schedule for each pool month of any year (using * for the year). Basically the "May" schedule would be "true" between May1 and May31. So I'd create a schedule for May, June, July, Aug, Sept since we have the pool open those months only.
2. Create a "MainPoolPumpOn" schedule that is true from 7:30-10:30am and another one that is true from 4:30-7:30pm. (I would modify my intermatic timer to run the main pool pump during these hours)
3. For each month/bleach concentration: Create an "interval" schedule that happens every hour, on the top of the hour, and ends a specific number of minutes and seconds from when it started. So for May-6%, one schedule would start every hour, and end 9 minutes later. For May-8.25% another schedule would start every hour and end 6.5 minutes later. Repeat for June,July,Aug,Sept

Create these conditions (with "On" condition turning the pump and "Off" turning it off)
ON:
When these things are all true: Schedule "2" above is true and any schedule "3" is true. In other words: "Schedule 2 AND Schedule3-1(any of them would work since they all become true at the top of the hour)"
OFF:
Create an off schedule for each Month and Chlorine concentration. Ex, "OffMay6%: condition would look like "Schedule 2 AND Schedule 1 AND 6%(virtualSwitch status)  and !Schedule3-1"
Basically this means, The main pool pump is on, and its May, and its 6%, and the May6% schedule has expired or gone false


This is the best I have right now. Am I making this more work than I need to? I'm going for 2 things: 1. I want to be able to come back to this a year later and remember what the heck is going on with the logic. I have that problem sometimes...and have to study it for an hour to figure out how to revise something. 2. I want editing it to be easy. In reality I am just giving it my best estimate on how much chlorine will be needed each month, but reality is I might need to come back and adjust the monthly levels. If I realize I am not dosing enough bleach in general (or too much), I may need to adjust each month and each concentration. With my plan above that means adjusting 10 different schedules.
« Last Edit: July 27, 2017, 04:59:57 pm by jmassination »

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9572
  • Karma: +729/-136
    • RTS Services Plugins
Re: Pool chlorine pump control
« Reply #4 on: July 27, 2017, 11:19:04 pm »
The pure PLEG solution would not be pretty for something like this.

What you need is some LUA code that and that uses some LUA tables to  select the amount of time based on two inputs (month, and chlorine concentration).
You could get the chloring concentration from a PLEG input bound to a MultiString. The month you can get directly from LUA.
You could trigger this LUA code via actions (i.e. LUA attached to an action) and this LUA code could update the value of some other condition variable.

Then later in the actions, the PLEG start timer, could use the value of the this condition variable as its argument.

i.e.
Schedule:
ChlorineScheduler               On - Self trigger, Off Interval: 15:00

Conditions:
ChlorineScheduler              "15:00"
StartChlorine                     Your logic to decide when to start the pumb, i.e. based on some schedule.

Then add the LUA code for the actions for "StartChloring" that dynamically changes the "ChoringSchedule" value.
Then later in the actions it use the StartTimer action for the PLEG devices, with a timer of ChlorineScheduler and a value of {(ChlorineSchedule)}

But the LUA code dynamically sets the value of ChloringSchedule





« Last Edit: July 27, 2017, 11:21:20 pm by RichardTSchaefer »

Offline Mike Yeager

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +6/-12
Re: Pool chlorine pump control
« Reply #5 on: July 30, 2017, 01:29:08 pm »
Well, you only need one schedule for the pump itself. Have it fire every hour. If the system is off, it simply won't run. The condition will run, but the equipment will not. He may be right about the LUA making things easier. I haven't had much chance to get on the computer, much less think about coding anything. Been pretty busy lately. I was thinking down a different line but haven't had time to look into it. Variables are going to come into play but they can be modified by virtual devices, that would likely be a LUA task. The watchdog is easy, you simply compare the last "On" time to a preset length of time. If more than that time has passed, turn it off (and notify you, of course). I'll try to sit down over the next few days and outline what I'm thinking so I can spot the flaws... I'm sure they're there. My thoughts rarely translate straight to working code....

Offline jmassination

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Pool chlorine pump control
« Reply #6 on: July 31, 2017, 12:17:17 pm »
I couldnt make sense of everything RTS said, and I got antsy, so I went ahead and implemented an ugly PLEG with lots of schedules and conditions. haha. But the logic is working perfect and I made it so its super easy to adjust the dosage on the fly from my phone. I also made it pretty, see the screenshot below from the "ImperiHome" app of the toggle buttons/dashboard I made. I also attached a PDF of the PLEG in case anyone is curious.

But basically here is what I ended up doing.

I abandoned the idea of the chlorine dosage happening based on what month it is. I just feel like I would have to constantly make alterations to the PLEG as I realized my guess on pump run time was too much or too little. I went with an approach that allows me to set the amount of bleach thats going in and leave it there until I change it from my phone with a multiswitch (virtual switch), meaning I will never have to update the PLEG schedules or conditions at all. The idea kinda stems from the "Manual" dosage that we've been doing the past 3 years. Which entails, every morning going out and measure the chlorine levels (usually is between a 1 and a 4) and then adding enough bleach to bump it back up to a 5. So like right now, its usually around a 1.5 to 2 when we check it in the morning. So if I were to "automate" it for current time of year, I would have it auto-dose enough to bring it from a 1.5 to a 5 everyday. Then as the pool season winds down, manually adjust it on my phone as I see fit. So heres how I did it....

1. Created a multiswitch with 8 switches/toggles for the different "levels" of chlorine in the pool: 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5. Like manually measuring the levels as described above, the numbers represent that reading that we have been doing each morning. So right now I have "1.5" selected.
2. Created conditions/actions such that if any multiswitch toggle is switched on, it switches all others off (so that only one number can be toggled at a time)
3. Create a virtual switch for the bleach concentration (6%=on 8.25%=off)
4. Created a virtual switch that must be "on" for the chlorine pump to turn on (in case i ever want to disable it.... like if i need to shock the pool, etc)
5. Created 16 schedules for turning the pump on each hour, and then back off after a specified amount of time. 16 because its one for each of the 8 multiswitch toggles above at each of the two bleach concentrations. For example, if its 6% bleach and the level is set to "1.5", that schedule goes for 15:34. If I have the multiswitch set to "3.5", that schedule just goes for 6:45.
6. Created 16 conditions/actions for turning the pump off, based on each of the schedules above ending. Each one looks at the concentration toggle, multiswitch, and its corresponding schedule and only fires when everything lines up.
7. I also created a "boost" virtual switch so that I could manually, that day only, add a boost of extra bleach. I have a boost schedule and a boost condition that only fires when the boost virtual switch is on.
8. I also created a "Reduce" virtual switch. similar to above, it will for that day only, cancel the last 2 of the 6 daily doses.
Both of these (7 and 8 ) get automatically toggled back off after the "boost" or the "reduction" has completed. I mainly added these, because I anticipate that at times the auto-dosing is going to be a little too much or too little based on weather, but we may not want to adjust the level on the multiswitch.

Best of all, this all happens super easily from my phone. I've come to love the ImperiHome app and its Dashboards. Much better than using the Vera app in my option, or even the Imperihome app in its normal "flat device list" view.

« Last Edit: July 31, 2017, 12:57:07 pm by jmassination »

Offline Mike Yeager

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +6/-12
Re: Pool chlorine pump control
« Reply #7 on: July 31, 2017, 03:58:27 pm »
If it works for you, that's the most important thing. Best thing is, you know what you did and why, making it easier to tweak later if you need to. I would have probably just done one schedule and multiple conditions, but that's me. Just make sure you have a watchdog to catch the pump if it runs too long. I suggest that it notify you and possibly turn everything off until you check it out...

Offline jmassination

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: Pool chlorine pump control
« Reply #8 on: July 31, 2017, 04:06:14 pm »
I mainly went the route of lots of schedules because I'm worried (probably overly so) that a lot of "NOW > 15:00" type conditions is gonna cause a lot of processor strain. Since those basically cause the condition to re-evaluate itself every minute (times 16 for the different chlorine levels and concentrations). So that would be a lot of re-evaluating. I'm running a Vera-Lite with over 100 devices!  :). Probably time to upgrade, but it runs smooth for the most part and I'm worried the upgrade process is gonna be a pain in the rear.
« Last Edit: July 31, 2017, 04:07:56 pm by jmassination »

Offline Mike Yeager

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +6/-12
Re: Pool chlorine pump control
« Reply #9 on: July 31, 2017, 10:52:05 pm »
It would only evaluate the time condition of the currently active condition. Either way, the way that you get it to work is the best. Like I said, I haven't had the time to really begin to work on it.