Please help: automation for IKEA TRADFRI remote control (E1524/E1810)

And further: I made the mistake to replayce “YOURLIGHT” by “0xd0cf5efffe0bb71a” wich didn’t work.
I had to change it to “0xd0cf5efffe0bb71a_light”

So the correct syntax for my (IKEA) bulb and remote is:

automation:
  ###################
  ## Toggle the light
  ###################
  - id: ikea_controller_toggle
    alias: Ikea Controller - Toggle
    trigger:
      - platform: state
        entity_id: sensor.0xd0cf5efffe307960_action
        to: "toggle"
    condition:
    action:
      - data:
          entity_id: light.0xd0cf5efffe0bb71a_light
        service: light.toggle

This seems to work

grtz
B

1 Like

And…YEZZZZZZZZZZZZZZZZZZZZ
It works now!

You’re definitely the best @xaviml!!!

I think these kind of samples should be posted on https://www.home-assistant.io/cookbook/ to. It helps a lot for newbies like me.

again: thank you a lot for helping me out of this.

B

1 Like

No worries! I had troubles finding something like this as well, so that is why I ended up making it by myself. If you take a further look to the python code and the yaml, you can change things like “delta” or “delay” in case you need something a little bit different. However, this are the settings that worked the best for me. I also did the same for IKEA E1743, which has the brightness_up and brightness_down functions as well. You just need to add the following code in a file and put it inside “packages”. It uses the same python script.

automation:
  - id: simple_controller_toggle
    alias: Simple Controller - Toggle
    trigger:
      - platform: state
        entity_id: sensor.YOURCONTROLLER_click
        to: "off"
      - platform: state
        entity_id: sensor.YOURCONTROLLER_click
        to: "on"
    condition:
    action:
      - service: light.toggle
        data:
          entity_id: light.YOURLIGHT
  - id: simple_controller_brighten_on
    alias: Simple Controller- Brighten on
    trigger:
      - platform: state
        entity_id: sensor.YOURCONTROLLER_click
        to: brightness_up
    condition:
      - condition: state
        entity_id: light.YOURLIGHT
        state: "on"
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.light_E1743_brightness
      - service: python_script.change_attribute_light_smoothly
        data:
          light_id: light.YOURLIGHT
          input_boolean: input_boolean.light_E1743_brightness
          delta: 20
  - id: simple_controller_dim_on
    alias: Simple Controller- Dim on
    trigger:
      - platform: state
        entity_id: sensor.YOURCONTROLLER_click
        to: brightness_down
    condition:
      - condition: state
        entity_id: light.YOURLIGHT
        state: "on"
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.light_E1743_brightness
      - service: python_script.change_attribute_light_smoothly
        data:
          light_id: light.YOURLIGHT
          input_boolean: input_boolean.light_E1743_brightness
          delta: -20

  - id: simple_controller_brighten_dim_off
    alias: Simple Controller- Brighten/Dim off
    initial_state: "on"
    trigger:
      - platform: state
        entity_id: sensor.YOURCONTROLLER_click
        to: brightness_stop
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.light_E1743_brightness
          state: "on"
        - condition: state
          entity_id: light.YOURLIGHT
          state: "on"
    action:
      - service: input_boolean.turn_off
        entity_id: input_boolean.light_E1743_brightness

input_boolean:
  light_E1743_brightness:
    name: Light E1743 brigthness
    initial: off
2 Likes

Hey guys,

I created an app for AppDaemon to give a better and flexible solution to this. If you have more than one controller you can add a new instance app and that’s it. I don’t support group of lights, just 1 sensor connected with 1 light. However, you can connect them by creating different apps with multiple lights and the same controller in all of them. You can see the post about it here.

Thanks for this yaml, got it working except for color warmth. I get this error when pressing it:

