Sunrise Simulator. Wake up gently to light

The script will not turn off the lamps (normally you need light after you wake up…), you should do that on your automation.

The behaviour you described is very strange and I think it has to do with how your lamps work (maybe they have a 100% dim as default, when they turn on).

The script starts working on the moment you call it. It doesn’t know when your alarm rings… You should check your automation why it calls the script 2 min before your alarm

I love the idea of this script. But when I put it in an automation, all my lights (hue and govee) flash bright white between each step. What am I doing wrong?

alias: Sunrise Simulator Manual
sequence:
  - parallel:
      - if:
          - condition: template
            value_template: "{{ wled | count > 0 }}"
        then:
          - repeat:
              for_each: "{{ wled }}"
              sequence:
                - service: light.turn_on
                  data:
                    effect: Sunrise
                  target:
                    entity_id: |
                      {{ repeat.item }}
                - service: number.set_value
                  data:
                    value: "{{ [(255 * (maxbri/100)) | int, 255] | min }}"
                  target:
                    entity_id: |
                      {{ device_entities(device_id(repeat.item))
                            | select('search', 'number.')
                            | select('search', 'intensity')
                            | list }}
                - service: number.set_value
                  data:
                    value: |
                      {{ [dur, 128] | min }}
                  target:
                    entity_id: |
                      {{ device_entities(device_id(repeat.item))
                            | select('search', 'number.')
                            | select('search', 'speed')
                            | list }}
      - if:
          - condition: template
            value_template: "{{ bright | count > 0 }}"
        then:
          - repeat:
              while:
                - condition: template
                  value_template: |
                    {{ repeat.index <= maxbri
                          and not ( repeat.index > 1 
                                             and states.light
                                                        | selectattr('entity_id', 'in', bright)
                                                        | selectattr('state', 'eq', 'on') | list | count 
                                                      ==  0 ) }}
              sequence:
                - variables:
                    bright: |
                      {% if repeat.index > 1 %}
                        {{ expand(bright)
                              | selectattr('state', 'eq', 'on')
                              | map(attribute = 'entity_id')
                              | list }}
                      {% else %}
                        {{ bright }}
                      {% endif %}
                - service: light.turn_on
                  data:
                    transition: |
                      {{ ( ( dur * 60 ) / (maxbri) ) | int }}
                    brightness_pct: |
                      {{ [maxbri, ((repeat.index * maxbri) / 100)] | min }}
                  target:
                    entity_id: |
                      {{ bright }}
                - delay:
                    milliseconds: |
                      {{ (  ( ( dur  * 60 ) / (maxbri) ) * 1000
                       ) | int }}
      - if:
          - condition: template
            value_template: "{{ temp | count > 0 }}"
        then:
          - repeat:
              while:
                - condition: template
                  value_template: |
                    {{ repeat.index <= 100
                          and not ( repeat.index > 1 
                                             and states.light
                                                        | selectattr('entity_id', 'in', temp)
                                                        | selectattr('state', 'eq', 'on') | list | count 
                                                      ==  0 ) }}
              sequence:
                - variables:
                    step: "{{ repeat.index }}"
                    temp: |
                      {% if repeat.index > 1 %}
                        {{ expand(temp)
                              | selectattr('state', 'eq', 'on')
                              | map(attribute = 'entity_id')
                              | list }}
                      {% else %}
                        {{ temp }}
                      {% endif %}
                - repeat:
                    for_each: "{{ temp }}"
                    sequence:
                      - service: light.turn_on
                        data:
                          transition: |
                            {{ ( ( dur * 60) / 100 ) | int }}
                          brightness_pct: |
                            {{ [ ((step * maxbri) / 100) | int, maxbri] | min }}
                        target:
                          entity_id: |
                            {{ repeat.item }}
                      - service: light.turn_on
                        data:
                          color_temp: >
                            {% set max = state_attr(repeat.item, 'max_mireds')
                            %} {% set min = state_attr(repeat.item,
                            'min_mireds') %} {% set dec = (max-min) / 100 %} {{
                            iif( step < 100, ( max - (dec * (step - 1) ) ) |
                            int, min ) }}
                        target:
                          entity_id: |
                            {{ repeat.item }}
                - delay:
                    milliseconds: |
                      {{ (  ( ( dur  * 60 ) / 100 ) * 1000
                       ) | int }}
      - if:
          - condition: template
            value_template: "{{ color | count > 0 }}"
        then:
          - repeat:
              while:
                - condition: template
                  value_template: |
                    {{ repeat.index <= 100
                          and not ( repeat.index > 1 
                                             and states.light
                                                        | selectattr('entity_id', 'in', color)
                                                        | selectattr('state', 'eq', 'on') | list | count 
                                                      == 0 ) }}
              sequence:
                - variables:
                    color: |
                      {% if repeat.index > 1 %}
                        {{ expand(color)
                              | selectattr('state', 'eq', 'on')
                              | map(attribute = 'entity_id')
                              | list }}
                      {% else %}
                        {{ color }}
                      {% endif %}
                - service: light.turn_on
                  data:
                    transition: |
                      {{ (  ( dur * 60 ) / 100  ) | int }}
                    brightness_pct: >
                      {{ [((repeat.index * maxbri) / 100) | int , maxbri] | min
                      }}
                  target:
                    entity_id: |
                      {{ color }}
                - service: light.turn_on
                  data:
                    rgb_color: |
                      {% if repeat.index <= 20 %}
                        [255,0,0]
                      {% elif repeat.index <= 40  %}
                        [255,77,0]
                      {% elif repeat.index <= 60 %}
                        [255,103,0]
                      {% elif repeat.index <= 80 %}
                        [255,129,0]  
                      {% else %}
                        [255,167,0]
                      {% endif %}
                  target:
                    entity_id: |
                      {{ color }}
                - delay:
                    milliseconds: |
                      {{ (  ( ( dur * 60 ) / 100 ) * 1000 ) | int }}
