Countdown timer for relay

Community contributed apps
Post Reply
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Countdown timer for relay

Post by lnevo »

What is the port supposed to do. Just cause the code you posted is gonna run that port for 2 minutes every 6 hours.

Try and put the following before the if statement.

ReefAngel.Relay.Off(Box2_Port6);

Is that the port your using anyway? You have to change the code to use the correct port. I don't see any Box1 or other Box2 ports...
paperdesk
Posts: 173
Joined: Fri May 23, 2014 8:09 am

Re: Countdown timer for relay

Post by paperdesk »

Facepalm ;) I thought that having two boxes meant I had a box 1 and a box 2. After reading your comment I realized that box 1 is actually my second box. After that came together it was simple to change the time values and remove the "else" line and it's working perfectly. Thanks!
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Countdown timer for relay

Post by lnevo »

Awesome. Can you post your final code that you used.
paperdesk
Posts: 173
Joined: Fri May 23, 2014 8:09 am

Re: Countdown timer for relay

Post by paperdesk »

I ran into some issues last night, but think it's working now. I'll post the code once I'm sure it's stable and correct, just doing a little testing today.
Image
paperdesk
Posts: 173
Joined: Fri May 23, 2014 8:09 am

Re: Countdown timer for relay

Post by paperdesk »

Here's what I ended up with. It runs for one hour and repeats every two days. , I have to wait two days to be sure it actually repeats, but I think it will:

Code: Select all

  int repeat=2880; // in minutes
  int runtime=3600; // in seconds
  static time_t t;
  
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Box1_Port6)) {
    ReefAngel.Relay.Auto(Box1_Port6);
    t=now();
  }  

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Box1_Port6);
  } else {
    ReefAngel.DosingPumpRepeat(Box1_Port6,0,repeat,runtime);    
  }  
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Countdown timer for relay

Post by lnevo »

Cool and triggering manually is working? What are you automating here?
paperdesk
Posts: 173
Joined: Fri May 23, 2014 8:09 am

Re: Countdown timer for relay

Post by paperdesk »

Yep, when I toggle the relay from the app it opens the relay for the set amount of time (60 minutes currently) and shuts off again. It then runs automatically every two days for 60 minutes.

I'm using this code to control a solenoid on my RODI system. It refills my fresh water container on a regular basis and other containers on demand.

My fresh water container has a shut off float in it, but I overflowed other water containers too many times, so it's nice to have something that will shut off automatically.

I wonder if this function could be built into the app that would allow one to start a countdown timer for any relay, after which the relay would return to its normal function. Seems like something a lot of people would use, and would be a lot simpler than changing to code frequently.
Image
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Countdown timer for relay

Post by lnevo »

I have a class in the libraries called TimedPort that does this. I would recommend looking at the water level sensor module and then just using the WaterLevelATO function to control the solenoid.
Post Reply