[WalkThrough] - Aquarium Lighting Logic
This is an exercise in React programming. There may be many other ways to accomplish this task, but this is a relatively simple way to do it using React Logical Programming.
Lets start off by describing the situation and what I was looking to accomplish. Then we will set in on how I went about doing it using React.
The scenario is a salt water aquarium with 2 sets of LED lighting. The first is a single set of actinic lights. The second is a group of an identical set of actinic combined with a 50/50 mix of actinic and 12k daylight. The idea is that all 3 lights simulate daytime light for the aquarium. Instead of harsh on/off cycle, the single set comes on an hour early and shuts off an hour late. This gives the aquarium dwellers a more natural sunrise/sunset type cylce. Both sets are controlled using Lutron Ra2 appliance switches in order to provide integration to my home automation system.
Now for what I wanted to accomplish. I wanted to be able to adjust the cycle times using URC Event Timers so that they could be easily manipulated. Next I wanted to be able to override the cycle and force the complete daylight setup manually from any URC interface. And finally I wanted it to be able to return to the cycle by toggling the button on the URC interface. Also I wanted the natural cycle to take back over if no action was taken after the manual override.
In order to accomplish this, I was going to need to track some logic as to what state of the cycle it was in. As I said earlier, this could be done many ways. But how I chose to do it was to hold logic in a React Variable. Later you will see how this greatly helps me in achieving my goals. The cycle was pretty simple;
NO LIGHTS>SINGLE ACTINIC>ALL LIGHTS>SINGLE ACTINIC>NO LIGHTS
Or in the variable, it looks like this;
The first part will consist of creating the 4 Device Events needed to control the 2 sets of lights. On for each set, on and off.
The next part will be creating the URC Event Timer with start and stop times that I can use to set the React Variable.
The final part will be with programming a single button on a URC interface that will toggle between All On and back to its regular cycle. This is where React really shines. This is also the reason I chose "becomes or remains" in my React Logic Option. What I want to have happen is if I press my Aquarium Lighting button and the lights are not All On then I want them to turn on. But if they are All On, then I want them to return to whatever place they should be in their daily cycle. This will first require a query of the Day Lights to see if they are active or not. Then we can use a simple conditional in order to control which part of the toggle should happen. If they are off, we are going to send the direct commands to turn everything on. The reason I am doing it this way is so as to not disturb the React variable. Then on the other side of the toggle, I can just "Refresh" the React Variable which will trigger the appropriate events in order to get the lights back into cycle.
Hopefully this little demonstration will help provide some insight into the power of using React. Please feel free to post any questions or hit me direct on HipChat for help with anything Dash related.last edited by Spin