How to limit daylighttime?

Hello, folks
I have a slight problem figuring out the terrarium lights on/off.
Optimal light conditions for veiled chameleon is 10-12 hrs regarding of the season. First I thought to use a sunset/-rise, but here in Finland our days are from 6hrs to 20hrs so cannot be used as is.
What would be the easiest way to limit this time of light?
Let’s say I want the light to be on from 9am to 7pm at winter (10hrs) and 8am to 8pm at summer (12 hrs) and between it could follow the sunrise/-set.
I have figures some solutions, but those are quite complicated. I think there must be easier way to do it.
thx

Ok, I try to be more exact.

Turning on the light could be done with three different automations:

  1. Turn on at 8am if the sun has risen
  2. Turn on at sunrise if the clock has past 8am
  3. Turn on at 9am

And turning off:

  1. Turn off at 7pm if the sun has set
  2. Turn off at sunset if the clock has past 7pm
  3. Turn off at 8pm

Is there a possibility to merge all these to one (or two if turn on and off are separated) automation?

I think I would use two automations. Trying to get the turn on & turn off triggers along with conditions would be too confusing. Sometimes simplicity is best.

based on your second post (which is somewhat technically different than your first post) you could do this:

trigger:
  - platform: time
    at: '08:00:00'
  - platform: sun
    event: sunrise
  - platform: time
    at '09:00:00'
condition:
  condition: or
    conditions:
      - "{{ now().hour >= 8 and is_state('sun.sun', 'above_horizon') }}"
      - "{{ now().hour >= 9) }}"
action:
  <turn_on_action>

that way if the sun is up at 0800 it turns on the light. if it’s not and it gets to sunrise then it turns on the light and if neither are true then it turns on the light at 0900.

then for the turn off automation:

trigger:
  - platform: time
    at: '19:00:00'
  - platform: sun
    event: sunset
  - platform: time
    at '20:00:00'
condition:
  condition: or
    conditions:
      - "{{ now().hour >= 19 and is_state('sun.sun', 'below_horizon') }}"
      - "{{ now().hour >= 20) }}"
action:
  <turn_off_action>

and this one will do the exact opposite - turn off if the sun is down at 7, if not then turn off at sunset, or if sunset is after 8 it will turn off at 8.

I haven’t fully tested it but I think it should do what you want.

Thanks, mate
Sometimes writing the problem down gives an idea :slight_smile:
I’ll try this one and let you know how it goes.

You also have the option of using the newfangled way to specify multiple times in a single Time Trigger. The end-result is bit more compact.

trigger:
  - platform: time
    at: 
      - '19:00:00'
      - '20:00:00'
  - platform: sun
    event: sunset
1 Like

I also just noticed a typo in the code…

Add a colon (:) to the second “at” in both automations.

Noticed this also. Never mind the typos…
Yesterday the sun rose here exactly at 9:00, so strangely nothing happened. But everything worked as a charm yesterday at 19:00 and today at 8:58.
So I fine tuned the firing one minute past and I’ll see at the autumn does this work :smiley:
“Thank you for your co-operation. Good night.” -RoboCop

1 Like