~travisshears/sewa-reef-controller

0bbf4236f32ca7b2d9c560830ce40be3601f6854 — Travis Shears 2 months ago c3ca70f master
add t5 lights
M .gitignore => .gitignore +1 -0
@@ 1,2 1,3 @@
log.txt
.DS_Store
.vscode

M CIRCUITPY/aquarium_controller/lights.py => CIRCUITPY/aquarium_controller/lights.py +45 -5
@@ 1,4 1,5 @@
import digitalio
from math import ceil

from adafruit_debouncer import Debouncer



@@ 31,15 32,54 @@ class Lights:

    def _on_rtc_msg(self, rtc_msg):
        dt = rtc_msg['dt']
        current_sec = (dt.tm_hour * 3600) + (dt.tm_min * 60) + dt.tm_sec
        self._handle_refigium_light(current_sec)
        self._handle_refigium_light(dt)
        self._handle_t5_lights(dt)

    def _handle_refigium_light(self, dt):
        current_min = (dt.tm_hour * 60) + dt.tm_min
        pwr_status = False
        if 1260 < current_min or current_min < 420: # 21 - 7
            pwr_status = True

    def _handle_refigium_light(self, current_sec):
        pwr_status = 32400 <= current_sec <= 75600 # 10 - 21
        self.core.publish('pwr', {
            'code': 'refigium_light',
            'prio': normal_sim_prio,
            'value': not pwr_status,
            'value': pwr_status,
        })
    
    def _handle_t5_lights(self, dt):
        # 11 - 18, 7h
        year = dt.tm_year
        day = 0
        for i in range(dt.tm_mon-1):
            if i%2 == 0:
                day += 30
            else:
                day += 31
        day += dt.tm_mday

        hour = dt.tm_hour
        minute = dt.tm_min
        current_min = (hour * 60) + minute
        pwr_status = False
        if year == 2022 and (192 < day < 283): # run custom schedule, 91 days
            # 0h july 9th, ~192nd day of the year
            # full 7h, ~283nd day of the year
            daily_minute_addition = 4.615
            day_of_schedule = day - 192
            run_time = ceil(daily_minute_addition * day_of_schedule)
            half_run_time = run_time // 2
            start_time = 870 - half_run_time
            end_time = 870 + half_run_time
            if start_time < current_min < end_time:
                pwr_status = True
        elif 660 < current_min < 1080: # run for 7h starting at 11
            pwr_status = True

        self.core.publish('pwr', {
            'code': 't5_light',
            'prio': normal_sim_prio,
            'value': pwr_status,
        })

    def update(self):

M CIRCUITPY/aquarium_controller/power.py => CIRCUITPY/aquarium_controller/power.py +9 -18
@@ 20,7 20,8 @@ _default_power_state = {
    # 'test_pin': False
    'refigium_light': False,
    'cabinet_light': False,
    'main_pump': True, # carbon_reactor will mirror main_pump via powerstrip
    't5_light': False,
    'main_pump': True, # carbon_reactor and sump dosing chamber pump will mirror main_pump via powerstrip
    'power_head_1': True,
    'power_head_2': True,
    'power_head_3': False,


@@ 44,13 45,14 @@ def _get_pin(b):

def power(core):
    pins = {
        'refigium_light': board.GP27,
        'power_head_1': board.GP28,
        'power_head_2': board.GP22,
        'power_head_3': board.GP21,
        'power_head_4': board.GP20,
        'refigium_light': board.GP28, 
        'power_head_1': board.GP27, # lower left 
        'power_head_2': board.GP22, # upper left
        'power_head_3': board.GP21, # lower right
        'power_head_4': board.GP20, # upper right
        'main_pump': board.GP19,
        'cabinet_light': board.GP26
        'cabinet_light': board.GP26,
        't5_light': board.GP18
    }

    # init prios


@@ 58,17 60,6 @@ def power(core):
    for key in _default_power_state:
        prio_holds[key] = base_prio

    left_over_pins = [
        board.GP18,
        # board.GP19
    ]

    # turn on all left over outlets
    for pin in left_over_pins:
        d = digitalio.DigitalInOut(pin)
        d.direction = digitalio.Direction.OUTPUT
        d.value = _set_pin(True)

    # transform pins into digitalio pins
    for key in pins:
        pin = pins[key]

M CIRCUITPY/aquarium_controller/rtc.py => CIRCUITPY/aquarium_controller/rtc.py +2 -2
@@ 12,6 12,6 @@ class RTC:
        self.core.publish("rtc time", {"dt": dt})
    def set_time(self):
        return; # comment out to set time
        dt = time.struct_time((2022, 7, 27, 23, 9, 0, 0, -1, -1))
        dt = time.struct_time((2022, 7, 29, 17, 58, 0, 0, -1, -1))
        print(f"Setting time to: {dt}")
        self.rtc.datetime = dt
        self.rtc.datetime = dt
\ No newline at end of file

M CIRCUITPY/code.py => CIRCUITPY/code.py +1 -1
@@ 15,7 15,7 @@ from aquarium_controller.power import power, id_outlets, master_power_switch, no
from aquarium_controller.flow import flow_sim
from aquarium_controller.lights import Lights

ver = '1.3.0'
ver = '1.4.0'

def util_mode(core):
    def change(mode):

M README.md => README.md +1 -1
@@ 8,4 8,4 @@ More info in [this blog post](https://travisshears.com/blog/sewa-reef-controller

## Name

Сева, Sewa in English, is the name of one of my first fish saltwater fish a Foxface Rabbitfish.
Сева, Sewa in English, was one of the first inhabinice of the tank. He is a Foxface Rabbitfish.