deCONZ - IKEA five button remote for lights with color temp

Tags: #<Tag:0x00007f326414a878> #<Tag:0x00007f326414a788>

This is a fork of the blueprint from Bram Kragten (Thanks for the inspiration!) with the following differences:

  • left/right buttons change color temperature to warmer/colder temperatures,
  • number of brightness and color temperature adjustment steps is configurable,
  • only one light entity (no areas or devices) is supported
  • This light entity needs to …
    • provide either both min_mireds and max_mireds attributes or the rgb_color attribute and
    • support the color_temp argument of the light.turn_on service.

(If you know how to make it more generic regarding areas and devices and keep the color temperature adjustment feature somehow, please let me know.)

My Home Assistant

This is a blueprint for the IKEA five-button remotes (the round ones), specifically for use with deCONZ.

The middle “on” button, toggles the lights on/off.

Dim up/down buttons will change the brightness smoothly and can be pressed and held until the brightness is satisfactory.

Left/right buttons will change the color temperature smoothly and can be pressed and held until the color temperature is satisfactory.

The ‘min/max color temperature override values’ are fallback values for light entities without min_mireds and max_mireds attributes (e.g. color lights with rgb_color attribute instead). They are only used to determine the color temperature step value to be applied on left/right button press.
For these light entities the current color temperature is approximated from (and only from) the rgb_color attribute using the inverse formula from here for color temperatures between 689 mireds (~1500 K) and 151 mireds (6600 K). Only for these rgb light entities, color temperatures can only set within this range.

The force brightness option allows you to configure a brightness which alyways should be used when turning the light on. If force brightness is off, the last brightness from when the light was turned of is used. However, with the latter, it is not possible to have a transition effect when toggling the light.

Force Brightness vs Transition Behavior
force brightness on off
transitions on
toggle?
yes no
brightness when
turning on?
the one you set in the
blueprint configuration
last brightness from
when turned off

This is what the Blueprint looks like from the UI:

Changelog

2021-02-27

  • Light now stays on at lowest brightness, when short/long pressing down button repeatedly
  • Added force brightness option (default off)
  • If force brightness is off, the last brightness from when the light is turned off is used when turning it on again, but there is no transition anymore. A smooth transition when toggling can only be achieved with the force brightness option.

2020-12-31

  • Limit set color temp to min/max color temp override values (for rgb light entites only). Setting cold color temperatures close to the valid approximation interval is now possible.
  • Extend valid approximation interval from 1900 K to ~1500 K (526 mired to 689 mired)
  • Set default values for min/max color temperature override to interval borders of valid approximation interval

2020-12-28

  • Introduce fallback color temperature approximation from rgb_color attribute so color temperature change does also work with color light entities and not just with white spectrum light entities.

2020-12-20

  • Initial release

Blueprint, which you can import by using this forum topic URL:

