# Ensuring x hours of light

We have chickens and in order to keep them laying through the winter, they need artificial light so that they have at least 12 hours of light. I want to setup an automation that ensures 12 hours of light year-round. I could trigger it to come on x hours before sunrise, but the time of daylight changes throughout the year.
I’m fairly new. How can this be done?
Here’s how I feel like it could work.

1. Use https://github.com/pnbruckner/ha-sun2 to get the hours of daylight
2. Take 12 - (hours of daylight) = x
3. Disregard negative numbers. If positive, turn the light on x hours before sunrise.
All help is appreciated!

• turn on light at 8:00
• turn off light at sunrise
• turn on light at sunset
• turn off light at 20:00

You can use also dawn&dusk instead of sunrise/set. Or use some lux meter for those middle ones.
You can also use “1 hour before sunrise” or similar for trigger.

There is a long topic on this which might be helpful

1 Like

That’s a brilliantly simple solution. Sunset - how many hours of sunlight you want as the offset for the trigger, and then turn off an hour after sunrise. I had something in mind using a delay, but that’s much cleaner. Love it.

Ah, thy Google-fu is stronger than mine!

Going to give it a go: Chicken eggs!

So I solved this a few months ago. And it works. My 6 hens now produce 6 eggs a day, EVEN IN WINTER. There are a few tricks to get there. After I get done at the vet I’ll post my automations. If you do this in the winter you have to sneak up on them. And a few other things which I’ll document.

Jeff

Here’s how I solved it, both for egg production as well as hot weather. Turns out cold, even freezing temps, doesn’t bother them so I got rid of the heat lamp.

Putting a light directly inside the coop didn’t work. As dumb as chickens are, they just moved outside the coop into the darkness. Once I figured this out, I added a second light to cover that area OUTSIDE the coop, on the same time schedule. You gotta be smarter than the average chicken to get them to lay the requisite one egg a day all year or why bother…

``````#turn on a sprinkler if it gets hot
- id: '1567839864112'
alias: Water on if hotter than 75
trigger:
- minutes: /30
platform: time_pattern
condition:
- condition: template
value_template: '{{ state_attr(''weather.house'', ''temperature'') | int>74}}'
action:
## the next script turns on a water valve for 1 minute that controls a sprinkler around the coop
- service: script.1567805755733
#
- id: '1569929226364'
alias: turn on egglights at sunset -16.00 hrs
#if you're doing this in the middle of winter, don't make a sudden change to light or else...
description: Increase by 15 min intervals each day until you reach -16:00:00
trigger:
- event: sunset
offset: '-16:00:00'
platform: sun
condition:
- before: sunrise
condition: sun
action:
- data: {}
entity_id: switch.egg_light_1
service: switch.turn_on
- entity_id: switch.egg_light_2
service: switch.turn_on
# ok the lights are now on for 16 hours but once the sun comes up, no need.
- id: '1569922898305'
alias: turn off egglights at sunrise +2hr
trigger:
- event: sunrise
offset: 02:00:00
platform: sun
condition: []
action:
- entity_id: switch.egg_light_1
service: switch.turn_off
- entity_id: switch.egg_light_2
service: switch.turn_off
# if it's cloudy out in the winter, make sure the chickens don't know it.
- id: '1577666848310'
alias: turn on eggllights at sunset -2 hours
description: ''
trigger:
- event: sunset
offset: '-2:00:00'
platform: sun
condition: []
action:
- entity_id: switch.egg_light_1
service: switch.turn_on
- entity_id: switch.egg_light_2
service: switch.turn_on
- delay: 2:00:000
- entity_id: switch.egg_light_1
service: switch.turn_off
- entity_id: switch.egg_light_2
service: switch.turn_off
#Egg Cam!!
- id: '1582012763487'
alias: Pan Egg Camera
description: ''
trigger: []
condition: []
action:
- data:
preset: 2
entity_id: camera.inside
service: amcrest.goto_preset
- delay: 00:00:07
#then put it back
- data:
preset: 1
entity_id: camera.inside
service: amcrest.goto_preset
``````

I also have chicken cam inside the coop. I set up 2 fixed presets so I can spin the camera to see if any of the nests have eggs. sometimes they move on me.

After Chicken Cam pans for 7 seconds it goes back to their “preferred nest”:

What I don’t have figured out is how to trigger an automation while watching the Amcrest stream. I need a css overlay of some kind to represent “Pan Chicken Cam” icon like in the first pic above. I have no idea how to do that, but it would be cool and be the next thing to do.

My wife thinks I’ve gone completely nuts, but is this cool or what? She likes the eggs, esp now in the winter. Now we need a Home Assistant “Egg Recognition Software Integration” to send an alert when an egg is detected in an image. I’ve thought thru this and the only way to really do it is to scan an image for objects shaped like an egg(s)…

Jeff

2 Likes

Have you tried deepstack and trained a model to recoginize eggs? I think Frigate has a model with egg detection or I’m mixing it with the Coral AI-thingy