Error while executing automation automation.lounge_light_remote_warm_down. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 443, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 190, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 273, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 355, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 87, in async_call_from_config
    template.render_complex(config[CONF_SERVICE_DATA_TEMPLATE], variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 71, in render_complex
    return {key: render_complex(item, variables) for key, item in value.items()}
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 71, in <dictcomp>
    return {key: render_complex(item, variables) for key, item in value.items()}
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 73, in render_complex
    return value.async_render(variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 222, in async_render
    return compiled.render(kwargs).strip()
  File "/usr/local/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

This is my yaml:

- id: Lounge_light_remote_warm_up
  alias: Lounge Light Warm Up
  trigger:
    platform: state
    entity_id: sensor.0x000d6ffffe179359_action
    to: arrow_right_click
  action:
    data_template:
      entity_id: light.0x000d6ffffe2a96db_light
      color_temp: "{{ state_attr('light.0x000d6ffffe2a96db_light', 'color_temp') + 75 }}"
    service: light.turn_on

- id: Lounge_light_remote_warm_down
  alias: Lounge Light Remote Warm Down
  trigger:
    platform: state
    entity_id: sensor.0x000d6ffffe179359_action
    to: arrow_left_click
  action:
    data_template:
      entity_id: light.0x000d6ffffe2a96db_light
      color_temp: "{{ state_attr('light.0x000d6ffffe2a96db_light', 'color_temp') - 75 }}"
    service: light.turn_on

Hi @Morphy

Which type of light are you using? Does it support color_temp? In other words, can you change the color temperature from the home assistant UI?

On a side note, I recommend you to check out this post. I put all this code together in a app for appdaemon and I put it on HACS, so you can download the latest code in there and have many more feature than these scripts.

Hola Xavi
It doesn’t actually, I thought it would being a colour bulb :confused: It’s an Ikea LED1624G9 which only supports on/off, brightness, color xy
I’ll have to look into appdaemon I’ve heard it mentioned.

In the meantime I changed the arrow buttons to colour cycle instead:

- id: FP_light_remote_colour_clockwise
  alias: Fireplace Light Remote Clockwise
  trigger:
    platform: state
    entity_id: sensor.fireplace_light_remote_action
    to: arrow_right_click
  action:
    service: light.turn_on
    data_template:
      entity_id: light.fireplace_light
      hs_color:
        - "{{ (15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
        - 100

- id: FP_light_remote_colour_anticlockwise
  alias: Fireplace Light Remote Anticlockwise
  trigger:
    platform: state
    entity_id: sensor.fireplace_light_remote_action
    to: arrow_left_click
  action:
    service: light.turn_on
    data_template:
      entity_id: light.fireplace_light
      hs_color:
        - "{{ (-15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
        - 100

I did have a colourcycle script which cycled through for a long press but it would sometimes stay on and it felt a bit hacky making the script keep running. It also made the poor SD card on my RPi3 go crazy and it didn’t cycle quick enough for my liking.

- id: FP_light_remote_colour_cycle_on
  alias: Fireplace Light Remote Colour Cycle On
  trigger:
    - platform: state
      entity_id: sensor.fireplace_light_remote_action
      to: arrow_right_hold
  condition:
    - condition: state
      entity_id: light.fireplace_light
      state: "on"
  action:
    - service: script.turn_on
      entity_id: script.light_colour_cycle3

- id: FP_light_remote_colourcycle_off
  alias: Fireplace Light Remote Colour Cycle Off
  trigger:
    - platform: state
      entity_id: sensor.fireplace_light_remote_action
      to: arrow_right_release
  condition:
    - condition: state
      entity_id: light.fireplace_light
      state: "on"
  action:
    - service: script.turn_off
      entity_id: script.light_colour_cycle3
    - service: script.turn_off
      entity_id: script.light_colour_cycle4

- id: FP_light_remote_colour_cycle_reverse_on
  alias: Fireplace Light Remote Colour Cycle Reverse On
  trigger:
    - platform: state
      entity_id: sensor.fireplace_light_remote_action
      to: arrow_left_hold
  condition:
    - condition: state
      entity_id: light.fireplace_light
      state: "on"
  action:
    - service: script.turn_on
      entity_id: script.light_colour_cycle5

- id: FP_light_remote_colourcycle_reverse_off
  alias: Fireplace Light Remote Colour Cycle Reverse Off
  trigger:
    - platform: state
      entity_id: sensor.fireplace_light_remote_action
      to: arrow_left_release
  condition:
    - condition: state
      entity_id: light.fireplace_light
      state: "on"
  action:
    - service: script.turn_off
      entity_id: script.light_colour_cycle5
    - service: script.turn_off
      entity_id: script.light_colour_cycle6

Script:

light_colour_cycle3:
  alias: Hue Light Colour Cycle3
  sequence:
    - service: light.turn_on
      entity_id: light.fireplace_light
      data_template:
        hs_color:
          - "{{ (15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
          - 100
        brightness_pct: 100
        transition: 1
    - delay: '00:00:1'
    - service: script.turn_on
      entity_id: script.light_colour_cycle4

light_colour_cycle4:
  alias: Hue Light Colour Cycle4
  sequence:
    - service: light.turn_on
      entity_id: light.fireplace_light
      data_template:
        hs_color:
          - "{{ (15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
          - 100
        brightness_pct: 100
        transition: 1
    - delay: '00:00:1'
    - service: script.turn_on
      entity_id: script.light_colour_cycle3

light_colour_cycle5:
  alias: Hue Light Colour Cycle5
  sequence:
    - service: light.turn_on
      entity_id: light.fireplace_light
      data_template:
        hs_color:
          - "{{ (-15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
          - 100
        brightness_pct: 100
        transition: 1
    - delay: '00:00:1'
    - service: script.turn_on
      entity_id: script.light_colour_cycle6

light_colour_cycle6:
  alias: Hue Light Colour Cycle6
  sequence:
    - service: light.turn_on
      entity_id: light.fireplace_light
      data_template:
        hs_color:
          - "{{ (-15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
          - 100
        brightness_pct: 100
        transition: 1
    - delay: '00:00:1'
    - service: script.turn_on
      entity_id: script.light_colour_cycle5

I’d like to get the hold arrow to move in and out of the saturation of the colour but I don’t really know what I’m doing with this expression:

hs_color:
          - "{{ (15 + (state_attr('light.fireplace_light', 'hs_color')[0] or 0)) % 360 }}"
          - 100

I have got some different uses for the buttons with my white only lights which I will post as well.
This was the best one I came up with though. Reset the light by long pressing the power button. Even though it mostly turned it off first it seemed to work after a few seconds.

- id: FP_light_remote_reset
  alias: Fireplace Light Remote - Reset
  trigger:
    - platform: state
      entity_id: sensor.fireplace_light_remote_action
      to: "toggle_hold"
  condition:
  action:
  - service: light.turn_on
    data:
      entity_id: light.fireplace_light
      rgb_color: [255,255,255]
      brightness: 255

I also added a condition to this so it would reset to cool white in daylight hours and warm white in night hours.

I would strongly recommend taking a look to the app from AppDaemon, with just 4 lines of code, you connect the sensor with the light. I recently gave support to xy color lights, so it cycles through a list of colors. You can check which colors it goes through in here. Unfortunately, I do not have a video with the smoothness of the color changing, but I can assure you it is quite smooth since I use the transition attribute. I tested it with the same light you have, the LED1624G9. The configuration would look like this for you:

fireplace_light:
  module: z2m_ikea_controller
  class: E1810Controller
  sensor: sensor.fireplace_light_remote_action
  light: light.fireplace_light

If you need any help with the setup, let me know.

1 Like

I have not used appdeamon before.
Could you @xaviml please help me with some guidelines for your app?

What I want is to use the ikea 5 button switch to dim my tasmotised light bulb using mqtt.
Now I run ikea through deconz

Hi @Jurgmaister, is your light connected to HA? This is the first thing you should do if you haven’t since the appdaemon app doesn’t do any mqtt calls.

Regarding AppDaemon, you just need to install the addon of AppDaemon 4.x from the community store (assuming you have home assistant (fka hassio) running). You can follow their instructions to make it up and running and then you can either install the app from HACS or download the controllerx folder and put it inside /config/appdaemon/apps/. Let me know if you have any questions.

Thanks for quick respons @xaviml.
My bulb is connected til HA using mqtt - it is working, both toggle and dimming.

So it is the appdeamon part I would appreciate some help with.
I guess I would need some help, also with the initial setup even though I have installed AppDaemon with Frencks add-on.

I guess I understand it correct that after installing Controllerx in hacs (or manual), I do the rest of the configuration in the apps.yaml?

Yes, that is right. Once you have AppDaemon and ControllerX installed, then you need to add your configuration in apps.yaml. The way AppDaemon works is that you can define automations with Python code (this is what ControllerX does) and then you can instanciate those automations (called apps) from a yaml configuration. In the case of ControllerX, each instance of an app binds a controller with an entity (e.g. light). You can follow the Configuration part from the README.md and copy that into your apps.yaml. If you tell me the entity of your light and the id of your device with deCONZ, I can give your the configuration that you need.

@xaviml thanks again!
I managed to get it working.
It was much easier than I was expecting.

For others who might be interested.
All I did was put this in apps.yaml;

[name the “scrip”] (feks “nightstand_light_masterbedroom”):
module: controllerx
class: E1810Controller
event_id: [from device you want to use, picked up by “deconz_event” in service tab]
light: [name of light entity]

Like this;

hovedsoverom:
module: controllerx
class: E1810Controller
event_id: bryter_hovedsoverom
light: light.nedis_hovedsoverom

1 Like

Thanks @Jurgmaister

I am working on a better documentation, but as you said it’s pretty straight forward, but that is thanks of how AppDaemon works, which is amazing!

1 Like

While the ControllerX is an awesome piece of software, using zigbee binding (https://www.zigbee2mqtt.io/information/binding.html) gives that without coordinator involvement.

I stumbled upon binding when one of the E1810 remotes would, without any good explanation, control Xiaomi wall switch in another room. Three did not have any side effect (it turned out they are bound to group 901), one would have (it was bound to group 0). Resetting it with four presses didn’t help.

Zigbee2mqttAssistant can help out with setting the bindings. You can do them manually as well, by sending messages to zigbee2mqtt/bridge/bind/*remote_name* topic.

1 Like

Hi all, I have question regarding to code posted by “xaviml”
I have manage to make it running but only for one light. I have a problem to control groups of lights with this code. I was using entity_id:group.kitchen - but dim/color function is not working.
If i use light.kitchen_1 then it is working.

Hi’ @ondrabanov

Did you manage to sort your issues ?

I’m using ControllerX with multiple group of lights, both via z2m and Hue Bridge integration - all working perfectly.

Remember that when controlling groups of lights, ControllerX reads supported_features for first entity in group and assumes that these features can be applied to remaining entities in group.

Ciao !

Ikea controller E1524 automation not working in “state” platform. What is wrong here.

This does WORK coorectly

automation:
  - id: 'bordlamp_ikea_bryter'
    alias: Bordlamp ikea bryter
    trigger:
    - entity_id: sensor.bordlampe_ikea_bryter_action
      platform: state
      to: toggle
    condition: []
    action:
    - data:
        entity_id: light.bordlampe
      service: light.toggle

But, this does NOT WORK

automation:
  - id: 'bordlamp_ikea_bryter'
    alias: Bordlamp ikea bryter
    trigger:
      - platform: state
        entity_id: sensor.bordlampe_ikea_bryter_action
        to: "off"
      - platform: state
        entity_id: sensor.bordlampe_ikea_bryter_action
        to: "on"
    condition:
    action:
      - service: light.toggle
        data:
          entity_id: light.bordlampe

Hi @smile,

The second configuration is not working because the E1524 controller does not fire a “on” and “off” state. You can check the states that it fires in zigbee2mqtt in here.

Hi @xaviml, Thanks for your code. It works well with TRADFRI remote control (E1524/E1810) by IKEA. But unfortunately right and left arrow is not working as my Philips Hue light doesn’t have color_temp attribute.
Below find attribute details from Developer Tools/States for Philips Hue lights.

min_mireds: 153
max_mireds: 500
effect_list: random, colorloop
brightness: 255
hs_color: 45, 21.961
rgb_color: 255, 240, 198
xy_color: 0.37, 0.372
effect: none
entity_id: light.dining_room
friendly_name: Dining Room
supported_features: 63

Please suggest the solution for changing temperature from “Day light” to “Warm White”.