variables:
  dur: |
    {{ duration | default(10, true) | int(10) }}
  entities: |
    {% if target is defined %}
      {% if target in states.light 
                         | rejectattr('state','in', ['unavailable', 'unknown', None])
                         | selectattr('attributes.supported_color_modes', 'defined')
                         | rejectattr('attributes.supported_color_modes', 'eq', None)
                         | map(attribute='entity_id') 
                         | map('area_name')
                         | list %}
        {% set target = area_entities(target) %}
      {% endif %}
      {{ expand(target)
            | selectattr('domain', 'eq', 'light')
            | selectattr('attributes.supported_color_modes', 'defined')
            | rejectattr('attributes.supported_color_modes', 'eq', None)
            | rejectattr('state', 'in', ['unavailable', 'unknown', None])
            | map(attribute='entity_id')
            | list }}
    {% elif cct is not defined
        and brightness is not defined %}
      {{ states.light 
               | rejectattr('state','in', ['unavailable', 'unknown', None])
               | selectattr('attributes.supported_color_modes', 'defined')
               | rejectattr('attributes.supported_color_modes', 'eq', None)
               | map(attribute='entity_id') 
               | list }}
    {% endif %}
  bright: |
    {{ expand(entities)
          | selectattr('attributes.supported_color_modes', 'eq', [ 'brightness'])
          | map(attribute='entity_id')
          | list + expand( brightness | default([], true) )
                      | rejectattr('state', 'in', [ 'unavailable', 'unknown', None ])
                      | rejectattr('entity_id', 'in', entities)
                      | selectattr('attributes.supported_color_modes', 'defined')
                      | selectattr('attributes.supported_color_modes', 'search', 'brightness')
                      | map(attribute='entity_id')
                      | list  }}
  temp: |
    {{ expand(entities)
          | selectattr('attributes.supported_color_modes', 'eq', [ 'color_temp'])
          | map(attribute='entity_id')
          | list + expand( cct | default([], true) )
                      | rejectattr('state', 'in', [ 'unavailable', 'unknown', None ])
                      | rejectattr('entity_id', 'in', entities)
                      | selectattr('attributes.supported_color_modes', 'defined')
                      | selectattr('attributes.supported_color_modes', 'search', 'color_temp')
                      | map(attribute='entity_id')
                      | list }}
  wled: |
    {{ integration_entities('wled')
          | select('in', expand(entities)
                            | selectattr('attributes.effect_list', 'defined')
                            | selectattr('attributes.effect_list', 'search', 'Sunrise')
                            | map(attribute='entity_id')
                            | list)
          | list }}
  color: |
    {{ entities | reject('in', temp + wled + bright) | list  }}
  maxbri: >
    {% set bri = max_brightness | default(100, true) | int(100) %} {{ bri if bri
    < 100 else 100 }}
