Auto Chicken Coop Door

Hey JT,

This is great stuff. I am an EE and a lot more experienced with C++ and Python, but will be using your code as soon as my coop gets built. Just finished painting the framework this morning.

BIG thanks for the info and once I get caught up I will gladly see if I can help out with some of the code optimization.

Glad to see someone on here to share code with and I have a lot more code to share, this is just the daylight portion. I know a tiny bit of C and C++ never seemed to have the motivation to go past that. I have written a DXF to G code conversion tool in Go Language that was interesting for sure but ended up being super fast. Are you planning on a automagic pop door and lights? Don't forget the ventilation and large overhangs as you build.

JT
 
You must have a CNC machine or maybe a 3D printer if you're doing DXF to G. Very jealous :)

And it takes a LOT of motivation to learn C++ - it can be such a tedious code. Powerful, but boring also!

I am planning on an auto door. Going to jerry rig something from a small motor. No way I'm paying the $250 for the ones on Amazon. I'm a cheap bastard lol when it comes to electronics that I can do myself.

Yes, going to do a long strip of LED lights which will be controlled by a Arduino R3. And since I'm in the Texas heat, a LOT of ventilation is needed. I've got ducks and chickens, so the new coop is going to be a ducken condo. Ducks on the first floor and the chickens right above them on the 2nd floor. Luckily, they are free range on 3 acres during the day. So that gives me a lot of flexibility on the style of coop I'm making. The entire coop will be under a 15'x25' heavy duty tarp to keep this crazy Texas heat off of the girls. Also, using the tarp as a way to catch as much rain as I can to a 90 gallon water retention barrel.
 
You must have a CNC machine or maybe a 3D printer if you're doing DXF to G. Very jealous :)

And it takes a LOT of motivation to learn C++ - it can be such a tedious code. Powerful, but boring also!

I am planning on an auto door. Going to jerry rig something from a small motor. No way I'm paying the $250 for the ones on Amazon. I'm a cheap bastard lol when it comes to electronics that I can do myself.

Yes, going to do a long strip of LED lights which will be controlled by a Arduino R3. And since I'm in the Texas heat, a LOT of ventilation is needed. I've got ducks and chickens, so the new coop is going to be a ducken condo. Ducks on the first floor and the chickens right above them on the 2nd floor. Luckily, they are free range on 3 acres during the day. So that gives me a lot of flexibility on the style of coop I'm making. The entire coop will be under a 15'x25' heavy duty tarp to keep this crazy Texas heat off of the girls. Also, using the tarp as a way to catch as much rain as I can to a 90 gallon water retention barrel.

Aye, I have a CNC machine shop and a fabrication shop and make my living with them.

Are you going to use the Arduino R3 to dim the lights at night simulating sundown? I've found the Raspberry Pi 3 to be a much more stable platform to do automation tasks. I have a box full of Arduino's and ESP8266's and other arduino type stuff and have spent a lot of time coding them but always come back to the single board computer.

The new coop sounds like an awesome place for the birds to live, I'm working on converting a 12' x 16' shed into a new walk in coop for my new Cinnamon Queens I'm getting in the spring.

JT
 
Trying to get back on topic... I refined the code this morning to be more inline with what will really happen when the Raspberry Pi 3 B boots up after a power cycle. I have reduced the logic to three tests to determine the current natural daylight, if daylight is increasing (from winter solstice to summer equinox) or decreasing (from summer equinox to winter solstice). Based on this information I can determine when to open the door and turn the lights on. The code is pretty slick.

Summer and Fall is the same test
If natural daylight is more than 10h and decreasing
Open door and turn on lights at dawn

Winter Test
If natural daylight is less than 10h and decreasing
Find the last date of 10h daylight
Add 5 minutes per day from that date

Spring Test
If natural daylight is less than 10h and increasing
Find the last date of 10h of daylight with daylight decreasing
Add 5 minutes per day from that date

