Random Color Temperature Automation for Tradfri Lights

Hey everyone, I’ve been diving into automating my lighting setup and wanted to share my experience with random color temperature settings for my Tradfri lights. It’s been a fun project and I’m excited to see how others approach similar tasks!

I recently tried setting up an automation to randomly adjust the color temperature of my living room lights throughout the day. The goal was to create a more dynamic and natural lighting environment. While I’m still learning the ropes, I ran into a few hiccups along the way.

Here’s what my initial setup looked like:
yaml

  • alias: ‘Random Color Temp’
    trigger:
    platform: time
    seconds: ‘/1’
    action:
    service: input_slider.select_value
    data_template:
    entity_id: input_slider.random_color_temp
    value: ‘{{ (range(40, 600)|random) }}’

  • alias: ‘Disco in Sofa’
    trigger:
    platform: time
    seconds: ‘/3’
    action:
    service: light.turn_on
    data:
    entity_id: light.sofa
    brightness_pct: 100
    color_temp: ‘{{ states(‘input_slider.random_color_temp’) }}’

At first glance, it seemed straightforward—generate a random color temperature value and apply it to the lights. However, I quickly realized that converting the slider value to an integer wasn’t as simple as I thought. After some research and trial and error, I figured out that wrapping the slider state in int() did the trick!

Now, every few minutes, my lights cycle through different color temperatures, creating a surprisingly pleasant ambiance. It’s especially nice in the evenings when I want the lights to shift to warmer tones without manually adjusting them.

I’d love to hear how others are using automations to enhance their lighting setups. Any tips or tricks you’ve discovered would be invaluable! :rocket: