Newbie Code Q: Using Defer and two virtual outlets

  • Thread starter Thread starter mike550
  • Start date Start date
  • Tagged users Tagged users None

mike550

Valuable Member
View Badges
Joined
Oct 13, 2019
Messages
2,269
Reaction score
2,328
Location
Chicago
Rating - 0%
0   0   0
Hello Apex gurus,

I’m trying to get my head around Apex programming and using the Defer statement. Right now, I’ve created (or shamelessly copied from @SuncrestReef — thank you) the following code for my return pump:

If Output Maintenance = ON then OFF
Defer 000:05 Then OFF


The use of the Defer statement is so that my ATO (Tunze) turns off before the pump so I don’t trip the ATO alarm as the sump fills with water. But here is my question, if I create another virtual outlet “Emergency” and want it to turn off the pump it would look like this.

If Output Maintenance = ON then OFF
Defer 000:05 Then OFF
If Output Emergency = ON then OFF


If I understand the Apex DEFER code correctly, it will be used regardless of where it lines up in the code. So basically even if Emergency = ON the pump will still wait 5 seconds before turning off. Is that correct? Is there a simple way around this?

Thanks in advance!
 
Yes, Defer is applied after all conditions have been evaluated. To get around this for your particular situation, create an additional virtual output for the return pump where you can place the Defer delay rather than on the pump itself:

[Pump_Maint] — virtual output
Set OFF
If Output Maintenance = ON Then ON
Defer 000:05 Then ON

[Pump]
Fallback ON
Set ON
If Output Pump_Maint = ON Then OFF
If Output Emergency = ON Then OFF
 
Yes, Defer is applied after all conditions have been evaluated. To get around this for your particular situation, create an additional virtual output for the return pump where you can place the Defer delay rather than on the pump itself:

[Pump_Maint] — virtual output
Set OFF
If Output Maintenance = ON Then ON
Defer 000:05 Then ON

[Pump]
Fallback ON
Set ON
If Output Pump_Maint = ON Then OFF
If Output Emergency = ON Then OFF
Thanks for this. So basically like a subroutine for the Defer code. Much appreciated.
 

HOW MUCH DOES A FISH’S FEEDING REQUIREMENTS AFFECT YOUR STOCKING DECISIONS?

  • A lot! - I avoid fish that require frequent or specialized feeding

    Votes: 7 23.3%
  • Quite a bit, but an automatic feeder can change my answer

    Votes: 5 16.7%
  • It depends on whether my nutrient export can handle it

    Votes: 5 16.7%
  • It depends on how badly I want the fish

    Votes: 10 33.3%
  • Not much. I’m willing to adjust my routine

    Votes: 7 23.3%
  • Not at all. Feeding demands don’t limit my stocking choices

    Votes: 5 16.7%
  • I usually learn about the demanding feeding schedule after buying the fish!

    Votes: 2 6.7%
  • I haven’t really considered this before

    Votes: 3 10.0%
  • Something else (see my comments in the thread)

    Votes: 0 0.0%
Back
Top
Home
Post thread…
Market
What's new