The test output is based on dates set for each season:
Code:
pi@coop2:~ $ coop6 1
Summer Test Seed Date Jul 17 2018
Natural Light Today is 14:24:23
Dawn Today is 05:25 AM
Dusk Today is 08:49 PM
Door Opens at 05:25 AM
Light On at 05:25 AM
Total Light Today 14:24:23
Light Off at 06:55 AM
Door Closes at 08:49 PM
pi@coop2:~ $ coop6 2
Fall Test Seed Date Aug 17 2018
Natural Light Today is 13:31:22
Dawn Today is 05:52 AM
Dusk Today is 08:18 PM
Door Opens at 05:52 AM
Light On at 05:52 AM
Total Light Today 13:31:22
Light Off at 07:20 AM
Door Closes at 08:18 PM
pi@coop2:~ $ coop6 3
Winter Test Seed Date Dec 17 2018
Natural Light Today is 9:39:06
Dawn Today is 06:39 AM
Dusk Today is 05:15 PM
Last 10h Daylight was 24 days ago
Door Opens at 05:36 AM
Light On at 05:36 AM
Total Light Today 11:39:06
Light Off at 08:07 AM
Door Closes at 05:15 PM
pi@coop2:~ $ coop6 4
Spring Test Seed Date Jan 04 2019
Natural Light Today is 9:43:16
Dawn Today is 06:45 AM
Dusk Today is 05:26 PM
Light Start Date is Nov 23 2018, 42 days ago
Door Opens at 04:13 AM
Light On at 04:13 AM
Total Light Today 13:13:16
Light Off at 08:14 AM
Door Closes at 05:26 PM

And for the code curious folks:
Code:
#!/usr/bin/env python3

import sys
from datetime import datetime, timedelta
import pytz
import astral

localTz = 'US/Central'
centralTz = pytz.timezone('US/Central')
dateFormat = '%b %d %Y'
timeFormat = '%I:%M %p'
extraLight = 60

coordinates = ["Poplar Bluff", "USA", 36.763084, -90.413871, localTz, 110]
pbmo = astral.Location(info=(coordinates))
pbmo.solar_depression = "civil"

"""
Summer and Fall is the same test
If natural daylight is more than 10h and decreasing
    Open door and turn on lights at dawn

Winter Test
If natural daylight is less than 10h and decreasing
    Find the last date of 10h daylight
        Add 5 minutes per day from that date

Spring Test
If natural daylight is less than 10h and increasing
    Find the last date of 10h of daylight with daylight decreasing
        Add 5 minutes per day from that date
"""

localTz = 'US/Central'
centralTz = pytz.timezone('US/Central')
dateFormat = '%b %d %Y'
timeFormat = '%I:%M %p'
extraLight = 60 # extra light after sunrise
addLight = 5 # how many minutes per day to add light
totalLight = 840 # minutes of total light up to summer
minLight = 600 # minutes of natural light to start adding light

# coordinates = ['City', 'Country', 'latitude', longitude', 'timezone', 'elevation']
coordinates = ["Poplar Bluff", "USA", 36.763084, -90.413871, localTz, 110]
pbmo = astral.Location(info=(coordinates))
pbmo.solar_depression = "civil"


if len(sys.argv) == 1:
    test = input('Pick Test 1, 2, 3 or 4 ')

if len(sys.argv) > 1:
    test = sys.argv[1]

if test == '1':
    # Summer
    # test if natural daylight is greater than 14h
    testName = 'Summer'
    today = centralTz.localize(datetime(2018, 7, 17))

elif test == '2':
    # Fall
    # test if natural daylight is less than 14h, more than 10h and decreasing
    testName = 'Fall'
    today = centralTz.localize(datetime(2018, 8, 17))

elif test == '3':
    # Winter
    # test if natural daylight is less than 10h and decreasing
    testName = 'Winter'
    today = centralTz.localize(datetime(2018, 12, 17))

elif test == '4':
    # Spring
    # test if natural daylight is less than 14h and increasing
    testName = 'Spring'
    today = centralTz.localize(datetime(2019, 1, 4))

else:
    print('You gotta pick one test lol')

print('{} Test Seed Date {}'.format(testName, today.strftime(dateFormat)))

# start the test
todayEvents = pbmo.sun(today)
todayDawn = todayEvents['dawn']
todaySunrise = todayEvents['sunrise']
todaySunset = todayEvents['sunset']
todayDusk = todayEvents['dusk']
todayLight = (todaySunset - todaySunrise).total_seconds()

print('Natural Light Today is {}'.format(str(timedelta(seconds=todayLight))))
print('Dawn Today is {}'.format(todayDawn.strftime(timeFormat)))
print('Dusk Today is {}'.format(todayDusk.strftime(timeFormat)))

