Sunrise Simulator. Wake up gently to light

I‘got this Info from Zigbee2MQTT, didn‘t know where to get the info from HA.

    "brightness": 127,
    "color": {
        "h": 0,
        "hue": 0,
        "s": 100,
        "saturation": 100,
        "x": 0.7,
        "y": 0.299
    },
    "color_mode": "xy",
    "color_temp": 160,

It‘s a Philips Hue light.

Hey @ChreeceGR

Are you still active?
I found your script, I’m looking for a while for something like this. Somehow it does not work for me :frowning:

Some info

description: ""
trigger:
  - platform: time
    at: "23:37:00"
condition: []
action:
  - service: script.1691702997070
    data:
      duration: 10
      target:
        - light.slaapkamer_ledstrip
      brightness: 100
mode: single

Light:
Slaapkamer - Ledstrip

supported_color_modes: rgbw
friendly_name: Slaapkamer - Ledstrip
supported_features: 32
color_mode: rgbw
brightness: 657
hs_color: 122.133, 88.235
rgb_color: 30, 255, 38
rgbw_color: 30, 255, 38, 0
xy_color: 0.178, 0.723

I have edited the script, should also work for you

Sorry for the late reply, could you test the edited script from the 1st post?

I was on vacation @ChreeceGR

New code doesn’t give errors, but it doesn’t work. It stays on 1%

Action:

duration: 1
target:
  - light.slaapkamer_ledstrip
brightness: 99

Can you please post the steps executed from the loop on the right? (You posted the left loop)

*also changed the script a bit, please check the new code

If i copy the script i get a redline. After looking what was changed i removed the tab at ‘maxbri: |’. After that i can’t save the new script:

Message malformed: extra keys not allowed @ data['temp']

Sorry for that, that’s why one shouldn’t edit code on phone… Please try again with the edited code (just put 2 spaces in front of temp: | line)

Thnx! No more errors in the script :slight_smile: but its stays on 1%
Logs:


Can you please post how did you call the script and what are the trace steps in the repeat action? ( the last two orange circles, down right.)
Are there any related errors in the logs?

Wow found the bug sorry for that… please check the updated script. Have fun!

Yeah, no more error and its going well (from distance)! If i’m at home tonight i will test it in the dark :wink:

One question and one feature request :wink:

  • It looks like it is not possible to turn off the lamp if the script is running, is that correct?
  • Is creating a sunset script an option? Then i can go to sleep and wake up with it :smiley:

Thnx for all your help, I’m pleased with it!

If you turn off the lamp after the lamp turns on from the script ( repeat.index 1) the script will just stop as it did before I changed the code.

Creating a sunset script is not something I’m interested.

Wouldn’t be much change on the code to try. Just need to reverse the procedure

Hello, thanks a lot for the script. I implemented it and it works well and does everything that it is supposed to. However, I found another small bug that prevents the set duration from taking effect and I thought it might be usefull for everyone to share how I fixed it.
I can’t claim that im very good with code like this so I don’t know if I broke something else but its definetly working for me now.

Basically what happend was, that the script always defaultet to the 10 minutes duration, no matter what I specified in the data when calling the script.

Replacing the line: {{ ( ( ( states('input_number.sunrise_sim_time') | int(10) * 60) / maxbri ) * 1000) | int }}
in the first section specifying the first delay with: {{ ( ( ( dur * 60) / maxbri ) * 1000 ) | int }} seems to have fixed it.

Indeed, that was a helper that I’m using and forgot to change.
Thank you very much, I have updated the script

The script turned all lights on, not the light specified.i had the entity name right.
And manual turning off didn’t interrupt.

Same here.

Can you please post the trace from the script, showing the “Changed Variables” tab.

If the light is in unavailable or unknown state, or the entity doesn’t exist, all the lights will turn on by default. That could be changed by removing the lines:

{% else %}
          {% set res.r = res.r + states.light 
                                   | rejectattr('state','in', ['unavailable', 'unknown', None])
                                   | selectattr('entity_id', 'in', area_entities(t))
                                   | map(attribute='entity_id') 
                                   | list %}

The kitchen lights entity is a group, not sure if that makes a difference.

Hmmm I’m not sure if group light entities are included in the state.lights object. What is the state of the light.kitchen_lights?

Can you please check in the template editor what results do you get with:

{{ states.light
       | selectattr('entity_id', 'eq', 'light.kitchen_lights')
       | list }}