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:
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.
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.
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.
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?
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).
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.
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.
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'
@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?
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.
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)
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:
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: