Close

Initial code done

A project log for ESP8266 Reef Aquarium Meanwell Moonlight dimmer

I have a Neptune Apex controlled reef aquarium. I also have massive moonlight LED's over it, but the Apex can't control them. ESP8266 Can.

tim-rightnourTim Rightnour 12/16/2020 at 05:340 Comments

The circuit was dead easy.  Will upload schematic in a few days.

The coding was non-trivial.  Took about 2 days.  More or less, we need a few things:

First, we need the current lunar phase.  This wasn't super difficult.  I had to find the date and time of a known new moon.  Once I have that, I can calculate the difference between now, and that known moon, and divide by a lunar period.  Knock off the left of the decimal point, and we have what percentage we are in the current phase.  Then it's just simple math to get the illumination.

The hard part was talking to the Apex. There is a known undocumented json API on the Apex, that gives the states of all the outlets/inputs/etc.  The problem is it dumps 14k of data, which, when you try to read with the Async http client library, just chokes it, and then ArduinoJson can't allocate enough ram to deserialize it anyhow.  So I had to do a bunch of hackery to find the specific section of the json I wanted, cut it out, and then pass that into the json lib.

So now I have a pretty little box that calculates the moon phase, sets the illumination, multiplies it by what the Apex *thinks* the illumination should be, and then sets the potentiometer to that setting.

The idea is you code the Apex with profiles to ramp up/down to 100% at the beginning and end of the moon up, and use the apex to power on the Meanwell, but the ESP sets the actual brightness based on the phase.  So if we were at say 50% full moon:

The Apex determines the time is right to start the moon, so it powers on the outlet.

Then the ramp profile starts ramping up from 0% to 100% over say, 90 minutes, to simulate the rise.  However, the ramp profile isn't connected to a physical device at all.

Then we multiply that ramp setting by the lunar illumination.  So when the ramp says 100%, we are actually at 50%, because we are 50% of full moon.  The ESP sets the potentiometer, which is connected to the MeanWell, and the dimming is set to the proper number.

Now I just need to test it out.. woo..

Discussions