mode: single
icon: mdi:weather-sunset-up

And here’s the automation code

alias: Sunrise color wakeup for Hans
description: ""
trigger:
  - platform: time
    at: "05:30:00"
condition: []
action:
  - service: script.1710176205775
    data:
      duration: 10
      target:
        - light.hans_wakeup_lights
      max_brightness: 100
mode: single

Nothing seems wrong at first sight.
Mind sharing the type of your lamps?

First of all…Thanks for your code!

But I also have some probs :slight_smile:

I also have a govee lightstrip

these are the attributes of the light

this is my automation


alias: New automation
description: Wake up light
trigger:
  - platform: time
    at: input_datetime.velux_invoer_uur
condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: "on"
action:
  - service: script.1710346218638
    data:
      duration: 10
      target:
        - light.slaapkamer_wakeuplight
      brightness: 100
mode: parallel

and script copied from the last post of LizL

my ledstrip starts in a kind of orange, 2 seconds later in a dark red and doesn’t change anymore :frowning:

where Am I wrong

I have just used the script (also copied the code from Liz and not from original post) and it works as intented.
Some ideas to troubleshoot yours:

  • You may have an automation that controls that light and stops the procedure (please examine your trace on the script)
  • The software from the govee stops somehow reacting
  • The light goes unavailable
  • There are some errors tha stop your script

It is very hard to make the script compatible for everyone since there are are tons of hardware out there and I can’t test them all…

Hope you find a solution :slight_smile:

Thanks for thinking about it, but it looks it doesn’t work for me.
When I start it, I don’t get the orange anymore, only the dark red

this errors are in the log

None (<class ‘custom_components.govee.light.GoveeLightEntity’>) does not set supported color modes

Entity None (<class ‘custom_components.govee.light.GoveeLightEntity’>) is using deprecated supported features values which will be removed in HA Core 2025.1. Instead it should use <LightEntityFeature: 19> and color modes

The govee custom component you have should be updated to set supported color modes as the error says…
Check if there is an available update. That could be the reason why the script stops

Actually it should already work since the error will be relative on 2025.1
Something seems to bother the light and it goes unavailable…

I think the problem is the polling interval

https://www.reddit.com/r/Govee/comments/w9hwii/help_recommended_api_polling_interval/

" You are allowed a total of 60 API calls a minute. So you have to divide that among your number of lights (60 / 6 = 10 calls per light, per minute), but that’s just for current status. You also need some headroom to actually send commands."

Yes that seems to be a problem… If it is true, it’s a govee thing. I’d suggest you to buy a WLED compatible led strip (or replace the govee controller with an esp if it is possible) to solve this problem

1 Like

Great script, thank you so much for your work on this! I have it all set up and running on two hue color bulbs. It is triggered 15 minutes before my iPhone alarm clock goes off. When the script is triggered, my hue bulbs start out fairly bright before quickly dimming down to the beginning of the sunrise transition.

I tried to edit the automation so the bulb would start at 1% brightness and red color, but it still started bright, transitioned to red, then transitioned to the sunrise transition. This might be something I need to fix outside of this script. Does anyone else have this issue? Thanks!

Edit: apparently this is a function of hue bulbs and one workaround is scenes. I will update if I figure this out.

Goovee2mqtt is the answer :wink:

Thank you so much for the script. It works really well. Great job!

Is it possible to define the duration, target and brightness in the same script? I am trying to create a Siri Shortcut that triggers this script as soon as the wake up alarm on my iPhone goes off. I know how to run a script in Siri Shortcut, but I am not sure if I can define any actions. I tried by creating a virtual switch but it’s not the most elegant solution. Any advise is highly appreciated.

Hey, sorry for the late answer I’m not very active here.
I’m not sure that I understand your request.
You need to call the script with the variables given in the first post to work as intended.