blueprint:
  name: deCONZ - IKEA five button remote for lights with color temp
  description: 'Control light entities with an IKEA five button remote (the round ones).


    The middle "on" button, toggles the lights on/off.

    Dim up/down buttons will change the brightness smoothly and can be pressed and
    held until the brightness is satisfactory.

    Left/right buttons will change the color temperature smoothly and can be pressed and
    held until the color temperature is satisfactory.

    The min/max color temperature override values are fallback values for light entities without 
    min_mireds and max_mireds attributes (e.g. color lights with rgb_color attribute).'
  domain: automation
  input:
    remote:
      name: Remote
      description: IKEA remote to use
      selector:
        device:
          integration: deconz
          manufacturer: IKEA of Sweden
          model: TRADFRI remote control
    light:
      name: Light(s)
      description: The light entity (can be a group) to control
      selector:
        entity:
          domain: light
    force_brightness:
      name: Force turn on brightness
      description: 'Force the brightness to the set level below, when the "on" button on the remote is pushed and lights turn on.'
      default: false
      selector:
        boolean: {}
    brightness:
      name: Brightness
      description: Brightness of the light(s) when turning on
      default: 50
      selector:
        number:
          min: 0.0
          max: 100.0
          mode: slider
          step: 1.0
          unit_of_measurement: "%"
    brightness_step_count:
      name: Brightness Adjustment Steps
      description: Steps/seconds needed to adjust brightness between 0% and 100%.
      default: 6
      selector:
        number:
          min: 1.0
          max: 10.0
          mode: slider
          step: 1.0
          unit_of_measurement: steps
    color_temp_step_count:
      name: Color Temperature Adjustment Steps
      description: Steps/seconds needed to adjust color temperature between min and
        max value.
      default: 6
      selector:
        number:
          min: 1.0
          max: 10.0
          mode: slider
          step: 1.0
          unit_of_measurement: steps
    color_temp_min_override:
      name: Min Color Temperature Override
      description: "Minimum color temperature value in mireds for light entities without 'min_mireds' attribute (e.g. color lights)."
      default: 151.0
      selector:
        number:
          min: 151.0
          max: 689.0
          mode: slider
          step: 1.0
          unit_of_measurement: mireds
    color_temp_max_override:
      name: Max Color Temperature Override
      description: "Maximum color temperature value in mireds for light entities without 'max_mireds' attribute (e.g. color lights)."
      default: 689.0
      selector:
        number:
          min: 151.0
          max: 689.0
          mode: slider
          step: 1.0
          unit_of_measurement: mireds
  source_url: https://community.home-assistant.io/t/deconz-ikea-five-button-remote-for-lights-with-color-temp/257617
