Skip to content

Instantly share code, notes, and snippets.

@brucefoster
Last active May 24, 2025 09:16
Show Gist options
  • Select an option

  • Save brucefoster/914891a933b86b874b25850111d2e593 to your computer and use it in GitHub Desktop.

Select an option

Save brucefoster/914891a933b86b874b25850111d2e593 to your computer and use it in GitHub Desktop.
blueprint:
name: "Tradfri Wrapper Dev"
description: >
### Workaround for animating both color and brightness in IKEA Tradfri bulbs
These bulbs are notorious for all sorts of glitches when trying to animate brightness and color simultaneously.
This script will help to animate brightness first and then will animate color or color temperate.
### Usage
Install this script and replace your regular calls to `light.turn_on` to `script.tradfri_wrapper` moving all params to `data`:
```yaml
# That's your usual call
action: light.turn_on
target:
entity_id: light.tradfri_e14
data:
kelvin: 2700
brightness_pct: 100
# Replace with (make sure to replace script's name if you've changed it):
action: script.tradfri_wrapper
data:
target:
entity_id: light.tradfri_e14
data:
kelvin: 2700
brightness_pct: 100
```
domain: script
variables:
known_brightness_keys: |
{{ [
'brightness', 'brightness_pct',
'brightness_step_pct', 'brightness_step'
] }}
known_colors_keys: |
{{ [
'rgb_color', 'kelvin',
'rgbw_color', 'rgbww_color',
'color_name', 'hs_color',
'xy_color', 'color_temp',
'color_temp_kelvin'
] }}
brightness_keys: |
{{ known_brightness_keys | select('in', data) | list }}
colors_keys: |
{{ known_colors_keys | select('in', data) | list }}
simultaneous_change_check: |
{{ brightness_keys | count > 0 and colors_keys | count > 0 }}
delay: |
{{ data["transition"] if "transition" in data else 0.5 }}
sequence:
- if:
- "{{ simultaneous_change_check == false }}"
then:
- action: light.turn_on
target: |
{{ target }}
data_template: >-
{% set data = dict(data , **{'transition': delay}) %}
{{ data }}
else:
- action: light.turn_on
target: |
{{ target }}
data_template: >-
{% set ns = namespace(filtered_data={}) %}
{% for key, value in data.items() if key not in colors_keys %}
{% set ns.filtered_data = dict(ns.filtered_data , **{key: value}) %}
{% endfor %}
{% set ns.filtered_data = dict(ns.filtered_data , **{'transition': delay}) %}
{{ ns.filtered_data }}
- delay:
hours: 0
minutes: 0
seconds: |
{{ delay + 0.05 }}
- action: light.turn_on
target: |
{{ target }}
data_template: >-
{% set ns = namespace(filtered_data={}) %}
{% for key, value in data.items() if key in colors_keys %}
{% set ns.filtered_data = dict(ns.filtered_data , **{key: value}) %}
{% endfor %}
{% set ns.filtered_data = dict(ns.filtered_data , **{'transition': delay}) %}
{{ ns.filtered_data }}
mode: parallel
fields:
target:
selector:
object:
data:
selector:
object:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment