EDIT:
I created a much smoother and better solution for this problem. Check the following post to now more about it.
Hi @bartplessers,
I have been working on these recently. I have the same Ikea controller and I wanted a smooth solution for this. I found this post where the same is done but with a Xiomi controller: Finally - a cheap WIRELESS switch that dims! Xiaomi Switch Gen1. I started adapting it from the solution found on this post, but I have changed some things. The main thing I changed was to create a python script to dim up/down smoothly.
I created a package for it:
automation:
###################
## Toggle the light
###################
- id: ikea_controller_toggle
alias: Ikea Controller - Toggle
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: "toggle"
condition:
action:
- service: light.toggle
data:
entity_id: light.YOURLIGHT
###########################################
## Dim up/down and warm up/down with clicks
###########################################
- id: ikea_controller_dim_up
alias: Ikea controller dim up
trigger:
platform: state
entity_id: sensor.YOURCONTROLLER_action
to: brightness_up_click
action:
data_template:
entity_id: light.YOURLIGHT
brightness: "{{ state_attr('light.YOURLIGHT', 'brightness') + 50 | int }}"
service: light.turn_on
- id: ikea_controller_dim_down
alias: Ikea controller dim down
trigger:
platform: state
entity_id: sensor.YOURCONTROLLER_action
to: brightness_down_click
action:
data_template:
entity_id: light.YOURLIGHT
brightness: "{{ [state_attr('light.YOURLIGHT', 'brightness') - 50, 1] | max }}"
service: light.turn_on
- id: ikea_controller_warm_up
alias: Ikea controller warm up
trigger:
platform: state
entity_id: sensor.YOURCONTROLLER_action
to: arrow_right_click
action:
data_template:
entity_id: light.YOURLIGHT
color_temp: "{{ state_attr('light.YOURLIGHT', 'color_temp') + 75 }}"
service: light.turn_on
- id: ikea_controller_warm_down
alias: Ikea controller warm down
trigger:
platform: state
entity_id: sensor.YOURCONTROLLER_action
to: arrow_left_click
action:
data_template:
entity_id: light.YOURLIGHT
color_temp: "{{ state_attr('light.YOURLIGHT', 'color_temp') - 75 }}"
service: light.turn_on
###############################################
## Dim up/down with long press
###############################################
- id: ikea_controller_brighten_on
alias: Ikea Controller - Brighten on
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: brightness_up_hold
condition:
- condition: state
entity_id: light.YOURLIGHT
state: "on"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.light_brightness
- service: python_script.change_attribute_light_smoothly
data:
light_id: light.YOURLIGHT
input_boolean: input_boolean.light_brightness
delta: 20
- id: ikea_controller_dim_on
alias: Ikea Controller - Dim on
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: brightness_down_hold
condition:
- condition: state
entity_id: light.YOURLIGHT
state: "on"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.light_brightness
- service: python_script.change_attribute_light_smoothly
data:
light_id: light.YOURLIGHT
input_boolean: input_boolean.light_brightness
delta: -20
- id: ikea_controller_brighten_dim_off
alias: Ikea Controller - Brighten/Dim off
initial_state: "on"
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: brightness_up_release
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: brightness_down_release
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.light_brightness
state: "on"
- condition: state
entity_id: light.YOURLIGHT
state: "on"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.light_brightness
###############################################
## Warm up/down with long press
###############################################
- id: ikea_controller_warm_on
alias: Ikea Controller - Warm on
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: arrow_right_hold
condition:
- condition: state
entity_id: light.YOURLIGHT
state: "on"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.light_color_temp
- service: python_script.change_attribute_light_smoothly
data:
input_boolean: input_boolean.light_color_temp
light_id: light.YOURLIGHT
light_attribute: color_temp
delta: 40
- id: ikea_controller_col_on
alias: Ikea Controller - Cold on
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: arrow_left_hold
condition:
- condition: state
entity_id: light.YOURLIGHT
state: "on"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.light_color_temp
- service: python_script.change_attribute_light_smoothly
data:
light_id: light.YOURLIGHT
input_boolean: input_boolean.light_color_temp
light_attribute: color_temp
delta: -40
- id: ikea_controller_warm_cold_off
alias: Ikea Controller - Warm/Cold off
initial_state: "on"
trigger:
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: arrow_left_release
- platform: state
entity_id: sensor.YOURCONTROLLER_action
to: arrow_right_release
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.light_color_temp
state: "on"
- condition: state
entity_id: light.YOURLIGHT
state: "on"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.light_color_temp
# Inputs to control the dim up/down and warm up/down smoothly
input_boolean:
light_brightness:
name: Light brigthness
initial: off
light_color_temp:
name: Light color temperature
initial: off
You will need to change:
- YOURLIGHT: Your light entity
- YOURCONTROLLER: Your controller
You can add this file on packages
folder and on the configuration.yaml:
homeassistant:
packages: !include_dir_named packages
python_script:
Then, you will need to add the following script (change_attribute_light_smoothly.py) inside /config/python_scripts:
input_boolean = data.get("input_boolean")
light_id = data.get("light_id")
delta = data.get("delta")
attribute_id = data.get("light_attribute", "brightness")
delay = data.get("delay", 350)
attribute_mapping = {
"brightness": {"min": 1, "max": 255},
"color_temp": {"min": 153, "max": 500},
}
exit_service = False
while True:
switch_input = hass.states.get(input_boolean).state
if switch_input == "off":
break
light = hass.states.get(light_id)
attr_value = light.attributes[attribute_id]
attr_value = attr_value + delta
if attr_value < attribute_mapping[attribute_id]["min"]:
attr_value = attribute_mapping[attribute_id]["min"]
exit_service = True
elif attr_value > attribute_mapping[attribute_id]["max"]:
attr_value = attribute_mapping[attribute_id]["max"]
exit_service = True
service_data = {"entity_id": light_id, attribute_id: attr_value}
logger.warning(f"Service data: {service_data}")
hass.services.call("light", "turn_on", service_data)
if exit_service:
break
time.sleep(delay / 1000)
I hope this helps you with your needs.