[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;

    OFF>ON>ON-Day>ON>OFF

    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.

    upload-1bc70891-1832-479b-bedf-fc0792c9de8b

    upload-3ec9937b-c7df-45fd-ad5f-a613b5d2fe51

    upload-af8b6523-6ee8-4f7f-b420-95cc0371fa61

    upload-125085f6-125c-4a0c-ba7c-7ef1d86f0970

    The next part will be creating the URC Event Timer with start and stop times that I can use to set the React Variable.

    upload-420f8668-d2d7-4473-829c-c78dba3f7ba3

    upload-429fa7f1-64c1-4468-b42d-2471e6c6fe86

    upload-c31348d7-0546-4440-bb96-48e6829e5639

    upload-24cd4bd9-be71-4e58-9d0c-7d85c70976d2

    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.

    upload-6230516e-48d3-4601-955c-a7d7ad54c0a4

    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.

    Justin Spiniolas


  • 1
    Posts
    477
    Views
    Log in to reply

Internal error.

Oops! Looks like something went wrong!