So I want to create my own blueprint for changing my light colors and temperature throughout the day.
I’m new to using Home Assistant, but I used a similar approach when I was using Google Home Automation.
Let me start by saying my lights (WiZ) do not support transition, so that doesn’t work.
Now I want to make a blueprint where the following aspects are chosen:
- Start/stop-time OR duration time of the change in minutes.
- Start temperature for the first time range
- Start brightness for the first time range
- End temperature for the first time range
- End brightness for the first time range
Then the following variables are calculated:
duration: #If start/stop-time is selected, then "{{ stop - start }}", if duration is chosen, then duration in minutes
intervals: "{{ duration * 2 }}"
step_kelvin: "{{ ((stop_kelvin - start_kelvin) / intervals) }}"
step_brightness: "{{ ((stop_bright - start_bright) / intervals) }}"
I was wondering if I could use a Python script to do the calculation. I used the following Python script to find those variables:
from math import gcd
# Input values
initial_temp = 3500 # Initial temperature in Kelvin
target_temp = 5500 # Target temperature in Kelvin
initial_brightness = 50 # Initial brightness (percentage or units)
target_brightness = 90 # Target brightness (percentage or units)
duration = 600 # Total time in seconds
# Function to find the smallest interval for whole number decrease
def smallest_interval(initial_value, target_value, total_seconds):
# Total decrease needed
total_decrease = initial_value - target_value
# Find the greatest common divisor (GCD) between total decrease and total seconds
interval_gcd = gcd(total_decrease, total_seconds)
# Calculate the interval in seconds
interval_seconds = total_seconds // interval_gcd
# Calculate the whole number decrease per interval
decrease_per_interval = total_decrease // interval_gcd
return interval_seconds, decrease_per_interval
# Calculate the smallest interval for color temperature
interval_seconds_temp, decrease_temp = smallest_interval(initial_temp, target_temp, duration)
# Calculate the smallest interval for brightness
interval_seconds_brightness, decrease_brightness = smallest_interval(initial_brightness, target_brightness, duration)
# Print results
print(f"Interval seconds: {interval_seconds_temp}")
print(f"Decrease brightness: {decrease_brightness}")
print(f"Decrease color: {decrease_temp}")
Hope someone can help me out!