ZHA - IKEA TRADFRI - 5 Button Remote - Custom Actions

Have a look at the code in this blueprint to understand more about the inner workings.

done, thank you. you’ve done really good work here.

for everybody else that may be wondering how to combine the Custom Actions blueprint with something like the Warm Lights blueprint, try out the code here:

---
# This automation simulates the use of the IKEA TRADFRI Remote control
# connected through ZHA.

# | Button   | Action               |
# | -------- | -------------------- |
# | Power    | Toggle the light     |
# | Dim-Up   | Increase brightness  |
# | Dim-Down | Decrease brightness  |
# | Right    | Custom Action        |
# | Left     | Custom Action        |

blueprint:
  name: ZHA - IKEA TRADFRI - 5 Button Remote - Warm White Lights + Custom Right/Left Presets
  # merged these two:
  # https://community.home-assistant.io/t/zha-ikea-tradfri-5-button-remote-warm-white-lights/284738
  # https://community.home-assistant.io/t/zha-ikea-tradfri-5-button-remote-custom-actions/284720

  description: >-
    This automation simulates the use of the IKEA TRADFRI remote control
    connected through ZHA.

  domain: automation

  input:
    remote:
      name: IKEA TRADFRI remote control
      description: Select the remote control you wish to use.
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: TRADFRI remote control
    light:
      name: Light
      description: Select the light entity you wish to control.
      selector:
        entity:
          domain: light
    speed:
      name: Speed
      description: The speed in which to update the light when the button is held.
      selector:
        number:
          min: 100
          max: 1000
          step: 100
          unit_of_measurement: milliseconds
          mode: slider
      default: 500

    colorup_short:
      name: Short Press - Color Up Button
      description: The action to perform on Short Press of the Color Up Button
      selector:
        action:
      default: []
    colordown_short:
      name: Short Press - Color Down Button
      description: The action to perform on Short Press of the Color Down Button
      selector:
        action:
      default: []
    colorup_long:
      name: Long Press - Color Up Button
      description: The action to perform on Long Press of the Color Up Button
      selector:
        action:
      default: []
    colordown_long:
      name: Long Press - Color Down Button
      description: The action to perform on Long Press of the Color Down Button
      selector:
        action:
      default: []

mode: restart
max_exceeded: silent

variables:
  var_light: !input light
  var_speed: !input speed

trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input remote