mode: restart
max_exceeded: silent
variables:
  light_entity: !input 'light'
  force_brightness: !input 'force_brightness'
  is_white_spectrum_light: '{{ (not state_attr(light_entity, "min_mireds") == none)|int }}'
  brightness_step_count: !input 'brightness_step_count'
  color_temp_step_count: !input 'color_temp_step_count'
  color_temp_min: !input 'color_temp_min_override'
  color_temp_max: !input 'color_temp_max_override'
  brightness_step: '{{ (255/brightness_step_count|int)|round(0, "ceil") }}'
  color_temp_step: '{{ (((state_attr(light_entity, "max_mireds")|default(color_temp_max|int, true) - state_attr(light_entity, "min_mireds")|default(color_temp_min|int, true))/color_temp_step_count|int)|abs)|round(0, "ceil") }}'
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      device_id: !input 'remote'
action:
  - variables:
      event: '{{ trigger.event.data.event }}'
  - choose:
      - conditions:
          - '{{ event == 1002 }}'
        sequence:
          - choose:
              - conditions: "{{ force_brightness }}"
                sequence:
                  - service: light.toggle
                    entity_id: !input 'light'
                    data:
                      transition: 1
                      brightness_pct: !input "brightness"
            default:
              - service: light.toggle
                entity_id: !input 'light'
      - conditions:
          - '{{ event == 2002 }}'
        sequence:
          - service: light.turn_on
            entity_id: !input 'light'
            data:
              brightness_step: '{{ brightness_step }}'
              transition: 1
      - conditions:
          - '{{ event == 2001 }}'
        sequence:
          - repeat:
              count: '{{ brightness_step_count }}'
              sequence:
                - service: light.turn_on
                  entity_id: !input 'light'
                  data:
                    brightness_step: '{{ brightness_step }}'
                    transition: 1
                - delay: 1
      - conditions:
          - '{{ event == 3002 }}'
        sequence:
          - service: light.turn_on
            entity_id: !input 'light'
            data:
              brightness_step: '{{ -([state_attr(light_entity, "brightness")-1, brightness_step]|min) }}'
              transition: 1
      - conditions:
          - '{{ event == 3001 }}'
        sequence:
          - repeat:
              count: '{{ brightness_step_count }}'
              sequence:
                - service: light.turn_on
                  entity_id: !input 'light'
                  data:
                    brightness_step: '{{ -([state_attr(light_entity, "brightness")-1, brightness_step]|min) }}'
                    transition: 1
                - delay: 1
      - conditions:
          - condition: and
            conditions:
              - '{{ event == 4002 }}'
              - '{{ is_state(light_entity, "on") }}'
        sequence:
          - service: light.turn_on
            entity_id: !input 'light'
            data:
              color_temp: '{{ [(state_attr(light_entity, "color_temp")|default(1e6/([[[2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[1]+161.1195681661)/99.4708025861)*100, 6600]|min, 1000]|max, [[(2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[2]+305.0447927307)/138.5177312231)+10)*100, 6600]|min, 1900]|max]|sum/2), True) + color_temp_step), color_temp_max|int*(1+10*is_white_spectrum_light)]|min }}'
              transition: 1
      - conditions:
          - condition: and
            conditions:
              - '{{ event == 4001 }}'
              - '{{ is_state(light_entity, "on") }}'
        sequence:
          - repeat:
              count: '{{ color_temp_step_count }}'
              sequence:
                - service: light.turn_on
                  entity_id: !input 'light'
                  data:
                    color_temp: '{{ [(state_attr(light_entity, "color_temp")|default(1e6/([[[2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[1]+161.1195681661)/99.4708025861)*100, 6600]|min, 1000]|max, [[(2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[2]+305.0447927307)/138.5177312231)+10)*100, 6600]|min, 1900]|max]|sum/2), True) + color_temp_step), color_temp_max|int*(1+10*is_white_spectrum_light)]|min }}'
                    transition: 1
                - delay: 1
      - conditions:
          - condition: and
            conditions:
              - '{{ event == 5002 }}'
              - '{{ is_state(light_entity, "on") }}'
        sequence:
          - service: light.turn_on
            entity_id: !input 'light'
            data:
              color_temp: '{{ [(state_attr(light_entity, "color_temp")|default(1e6/([[[2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[1]+161.1195681661)/99.4708025861)*100, 6600]|min, 1000]|max, [[(2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[2]+305.0447927307)/138.5177312231)+10)*100, 6600]|min, 1900]|max]|sum/2), True) - color_temp_step), color_temp_min|int*(1-is_white_spectrum_light)]|max }}'
              transition: 1
      - conditions:
          - condition: and
            conditions:
              - '{{ event == 5001 }}'
              - '{{ is_state(light_entity, "on") }}'
        sequence:
          - repeat:
              count: '{{ color_temp_step_count }}'
              sequence:
                - service: light.turn_on
                  entity_id: !input 'light'
                  data:
                    color_temp: '{{ [(state_attr(light_entity, "color_temp")|default(1e6/([[[2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[1]+161.1195681661)/99.4708025861)*100, 6600]|min, 1000]|max, [[(2.7182818284**(((state_attr(light_entity, "rgb_color")|default([0,0,0], true))[2]+305.0447927307)/138.5177312231)+10)*100, 6600]|min, 1900]|max]|sum/2), True) - color_temp_step), color_temp_min|int*(1-is_white_spectrum_light)]|max }}'
                    transition: 1
                - delay: 1
4 Likes

Looks absolutely great. Too bad I am on ZHA and the ones available in blueprints is without the color change. Is someone able to rewrite this for ZHA?

Thanks for this blueprint, but alas, I’m running into a consistent error. Probably due to my lack of knowledge :slight_smile:

ERROR (MainThread) homeassistant.components.automation.deconz_ikea_five_button_remote_for_lights_with_color_temp] Error rendering variables: TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'

Any help appreciated, as I cannot figure out where to look

That error message is complaining about a subtraction performed by one of the variables. It’s probably this one:

color_temp_step: "{{ ((state_attr(light_entity, 'max_mireds') - state_attr(light_entity, 'min_mireds'))/color_temp_step_count|int)|round(0, 'ceil') }}"

The error indicates two NoneTypes were being subtracted. That means the two state_attr() functions, used in the template, returned None.

That could happen if the supplied light_entity is a non-existent entity and/or it doesn’t have the required attributes (max_mireds, min_mireds).

My guess is you may have selected a light entity that doesn’t have the two required attributes. Go to Developer Tools > States, find the entity you chose, and check its attributes for the presence of max_mireds and min_mireds.

