Thanks Dave, but it would be ideal if it worked like that
Looked into the configuration in my post above and found that you cannot template a time or time_pattern trigger, so doing the math for the sunrise effects and trigger based on that is not done easily. It could probably be done, but it would get inconviently complex.
Easiest way would be to create a second calculated input_datetime helper which is set by the blueprint after it has been set up with alarm input_datetime helper. You would need 2 datetime helpers for each instance of the blueprint with alarm times.
Thanks for this nice blueprint. I’ve got it up and running.
Now I’m trying to change it a little bit to get a sunset animation… But I’m struggling as it seems that it is not that easy to just change the target brightness and temperature in reverse.
Do you have any hints on how to achieve a sunset?
Sunset would require some modification to the script. You’d have to Take Control
of the blueprint and turn into an automation so that you can feed both the Warmest Kelvin
and Coolest Kelvin
into the the script. The blueprint make some assumptions here.
The script would require reversing min_brightness
and max_brightness
as well as changing max_brightness_pct
to min_brightness_pct
and reversing the direction of the step so that the kelvin_step
and bright_step
reverse their current direction.
This is just after a quick look at the script again, but more may be required.
Thank you @steriku
With some time and the help of MS Copilot I built a script, which I can call by pressing a button or by some other kind of action.
Here’s the script code:
blueprint:
name: Light Sunset
author: MS27HA
description: 'Script to simulate a sunset with a linear transition of color temperature and brightness.'
domain: script
homeassistant:
min_version: 2024.9.0
input: {}
fields:
target_kelvin:
description: Warmest Kelvin value. This is the end value - most orange/red
selector:
color_temp:
unit: kelvin
min: 2000
max: 6500
default: 2000
name: Warmest Kelvin
start_kelvin:
description: This is the start value.
selector:
color_temp:
unit: kelvin
min: 2000
max: 6500
default: 2500
name: Coolest Kelvin
max_brightness_pct:
description: Maximum brightness in percent to start from
selector:
number:
min: 1
max: 100
default: 100
name: Max Brightness
alarm_length:
description: This is the start to finish time. Take this into account when setting up the automation this script is called by.
selector:
number:
min: 1
max: 60
default: 10
name: Alarm Length
steps_per_minute:
description: How many steps per minute
selector:
number:
min: 1
max: 12
default: 12
name: Steps Per minute
target_light:
description: A single light or group
selector:
entity:
filter:
domain: light
name: Target Light
variables:
steps: '{{ alarm_length * steps_per_minute }}'
max_brightness: '{{ max_brightness_pct * 2.55 }}'
min_brightness: 0
kelvin_step: '{{ (float(start_kelvin) - float(target_kelvin)) / steps }}'
bright_step: '{{ (float(max_brightness) - float(min_brightness)) / float(steps) }}'
start_time: '{{ as_timestamp(now()) }}'
individual_step: '{{ 60 / steps_per_minute }}'
sequence:
- service: light.turn_on
target:
entity_id: '{{ target_light }}'
data:
brightness_pct: '{{ max_brightness_pct }}'
color_temp_kelvin: '{{ start_kelvin }}'
transition: 1
- delay: 1
- repeat:
count: '{{ steps }}'
sequence:
- variables:
steps_to_now: '{{ repeat.index }}'
brightness: '{{ [float(max_brightness) - (bright_step * steps_to_now), 0] | max | round(0, "ceil") }}'
kelvin: '{{ float(start_kelvin) - (kelvin_step * steps_to_now) }}'
- choose:
- conditions:
- condition: template
value_template: '{{ brightness <= 0 }}'
sequence:
- service: light.turn_off
target:
entity_id: '{{ target_light }}'
default:
- service: light.turn_on
target:
entity_id: '{{ target_light }}'
data:
brightness: '{{ brightness }}'
color_temp_kelvin: '{{ kelvin }}'
transition: '{{ individual_step }}'
- delay:
seconds: '{{ individual_step }}'
Is there an easy way to enable this automation only when you’re home? Imagine you travel for couple of days, the lights shouldn’t turn on when there is nobody home
You can use the workday integration for this. There is a field built into the blueprint for it. Just configure the days you’re gone to be a holiday.
Essentially this is just a binary sensor. You can create your own binary sensor to detect when you’re device is home or not and use that instead.
I used your script as inspiration (and a massive crutch in learning how to write scripts) and overhauled it to make a script which actually transitions along a parabolic curve (with the exponent used being selected by the user, my wife likes to the fourth power for wakeup alarm). Script can be found here and home assistant topic with regard to the same can be found here.
This is my first time writing a script/using github/making an automation in home assistant and I kind of feel like I went off the deep end. I’d really appreciate any feedback.
Cool mod! I did try this when creating the script but I like having more control over the different stages. The lights I’m using appear to have smoother transitions in all stages than using an actual parabolic formula.
Firstly, thanks for sharing the script.
Looks like I have the same issue as lateparty with the pulsing lights rather than smooth sunrise transition. Using Ikea Tradfri bulbs over Z2M
Am I missing somethig or is it correct, that the automation can only be applied to ONE light?
Or a light group
First off, thanks for making this. It’s brilliant.
I’m now trying to find a family safe way of integrating this. Meaning ideally I would like this to respond to the alarm my wife sets on her iPhone. But I’m lost if this is even possible?
If that is not possible. I put the date/time helper on a dash, allowing to set the alarm time there. But now I would like to add a on/off switch on the dashboard that could function as the binary sensor for turning the wake-up alarm on or off. Is there any way to do this?
Me too, Tradfri GU10 bulbs. And the reason for the issue is transition. I have no idea why this flow uses transition at all, though I haven’t put any effort into figuring this out.
So, I’ve added a way to not use the transition in the flow, making it optional via a switch element in the settings.
Feel free to give it a try:
It works for me for a couple of days already, it that makes sense I can create a PR to the original repo.
Not sure about Apple, but at least on Android there is a Next Alarm
that you can enable on the mobile app integration. You can probably create an input_datetime
sensor from this using templates and use that as the trigger in the blueprint.
As for the switch, you can use the field for Workday Sensor
. This was intended to be used with the Workday integration but it is really just a binary sensor. You could create your own binary_sensor
template that is linked to an input_boolean
you can manage yourself.
Thanks. Second option is what I ended up doing. Creating a switch helper and making a binary sensor template for it. The script and automation work great!
This should help you: https://www.reddit.com/r/homeassistant/comments/17fmyt8/comment/k6bdkgt/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
I’ve modified it so that it runs only when I’m connected to my local wifi.
And I copied it with a second trigger that it also sends the last known wakeup time to HA when I plug the charger in my phone.
Revamped original post to simplify the instructions and remove confusing/unrequired information.
Tried this out the other day, with my ikea rgbw bulbs this only uses the white leds which have too bright of a baseline, has anyone made a transition that incorporates the rgb leds to provide a more gradual transition?