Parabolic (Power Law) Light Transition

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

This script/blueprint can be used to transition a light’s brightness and color temperature along a power law curve. I personally call it in an automation as a gentle wakeup alarm in the morning. The blueprint github repository can be found here.

For reference, here are some example power law curves:


Note that the number in superscript after the x is the “exponent” which you would provide to the script to get the curve you desire. All numbers greater than 0 should work.

This script was originally inspired by Steriku’s work on a parabolic alarm, which can be found here.

This is my first attempt at a home assistant script, so if there are rough edges let me know so I can iron them out. Tons of credit goes to Steriku for building the original script that I overhauled to make this one. Their script was invaluable as a reference and a template while I experimented/learned how to build half of this stuff.

For future improvements, my goal is to adapt this script to accept multiple lights instead of a single light. The challenges I foresee (and could use some help figuring out) are as follows:

  1. The ability to stop adapting lights that receive commands from other sources, e.g. if a user manually sets the brightness/color/state of a light stop adapting that one (and keep adapting the rest). Similar to the check in the current script to only adapt the light if it remains on, but more robust and with multiple lights.
  2. Adapting each light from its own starting brightness/color temperature. Honestly this one may be insurmountable. Without running separate instances of the repeat block for each light with their own variables I don’t see how it can be done. But I’m a noob so maybe y’all have an awesome answer.
2 Likes

Hello John,

Thanks for contributing to the community with a new Blueprint.

I have a suggestion for you. Many people who are not familiar with directory structures will have problems installing this without the Home Assistant MY tools.
Adding a MY link for this Blueprint to your top post would help them a lot.
Here is the link to make that.

Create a link – My Home Assistant

1 Like

Done! Thanks for the great tip! How easy would it be to make it look like those nice add to my home assistant links I am used to seeing in the documentation?

That link will do that. Select the markdown one.

All I had to do was scroll down T_T
Thanks!

1 Like

Thanks, I’ve just started migrating some of my Hubitat automations over to HA and this looks perfect to replicate part of my current behaviour.

Might be a daft question (as I’m still getting to grips with HA) but how do you parse the input values to the script?

I’ve imported the Blueprint & made a script off the back of it, but they show has having no inputs? I’m looking to call it as part of an automation I’ve written (got the script trigger created okay).

Thanks

Just coming back to this for anyone else - it was indeed just inexperience with HA. After reloading things and going back to an automation I now have a GUI picker for selecting the light and critiera I want to set. Thanks.

Glad you figured it out Ben! Sorry I’ve been away traveling for the holiday.

1 Like

Hi @Coleslaw1994 , thanks a lot for the script.
I have modified it to use RGB instead of color temp because on my IKEA bulb I found the initial switch-on too bright. Since this is my first couple of days on Home assistant, I am not sure everything is OK, nor how to share the blueprint. Could you please have a look and share it for the rest of the community if deemed OK.
It seems to work here.

Thanks,

Pierre

Actually, I am getting an error, but not systematically. When it happens the automation is terminated straight away. I don’t know if it the automation trigger (time trigger based on a template sensor using a time input helper) or the script.

The error:

2025-01-07 06:30:00.004 ERROR (MainThread) [homeassistant.components.script.light_transition_wake_up_rgb] Light Transition Wake up RGB: Error executing script. Error rendering template for variables at pos 1: TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
2025-01-07 06:30:00.005 ERROR (MainThread) [homeassistant.components.automation.chambre_pierre_interrupteur_chevet_reveil] Chambre Pierre reveil: Error executing script. Error rendering template for call_service at pos 1: TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'
2025-01-07 06:30:00.005 ERROR (MainThread) [homeassistant.components.automation.chambre_pierre_interrupteur_chevet_reveil] Error while executing automation automation.chambre_pierre_interrupteur_chevet_reveil: TypeError: unsupported operand type(s) for -: 'int' and 'NoneType'

I will investigate further but welcome expertise.

Pierre

I like the idea but couldn’t successfully test it. it threw me this error.

Executed: January 7, 2025 at 10:11:33 PM
Error: network error:(SYSTEM_ERROR) Server Error
Result:
params:
  domain: script
  service: parabolic_light_transition
  service_data:
    starting_brightness: 1
    target_brightness: 100
    brightness_exponent: 2
    starting_kelvin: 2000
    target_kelvin: 6500
    kelvin_exponent: 2
    transition_length: 15
    steps_per_minute: 12
    target_light: light.lamp_office
  target: {}
running_script: true
child_id:
  domain: script
  item_id: parabolic_light_transition
  run_id: 9c722d8a86dd1ea234dba41566457bbd0

@xlordxcheater I am afraid I am not the best suited to help there, my HA instal is less than 3 weeks old so I am really a rookie in all this. I am surprised at the “network error”, I don’t know how this would be linked to the script.

As for my error, I am also very puzzled:

  • when I use my time trigger for something else (play media for example) it seems to work properly
  • when I trigger the script from a button, it seems to work properly

could there be some race condition? could someone tell me what the “variable at pos 1” refers to?

thanks,

Pierre

Ok, just a little update. I am not sure why but it seems the script is now working and I have not changed anything on it. So if somebody have an idea what these errors could have been, you’re welcome to enlighten me. For now I am enjoying the new alarm clock setup.

Pierre

Cool idea! One (pretty insignificant) side note: it’s only parabolic if the exponent is 2. I would call this a ‘power law’

Pierre,
Admittedly I also don’t know much on this stuff yet, but I am glad to hear it’s working for you now! I haven’t had any errors yet myself.

Damn, you learn something every day. I probably knew this back in school but had definitely forgotten that parabolas are only the second power, and how they were related to cones. That said, I don’t know if “Power law light transition” sounds as sexy. We’ll have to workshop better names.

How about ‘polynomial light transition’? It sounds about as cool as parabolic and it’s almost correct (the non-integer powers like 1/2 don’t fit in the definition of a polynomial)

Maybe we can go for “Non-linear light transition” or even for the cheesier “Power(ful) Light transtition” :wink:

For the ones interested, this is the setup for my alarm clock using the transition script. There is still a little issue which I will try to solve later: because of the way the helper sensor is setup the alarm (the light component) will not work for times between midnight and half past midnight.

IKEA Symphonisk lamp with an IKEA Tradfi Bulb color/white E27 806lm.
IKEA Styrbar 4 button remote

Inputs:

  • alarm time input: input_datetime set for time only. This is what is used to program the “end” wake up time. The light transition starts 30mn before. The music starts at this time.

  • light On/Off toggle: input_boolean. This switches On/Off the light part of the alarm clock

  • music On/Off toggle: input_boolean. This switches On/Off the music part of the alarm clock

Helpers:

  • alarm sensor 30mn: this is a timestamp helper which calculates the begining time of the light transistion (for me 30 mn transition). template type with the template YAML:
    {{(today_at(states('input_datetime.chambre_pierre_reveil_1')) - timedelta(minutes = 30))}}

  • music toggle helper: input_boolean; this is used so I can cancel the music part if I am wake during the light transition and before the music starts

Automations:

  • Light automation: this starts by initialising the music helper to the value of the music toggle, then depending on the light toggle it starts the light transition script:
triggers:
  - trigger: time
    at: sensor.chambre_pierre_sensor_30mn_reveil_1
conditions: []
actions:
  - action: >-
      input_boolean.turn_{{
      states('input_boolean.chambre_pierre_on_off_reveil_1_musique_toggle') }}
    target:
      entity_id: input_boolean.chambre_pierre_reveil_1_musique_helper
  - if:
      - condition: state
        entity_id: input_boolean.chambre_pierre_on_off_reveil_1_lumiere_toggle
        state: "on"
    then:
      - action: script.light_transition_wake_up_rgb
        metadata: {}
        data:
          starting_brightness: 1
          target_brightness: 50
          brightness_exponent: 2
          starting_kelvin: 2000
          target_kelvin: 6500
          kelvin_exponent: 2
          transition_length: 30
          steps_per_minute: 12
          target_light: light.chambre_pierre_lampe_chevet
mode: single
  • Music automation: starts plaing music on the time of the alarm if the music helper is on:
triggers:
  - trigger: time
    at: input_datetime.chambre_pierre_reveil_1
conditions:
  - condition: state
    entity_id: input_boolean.chambre_pierre_reveil_1_musique_helper
    state: "on"
actions:
  - action: media_player.play_media
    target:
      entity_id: media_player.chambre_pierre_enceinte_ma
    data:
      media_content_id: library://album/16
      media_content_type: album
    metadata:
      title: ( )
      thumbnail: null
      media_class: album
      children_media_class: track
      navigateIds:
        - {}
        - media_content_type: music_assistant
          media_content_id: albums
        - media_content_type: music
          media_content_id: library://album/16
mode: single
  • alarm stop automation: on a single press of the button it will toggle off the music helper (caveat the helper is reset on the t-30 light automation, so pressing the button before light transition is started will have no effect, use the input music toggle to switch the music alarm off) and turn off the music if playing. On a second press within 5 seconds of the first, the light transition script stops and the light stays at the current brightness and color:
triggers:
  - domain: mqtt
    device_id: ce7b8bf7370ad4cdf269f7f06009f957
    type: action
    subtype: "off"
    trigger: device
conditions: []
actions:
  - action: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.chambre_pierre_reveil_1_musique_helper
  - action: media_player.media_stop
    metadata: {}
    data: {}
    target:
      device_id: 1e3112d0e61282d6edcef75e5cbc0f13
  - wait_for_trigger:
      - domain: mqtt
        device_id: ce7b8bf7370ad4cdf269f7f06009f957
        type: action
        subtype: "off"
        trigger: device
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - action: script.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: script.light_transition_wake_up_rgb
mode: single

Dashboard on an old smartphone (on a stand with QI charging);