yesterday = today - timedelta(days = 1)
yesterdayEvents = pbmo.sun(yesterday)
yesterdaySunrise = yesterdayEvents['sunrise']
yesterdaySunset = yesterdayEvents['sunset']
yesterdayDaylight = ((yesterdaySunset - yesterdaySunrise).total_seconds())

# test 1 and 2 daylight is more than 10h and decreasing
if todayLight > (minLight * 60) and yesterdayDaylight > todayLight:
    doorOpen = todayDawn
    totalLight = todayLight

# test 3 daylight is less than 10h and decreasing
if todayLight < (minLight * 60) and yesterdayDaylight > todayLight:
    i = 1
    testDaylight = 0
    while testDaylight < (minLight * 60):
        daylightTestDate = today - timedelta(days = i)
        testEvents = pbmo.sun(daylightTestDate)
        testSunrise = testEvents['sunrise']
        testSunset = testEvents['sunset']
        testDaylight = (testSunset - testSunrise).total_seconds()
        i += 1
        if i > 100:
            print('WTF the while loop failed!')
            break
    days = (today - daylightTestDate).days
    print('Last 10h Daylight was {} days ago'.format(days))
    totalLight = todayLight + (days * (addLight * 60))
    doorOpen = todayDusk - timedelta(seconds=totalLight)

# test 4 daylight is less than 14h and increasing
if todayLight < (totalLight * 60) and yesterdayDaylight < todayLight:
    increasingLight = False
    i = 1
    lastTestDate = today
    while not increasingLight:
        currentTestDate = today - timedelta(days = i)
        events = pbmo.sun(currentTestDate)
        currentLight = int(((events['sunset'] - events['sunrise']).total_seconds()))
        lastEvents = pbmo.sun(lastTestDate)
        lastLight = int(((lastEvents['sunset'] - lastEvents['sunrise']).total_seconds()))
        if currentLight > lastLight and currentLight > 36000:
            days = (today - currentTestDate).days
            totalLight = todayLight + (days * (addLight * 60))
            doorOpen = todayDusk - timedelta(seconds=totalLight)
            print('Light Start Date is {}, {} days ago'.format(currentTestDate.strftime(dateFormat), days))
            break
        i += 1
        lastTestDate = currentTestDate
        if i > 60:
            print('WTF the while loop failed!')
            break

print('Door Opens at {}'.format(doorOpen.strftime(timeFormat)))
print('Light On at {}'.format(doorOpen.strftime(timeFormat)))
print('Total Light Today {}'.format(str(timedelta(seconds=totalLight))))

lightOff = todaySunrise + timedelta(minutes=extraLight)
print('Light Off at {}'.format(lightOff.strftime(timeFormat)))
print('Door Closes at {}'.format(todayDusk.strftime(timeFormat)))

JT
 
JT,

Thanks for the invite in the other thread.

OT for a moment: I don't know any code other than G&M (I'm a CNC programmer) but am very interested in learning python and playing around with a RaspberryPi. I'm in the early stages of it all. I haven't even built a coop yet, but want to incorporate some automation from the get go. Obviously you ran power to your coop...did you also run CAT5 or are you wireless? I think I'd like to have a hardwired data connection to my house, is CAT5 the best way to do it?
 
Not JT, but I can answer the Cat5 question. The progression on Network cables recently goes - Cat5 -> Cat5E - > Cat6 to finally the new speed & distance standard is Cat6A. Cat5 is about 30% less expensive than Cat6 and 60% less expensive than Cat6A.

The decided factors are: Are you running this JUST to the coop? If so, Cat5 will work awesome and be the cheapest. If 10 Gigabit speed is important (and not typically for any coop related functions - even a live cam) say you are running this cable out to your garage and coop, then go with Cat 6A if the distance from router to coop is just under 300 feet. Cat6 if your distance is less than 150 feet. Again, that is if you need 10 GB speed.

And....now that I read that you are in ND and if you are running this outdoors. My recommendation changes from the Cat5 to the Cat6 or Cat6A due to the cold. The thickness of the cabling on Cat6 is better insulated than Cat5. If you are going to run from house to coop outdoors and not burying the cable in conduit, then look for a cable with UV shielding and waterproof.

As far as Python goes, it's a pretty easy language to learn. I would suggest the following link for some awesome tutorials.

https://www.chalkstreet.com/python-...rce=Profiles&utm_medium=Quora&utm_campaign=rb

And please feel free to hmu if you have any questions. Good Luck on your coop build.
 

New posts New threads Active threads

Back
Top Bottom