1 Like

My attributes:

brightness: 254
hs_color: 30.207, 56.863
rgb_color: 255, 182, 109
xy_color: 0.491, 0.39
is_deconz_group: false
friendly_name: Color light 3
supported_features: 57

Indeed no min_mireds en max_mireds

It is a real color bulb

Unless the author can invent a way of computing color_temp_step without relying on the two mireds attributes, your lamp is incompatible.

Guess so :frowning:

Mireds are a unit of measurement for expressing color temperature. I’m no expert in this, and this is just a guess, but it’s possible that your light doesn’t support adjustments to its color temperature so that’s why it lacks attributes for max and min mireds. In other words, there may be no ‘other way’ to compute color_temp_step for bulbs that don’t support color temperature changes.

Gonna find out how to handle it. Another project on the list :slight_smile:

Thanks for all the feedback, trying out the blueprint and discovering that it does did not work with real color lights without min_mireds and max_mireds attributes.

I did some research about converting rgb and color temperatures back and forth and discovered, that HA already implements the rgb-2-color-temp direction in their homeassistant.util.color.color_temperature_to_rgb function.
The inverse mapping is only a bijective function between 526 mireds (1900 K) and 151 mireds (6600 K) and so I inverted this approximation in that range and used it as a fallback color temperature for lights with only a rgb_color attribute.

It now should also work with real color lights as long as they have the rgb_color attribute.

Maybe it’s time for a color_temp_step argument to the light.turn_on service? :thinking:

1 Like

just ordered the conbee II and the ikea 5 button switches so hopefully I will be able to use this one with my lohas rgb color led’s that were flashed with tasmota and running nicely on ESPHome and HA, but it would be nice to have some physical switches for them. I don’t subscribe to the idea of color temp for my control now through nodered automations, just using specific values for my desired colors for different times of day - like{"brightness_pct":70,"rgb_color":[255,160,0],"white_value":0,"transition":10} my steps go from bright white in the early evening to plain red in the late evening, which I just love, and my version of color temp with these switches will hopefully do the same thing.

Thanks for this update. Just downloaded it. Ready for testing :slight_smile:

Just to be sure: I only need to connect the bulb and remote control to my Conbee II. There is no reason to group them in the Conbee II, right?

Just to be sure: I only need to connect the bulb and remote control to my Conbee II. There is no reason to group them in the Conbee II, right?

Correct, the information flow is: Remote > ConBee > HA (this blueprint) > ConBee > Bulb

Right … and the good news: It is working for my color bulb :slight_smile:

And i’ve learned a bit about colours and colour temperature too in the meantime.

Just out of curiosity: is it possible to set a higher “max” for “Max Color Temperature Override”, so the bulb colour becomes more White?
The bulb can handle up to 6000 Kelvin

@patrickr Should be fixed now :slight_smile:

In the 2020-12-28 version, the min/max color temp override values did not limit the set color temp, so it could happen, that a color temp outside the valid approximation interval was set which led to a wrong approximated color temp in the next step.

When using the current version (2020-12-31) with a rgb light entity, the min/max color temp override values now limit the settable color temp correctly.

@mrbc Thanks for the quick update :slight_smile: … Just tested it a little bit. Seems to work for now … Will test a bit more next year :wink:

I have made one change in the blueprint myself, as I expect it to be a minor mistake in the one published now:

I was expecting that color_temp_min_override and color_temp_max_override both have the same min and max values, 151 and 689 respectively. color_temp_min_override has a max value of 526 now, which I’ve changed to 689 myself.

Or am I wrong now?

@patrickr Thanks, you’re right, that slipped through. Just fixed it. :slight_smile:

I don’t understand these blueprints or even HA tbh sometimes. how do I go back after creating an automation through this blueprint and change the settings? the only option in the blueprint is to create an automation.

Oh, and thanks again for doing this! it works great, so far so good!!! I couldn’t figure out how to get the deconz inegration working, and then 30 minutes later, home assistant discovered it :man_facepalming:

Configuration > Automations > the name of the automation you created via the blueprint

1 Like