Set lights to simulate sunrise and sunset

Hi
I have 2 dimmer outlets with dimmable halogenlights connected to them.
Now i want a better solution to simulate sunrise and sunset. Now i have 16 automation posts for each outlet

  1. Turn on light 10%
    2.torn on light 2 10%
    And so on
    This is something that takes a lot of time to administer since it is changing over time during the year.
    Is there any easier way to solve this?
    The timespann from 0% to max is about 3 hours, and the same in the other direction.

Post what you are currently using so we can get a better idea of how you are controlling the lights.

I would recommend the adaptive lighting custom component. Sounds like it should handle your needs.

https://github.com/basnijholt/adaptive-lighting

I am currently using a Nexa AD-147: Plug-in dimmer and a Shelly dimmer 2
The Shelly dimmer 2 is connected to a 12V halogen transformer and the Nexa is connected directly to 230V.

I should have been more precise. Post the automation(s) you are currently using.

1 Like

This is what one of them looks like…
Since i am a rookie and it is important that it works i did it the easiest way

alias: 'Nexadimmer  dimmer 10% ON 09:00 '
description: Nexadimmer dimmer 10% ON
trigger:
  - platform: time
    at: '09:00'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 10
mode: single

Maybe you can use this one?

It seems like that one is for switches. I also use outlets

Your automation triggers at 09:00 and sets the lights to 10% brightness. You want it to progressively increase the brightness to 100% over the next 3 hours?

At what time do you want it to start decreasing the brightness to zero?

Depending on the time of the year i want it to go to somewhere between 60-100%
15:00 it should start decreasing.

The challenge of helping you achieve your goal is the fact that you haven’t clearly defined the requirements. “Depending on the time of the year” cannot be represented as automation logic until you clarify it. Similarly, “somewhere between 60-100%” provides no guidance for how the value should be computed.

1 Like

Sorry about that.
What would be most simple is if i hade one automation with values and then i can change them myself depending of the time of the year, since all depends of the outside temperature etc.

That’s another requirement that was unknown to anyone until now.

It’s easy for me to create an automation that progressively increases, or decreases, a light’s brightness over a period of time (using repeat). However, I feel no matter what I create it won’t suit your requirements for the simple reason that they haven’t been fully explained yet.

Ok, sorry. I’ll try to explain.
I keep reptiles. I use this lights as hear source for them.
As i try to give them as natural environment as possible i hibernate them in the winter. But depending on the outside temps i decide if it is time to go all the way down to 5-8 degrees. In February-march i startup with a couple of hours of “sun” and increase it until July when i start slowly decrease it again.
It would be easy if i just hade one automation for ramp-up and one for down.
As it is now i have to manually go into 32 automations to change the values

Thank you, now understand the purpose of the lighting and why brightness varies depending on the time of year.

Perhaps if we can reduce that to a single automation, then you can change the times in one place.

I assume half of the 32 automations is for turning on the lights and the other half is for turning them off? If that’s the case, post at least four examples from each half so we can get an idea of when you sending the turn_on and turn_off commands.

Here is 4 on and 4 off:

alias: Nexadimmer långvägg dimmer 10% ON 09:00
description: Nexadimmer långvägg dimmer 10% ON
trigger:
  - platform: time
    at: '09:00'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 10
mode: single
alias: Nexadimmer långvägg dimmer 20% ON 09:20
description: Nexadimmer långvägg dimmer 20% ON
trigger:
  - platform: time
    at: '09:20'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 20
mode: single
alias: Nexadimmer långvägg dimmer 30% ON 09:30'
description: Nexadimmer långvägg dimmer 30% ON
trigger:
  - platform: time
    at: '09:30'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 30
mode: single
alias: Nexadimmer långvägg dimmer 40% ON 09:40 
description: Nexadimmer långvägg dimmer 40% ON
trigger:
  - platform: time
    at: '09:40'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 40
mode: single

Below is OFF