action:
  - choose:
      # Short-Press on the power button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "toggle" }}'
        sequence:
          - service: light.toggle
            target:
              entity_id: !input light

      # Long-Press on the power button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "move_to_level_with_on_off" }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light
            data:
              brightness: 254
              color_temp: 400

      # Short-Press on the dim-up button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "step_with_on_off" }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light
            data:
              brightness_step_pct: 20
              transition: "{{ (var_speed / 1000)|float }}"

      # Long-Press on the dim-up button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "move_with_on_off" }}'
        sequence:
          - repeat:
              while: []
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light
                  data:
                    brightness_step_pct: 10
                    transition: "{{ (var_speed / 1000)|float }}"
                - delay:
                    milliseconds: !input speed

      # Short-Press on the dim-down button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "step" }}'
        sequence:
          - service: light.turn_on
            target:
              entity_id: !input light
            data:
              brightness_step_pct: -20
              transition: "{{ (var_speed / 1000)|float }}"

      # Long-Press on the dim-down button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "move" }}'
        sequence:
          - repeat:
              while: []
              sequence:
                - service: light.turn_on
                  target:
                    entity_id: !input light
                  data:
                    brightness_step_pct: -10
                    transition: "{{ (var_speed / 1000)|float }}"
                - delay:
                    milliseconds: !input speed

      # Short-Press on the color-up button.
      # - conditions:
      #     - condition: template
      #       value_template: '{{ trigger.event.data.command == "press" }}'
      #     - condition: template
      #       value_template: "{{ trigger.event.data.args == [256,13,0] }}"
      #   sequence:
      #     - service: light.turn_on
      #       target:
      #         entity_id: !input light
      #       data:
      #         color_temp: >-
      #           {% if state_attr(var_light, "color_temp") - 18 < 153 %}
      #             {{ 153 }}
      #           {% else %}
      #             {{ state_attr(var_light, "color_temp") - 18 }}
      #           {% endif %}
      #         transition: "{{ (var_speed / 1000)|float }}"

      # Short-Press on the color-up button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "press" }}'
          - condition: template
            value_template: "{{ trigger.event.data.args == [256,13,0] }}"
        sequence: !input colorup_short

      # Long-Press on the color-up button.
      # - conditions:
      #     - condition: template
      #       value_template: '{{ trigger.event.data.command == "hold" }}'
      #     - condition: template
      #       value_template: "{{ trigger.event.data.args == [3328,0] }}"
      #   sequence:
      #     - repeat:
      #         while: []
      #         sequence:
      #           - service: light.turn_on
      #             target:
      #               entity_id: !input light
      #             data:
      #               color_temp: >-
      #                 {% if state_attr(var_light, "color_temp") - 18 < 153 %}
      #                   {{ 153 }}
      #                 {% else %}
      #                   {{ state_attr(var_light, "color_temp") - 18 }}
      #                 {% endif %}
      #               transition: "{{ (var_speed / 1000)|float }}"
      #           - delay:
      #               milliseconds: !input speed

      # Long-Press on the color-up button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "hold" }}'
          - condition: template
            value_template: "{{ trigger.event.data.args == [3328,0] }}"
        sequence: !input colorup_long

      # Short-Press on the color-down button.
      # - conditions:
      #     - condition: template
      #       value_template: '{{ trigger.event.data.command == "press" }}'
      #     - condition: template
      #       value_template: "{{ trigger.event.data.args == [257,13,0] }}"
      #   sequence:
      #     - service: light.turn_on
      #       target:
      #         entity_id: !input light
      #       data:
      #         color_temp: >-
      #           {% if state_attr(var_light, "color_temp") + 18 > 500 %}
      #             {{ 500 }}
      #           {% else %}
      #             {{ state_attr(var_light, "color_temp") + 18 }}
      #           {% endif %}
      #         transition: "{{ (var_speed / 1000)|float }}"

      # Short-Press on the color-down button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "press" }}'
          - condition: template
            value_template: "{{ trigger.event.data.args == [257,13,0] }}"
        sequence: !input colordown_short

      # Long-Press on the color-down button.
      # - conditions:
      #     - condition: template
      #       value_template: '{{ trigger.event.data.command == "hold" }}'
      #     - condition: template
      #       value_template: "{{ trigger.event.data.args == [3329,0] }}"
      #   sequence:
      #     - repeat:
      #         while: []
      #         sequence:
      #           - service: light.turn_on
      #             target:
      #               entity_id: !input light
      #             data:
      #               color_temp: >-
      #                 {% if state_attr(var_light, "color_temp") + 18 > 500 %}
      #                   {{ 500 }}
      #                 {% else %}
      #                   {{ state_attr(var_light, "color_temp") + 18 }}
      #                 {% endif %}
      #               transition: "{{ (var_speed / 1000)|float }}"
      #           - delay:
      #               milliseconds: !input speed

      # Long-Press on the color-down button.
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command == "hold" }}'
          - condition: template
            value_template: "{{ trigger.event.data.args == [3329,0] }}"
        sequence: !input colordown_long

    # Any other event will cancel the repeat loops.
    default: []

What this code does is basically give you the option to use the Left/Right arrow keys for custom actions AND the original Warm Lights (incl. smooth brightness controls)

the input fields look like this:

Thank you!

I’d tried other blueprints that were too complex for me to get working but this one just works! Thanks again.

1 Like


How can I see my IKEA remote like this?

In the ZHA integration page

Hello!

The up/down buttons seem to have stopped working for me. I see this in the log (but no light brightness increase/decrease)

TRADFRI 5 Button Remote Control B Step event was fired with parameters: {'step_mode': <StepMode.Down: 1>, 'step_size': 43, 'transition_time': 5, 'options_mask': <bitmap8: 0>, 'options_override': <bitmap8: 0>}

Any ideas?

I already tried removing and re-adding the device, but it did not help.

Thanks!

I’ll have a look.

Thanks, this works! I’m using it to control a pair of speakers. Dim Up/Down = Volume Up/Down. The step is too much though, is this choose-hack also applicable in my case?

(I wonder why you chose to call it color Up/Down… would be more logical with Right/Left?)