Chicken eggs!

I know i need automations

I kind of thought that was only an example of what was needed at that moment based on the quoted portion of my last post which states to turn on an hour before sunrise & give them 15 hours of light.

to wit:

“Yes, I want to overlap and turn on an hour before sunrise and give the little guys 15 +/- hours of light. Each day.”

Exactly, yes!

My bad…not an hour before sunrise. X hours before sunrise so they have 15 hours total of light, bulb+sun.

Jeff

Exactly. Yes!

4-6. And with 9 hens I get about 5 eggs a day. So maintaining that will be critical to my well-being.

no problem really. But it does help people to help you to be as precise in the problem statement as you can as you did in your post above.

So as you are using Phil’s enhanced sun component and assuming you added sunset as a monitored condition then you can get the time to turn on the light by using the following template:

{{ (as_timestamp(states.sensor.sunset.state) | int - 54000) | timestamp_custom('%H:%M') }}

that will give you the time when it is 15 hours before the next sunset.

For me the result is ‘04:28’.

use that as a comparison to the actual time to trigger an automation.

Also you will need to set up the time sensor

the automation will look something like:

alias: turn on coop light
trigger:
  platform: template
  value_template: "{{ states.sensor.time.state == (as_timestamp(states.sensor.sunset.state) | int - 54000) | timestamp_custom('%H:%M') }}"
action:
  - service: switch.turn_on
    entity_id: switch.4857044184f3eb916030_2

then the light comes on at the set time before sunrise. then just have a regular automation to turn the light off at sunrise.

At least I think that should work.

And no need to worry about timers or input_datetime complexities.

Where I live, the longest day of the year provides over 15 hours of daylight. So simply offsetting 15 hours from sunrise sunset would mean the light is turned on after sunrise.

Perhaps the ‘turn on coop light’ automation needs a condition that ensures daylight hours are less than 15. If greater than 15, then the light doesn’t need to turn on.

1 Like

Good catch. I’ve never looked to see how long daylight is in the summer here.

so the modified automation would be:

alias: turn on coop light
trigger:
  platform: template
  value_template: "{{ states.sensor.time.state == (as_timestamp(states.sensor.sunset.state) | int - 54000) | timestamp_custom('%H:%M') }}"
condition:
  condition: template
  value_template: "{{states.sensor.daylight.state | int < 15 }}"
action:
  - service: switch.turn_on
    entity_id: switch.4857044184f3eb916030_2

I was think of something similar and the way I thought of the automations is :

Automation #1 : Turn ON the light at SUNSET, with an offset of -15 hours, and a condition that it is before SUNRISE
Automation #2 : Turn OFF the light at SUNRISE

Would that work ?

2 Likes

Maintaining that will be critical to your constipation :rofl:

Hang on, what balance is needed, if any e.g. should we just start 7.5 hours before noon? And off 7.5 hrs later? Then work out what to switch around the horizon transitions ? What are the predator criteria ? When are the predators most active ? Early evening or early morning? What overlap sunrise/sunset do you need with the daylight. Sunrise/sunset is still pretty bright. I only allow external lights on when sun lower than -4 degrees.
Do you have a dimmer, it it set with transitions? Would that be better or hard / on hard off

(noon is calculated as the sun’s highest point, not 12:00)

I think that this should be written up as a package and anyone should be able to use it we could call it care of chicken kind or cock for short. :rofl:

Too funny. You guys are a hoot. Care of Chicken Kind… my rooster would approve, but would that package name fly on Github?

I’ll try finity’s automation (thank you!) tomorrow and report back! Too hard to modify code on this iPad.

Jeff

I couldn’t wait… yaml config checks ok. Let’s see if it works tomorrow.

- id: '1569922898305'
  alias: turn on coop light with template
  trigger:
  - platform: template
    value_template: '{{ states.sensor.time.state == (as_timestamp(states.sensor.sunset.state)
      | int - 54000) | timestamp_custom(''%H:%M'') }}'
  condition:
  - condition: template
    value_template: '{{states.sensor.daylight.state | int < 15 }}'
  action:
  - data:
      entity_id: switch.4857044184f3eb916030_2
    service: switch.turn_on
  - after: sunrise
    after_offset: 01:00:00
    condition: sun
  - data:
      entity_id: switch.4857044184f3eb916030_2
    service: switch.turn_off

That just seems waaay too simple. Why wouldn’t this work? It’s a conditional based on sunset, not a timer so even if a restart happened, the condition would still be tested.

I’ll try it as well.

Jeff

1 Like

I was also thinking about it some more :wink:

If you don’t care if the light is on either before sunrise or after sunset you could easily just do something like this:

Trigger: CurrentTime = 15 - (Todays daylight in hours). Use this to turn on the light that many hours before sunrise.

Then turn off the light as soon as the sun is up.

In this case, you can easily make sure that your chickens always get 15h of light.
i.e.: Daylight Hours are 8h.
Sunrise is at 07:00

That would mean your automation would turn on the light @ 0:00 midnight (07:00 - ( 15:00 - 8:00 ))
And then turn off as soon as there is daylight at 7:00.

Another possibility would be a light sensor in the chicken coop :slight_smile: Then you just check for the light level and turn on the light if the light level is below a certain threshold and has not been above a certain threshold for 15h already.

that’s kind of what my template is doing, except it uses sunset instead of daylight hours.

But it’s not as simple as a strict numerical calculation because you have to convert everything to a datetime object the do the calculation, then compare it to the current time. Or convert the current time hour into a number to compare. but then how do you handle the minutes?

if you just do the “15 - hours” you get a number similar to what jazzmonger got in this post

And that can’t be used for comparison to the time now to cause the trigger.

That would probably work.

I didn’t think about using an offset of that many hours. I use offsets for stuff but mine are only minutes, not hours.

I’m happy to report this does indeed work and turns off an hour after sunrise. And it’s SIMPLE!!

- id: '1569929226364'
  alias: turn on egglight at sunset -15 hrs
  trigger:
  - event: sunset
    offset: '-15:00:00'
    platform: sun
  condition: []
  action:
  - data:
      entity_id: switch.4857044184f3eb916030_2
    service: switch.turn_on
  - after: sunrise
    after_offset: '1:00:00'
    condition: sun
  - data:
      entity_id: switch.4857044184f3eb916030_2
    service: switch.turn_off

Thanks to everyone who cared deeply about my eggs! I learned a few things along the way as well.

4 Likes

So the automation turns on the light 15 hours before sunset then turns it off 1 hour after sunrise. That’s it, that’s all.

The joke’s on us. This lengthy thread was all about accurately interpreting your requirements and precisely controlling the light’s duration (to the minute). In contrast, your chosen solution allows the light to remain on for a full hour after sunrise … or so it seems?