alias: Nexadimmer långvägg dimmer 80% OFF 15:00
description: Nexadimmer långvägg dimmer 80% OFF
trigger:
  - platform: time
    at: '15:00'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 80
mode: single
alias: Nexadimmer långvägg dimmer 70% OFF 15:20
description: Nexadimmer långvägg dimmer 70% OFF
trigger:
  - platform: time
    at: '15:20'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 70
mode: single
alias: Nexadimmer långvägg dimmer 60% OFF 15:40
description: Nexadimmer långvägg dimmer 60% OFF
trigger:
  - platform: time
    at: '15:40'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 60
mode: single
alias: Nexadimmer långvägg dimmer 50% OFF 16:00
description: Nexadimmer långvägg dimmer 50% OFF
trigger:
  - platform: time
    at: '16:00'
condition: []
action:
  - type: turn_on
    device_id: 437a1d28451e0c24166d17bc94b9f75a
    entity_id: light.varme_dimmer_langvagg
    domain: light
    brightness_pct: 50
mode: single

To get them in one automation would make my life so much easier
Thanks!

Based on what you posted, brightness changes by 10% every 10 minutes, except in the first 20 minutes when it changes by 10% (i.e. at 9:20 and 15:20).

Is there a special need for this initial longer time period (20 instead of 10 minutes)? Can it be simplified so that all time periods are the same duration?

1 Like

No, there is no need for that, as long as i can change it later :grinning:

In the following automation:

  • step_time represents the amount of time, in minutes, between each change of the light’s brightness. It is currently set to 10 minutes. You can change it to whatever interval you prefer.

  • step_pct represents the percent change of the light’s brightness for each step. It is currently set to 10 percent. You can change it to whatever amount you prefer.

  • The automation will trigger at 09:00(you can set it to whatever you want) and increases the light’s brightness by 10 every 10 minutes. It will do this ten times (the number of iterations is computed by count).

  • The automation will trigger at 15:00 (you can set it to whatever you want) and decreases the light’s brightness by 10 every 10 minutes. It will do this ten times (computed by count).

- alias: Nexadimmer långvägg dimmer
  variables:
    step_time: 10
    step_pct: 10
  trigger:
  - id: increase
    platform: time
    at: '09:00:00'
  - id: decrease
    platform: time
    at: '15:00:00'
  action:
  - repeat:
      count: "{{ (100 / step_pct) | round(0, 'ceil') }}"
      sequence:
      - variables:
          brightness: '{{ step_pct * repeat.index }}'
      - service: light.turn_on
        target:
          entity_id: light.varme_dimmer_langvagg
        data:
          brightness_pct: "{{ brightness if trigger.id == 'increase' else (100 - brightness) }}"
      - delay:
          minutes: '{{ step_time }}'

NOTE

This automation uses a repeat containing a delay statement. If you restart Home Assistant, or Reload Automations, while the delay is waiting, it will terminate the automation. That means it will stop increasing/decreasing the light’s brightness and the light will be left in its current state until the automation is triggered again. If that is unacceptable then the automation must avoid using a repeat with a delay.

Alternatives:

  1. Single automation with multiple Time Triggers
    Basically this is similar to what you have done, using 32 automations, except all times are in one automation. Its action will be complex because it has to determine what to do based on the triggered time. It is simplified slightly by creating two separate automations, one for increasing brightness and the other for decreasing it.

  2. Single automation with a Time Pattern Trigger
    Instead of specifying multiple Time Triggers, this one simply triggers every 10 minutes. Once again, the action will be complex because it has to determine what to do based on the triggered time.


EDIT

Corrections

  1. Fixed improper declaration of variables option.
  2. Fixed improper use of quotes in count's template.
2 Likes

Thanks mate!
Realy appreciate your work!
I tried to implement it with a blank blueprint, but i get error " Message malformed: Integration ‘’ not found"
When i tried to copy/paste to automations.yaml i get several error messages,
After alot of head scratch i have come this far: