I am new to Photon and new to coding. I am working on a DIY Pool Controller, and have made quite a bit of progress.
I am looking to set up some schedules that will run certain pumps, lights, valves, etc at various times and created the following code as a test.
The LED comes on via the relay it’s attached to at the set time, however, it does not turn off. I’m hoping someone can easily spot where I’ve gone wrong.
Also, is there a cleaner, easier way to accomplish the same thing? This code seems like it might get pretty hairy as I build out more complex schedules.
I actually looked at that library, but being a noob and by no means a coder, I wasn’t sure where to start. If you have some sample code or examples to point me towards, that would be great.
I basically just need to turn on/off various relays at certain times each day and add some logic to do some things based on weather, etc.
What's with these large numbers? I don't understand how the LED ever turned on in the first place, since Time.local() % 86400 will never be greater than either of those numbers.
const int timeActionOn = 16*3600 + 41*60 + 00; // hh+mm+ss
const int timeActionOff = 16*3600 + 42*60 + 00;
The actual times are fairly irrelevant, as I’m just testing the code. I’m changing it to be a few minutes after I flash the firmware just to make sure it’s working.
In the above case it was 4:41pm ON and 4:42pm OFF (not sure how to accommodate for Daylight savings, so I switched -6 to -5)
The relay is turning ON, but not OFF at the prescribed time. Sorry about the formatting!
If there is a better (i.e. easier) way to format the time, please let me know. I’m assuming that is what the time libraries accomplish.
In your if clause you set previousDay = Time.day(), but the else-if won’t execute unless previousDay != Time.day(). That’s why it never turns off (I assume the LED goes on when you write LOW).
You are correct that it will get hairier as you add more things to turn on and off. I would go with @bko 's suggestion, and use the Time Alarms library. There is an example .ino file with the library that shows you how to use it. It is very simple.