ZHA IKEA Tradfri Shortcut button firmware 2.3.075 or greater

Check the version number of your shortcut button

As of 2.3.075 the shortcut buttons no longer fire multiple messages for each press, and a new double press “off” command is introduced. This makes automations much simpler.

Checking software version numbers in ZHA:

  1. Device page of the device in question
  2. 3 dots next to “RECONFIGURE” → Manage Zigbee Device
  3. Clusters → Basic (Endpoint id: 1, Id: 0x0000, Type: in)
  4. Cluster Attributes → sw_build_id (id: 0x4000)
  5. Click Read Attribute
  6. If device is battery powered, trigger it somehow
  7. The version should appear in the “Value” box

If you are using an older version then you can have a look at this blueprint ZHA - IKEA Tradfri Shortcut button

If you want to update your firmware then you may find this link useful. But beware, your other Tradfri products are likely to be updated during the process and there are some breaking changes, particularly with the binding behaviour of the on/off switches.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: ZHA - IKEA Tradfri Shortcut button
  description: Control anything with the ikea shortcut button
  source_url: https://https://community.home-assistant.io/t/zha-ikea-tradfri-shortcut-button-firmware-2-3-075-or-greater/402565
  domain: automation
  input:
    shortcut_button:
      name: Device
      description: Select an IKEA shortcut button
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: TRADFRI SHORTCUT Button
    button_short:
      name: Single click
      description: 'Choose action(s) when short pressed:'
      default: []
      selector:
        action: {}
    button_double:
      name: Double click
      description: 'Choose action(s) when double pressed:'
      default: []
      selector:
        action: {}
    button_long:
      name: Long click
      description: 'Choose action(s) when long pressed:'
      default: []
      selector:
        action: {}
    button_release:
      name: Release Long Click
      description: 'Choose action(s) (if any) when releasing long press. This will run in a separate call of the automation so in "single" mode it may be suppressed by the long-press action if that takes some time. It cannot easily be used to stop a long-press action, for that - use mode: "restart instead" '
      default: []
      selector:
        action: {}
    automation_mode:
      name: Automation Mode
      description: 'The [mode](https://www.home-assistant.io/docs/automation/modes/) for this automation. Default is "single" - further actions are blocked whilst the automation is running. Choose "resart" if you want the long-press action to stop on release.'
      default: single
      selector:
        select:
          options:
            - single
            - restart
            - queued
            - parallel
mode: !input 'automation_mode'
max_exceeded: silent
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      cluster_id: 6
      device_id: !input 'shortcut_button'
  - platform: event
    event_type: zha_event
    event_data:
      cluster_id: 8
      device_id: !input 'shortcut_button'
action:
- variables:
    command: '{{ trigger.event.data.command }}'
    cluster_id: '{{ trigger.event.data.cluster_id }}'
    endpoint_id: '{{ trigger.event.data.endpoint_id }}'
    args: '{{ trigger.event.data.args }}'
- choose:
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 6 }}'
    - '{{ command == ''on'' }}'
    sequence:
    - choose:
      default: !input 'button_short'
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 6 }}'
    - '{{ command == ''off'' }}'
    sequence:
    - choose:
      default: !input 'button_double'
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 8 }}'
    - '{{ command == ''move_with_on_off'' }}'
    sequence:
    - choose:
      default: !input 'button_long'
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 8 }}'
    - '{{ command == ''stop_with_on_off'' }}'
    sequence:
    - choose:
      default: !input 'button_release'

Fork of: ZHA - IKEA Tradfri Shortcut button
I beta test new features here: BETA TESTING - ZHA IKEA Tradfri Shortcut button firmware 2.3.075 or greater

Edit 1: On my install at least, the ‘wait_for_trigger’ is never triggered and the automation times out.
Edit 2: 2023-07-02 Edited post instructions for checking firmeware version for the new UI.
Edit 3: Added “max_exceeded: silent” back into version 2 to stop cluttering logs.

2023-07-02 Version 2 release:

  1. Removed the “wait_for_trigger:” and “timeout” blocks as I am not sure what they were achieving
  2. The automation will only trigger on “cluster_id” 6 and 8. So it will no longer trigger on device “checkin” which will simplify logbooks, debugging and traces.
  3. Automation mode is now user-configurable
  4. Button release action is now configurable. Useful for making something happen after the long press has finished. Such as saving a device state or toggling a config variable.

To update either just click the Import Blueprint button above or see the guide here.

See example automation with a long-press dimming feature here: ZHA IKEA Tradfri Shortcut button firmware 2.3.075 or greater - #14 by HarvsG

4 Likes

Thank you for this! Just noticed my double click actions stopped working, and the new “off” events coming from the button. Was about ready to rewrite this thing myself, but glad to see your working fix beat me to it :slight_smile:

1 Like

Sadly I always get the following error message, even when I try to save it as empty (only setting target device, but no actions):

Message malformed: expected a dictionary for dictionary value @ data['action'][0]['variables']

I‘ve got the same problem. Do you have a solution yet?

judging by your error it is not seeing this as a dictionary, no idea why! What version of HA are you using, and I’ll have a look through the breaking changes.

    command: '{{ trigger.event.data.command }}'
    cluster_id: '{{ trigger.event.data.cluster_id }}'
    endpoint_id: '{{ trigger.event.data.endpoint_id }}'
    args: '{{ trigger.event.data.args }}'

Edit maybe some bad indenting, try now

I‘ll try it again-same error.

Home Assistant 2023.1.6
Supervisor 2022.12.1
Operating System 9.4
Frontend 20230110.0 - latest

May be fixed now?

I think it was some subtle indenting/ tabs and spaces error I introduced.

Hey @HarvsG, yes, it does seem to be working for me now. Thanks for looking into! :pray:

1 Like

Is there a way for the long press action to continuously increase/decrease light brightness while it’s held?

Probably, but not with this blueprint. IIRC a “Stop” command is sent on release. So you could trigger a loop that starts with move_with_on_off and ends when a “stop” message runs.

Thank you! I couldn’t figure out how to include a trigger in my automation created from your blueprint. So I have the loop being stopped by an input_boolean helper being toggled on, and having a separate automation detect the release command and toggle the helper. I added in a bit of a delay (350 ms) in the loop for increasing the brightness and it works perfectly like I want.

If you happen to know how I could include the zha_event as a trigger in the automation created from your blueprint, that would be great to simplify things.

Untested but something like this might work:

blueprint:
  name: ZHA - IKEA Tradfri Shortcut button
  description: Control anything with the ikea shortcut button
  domain: automation
  input:
    shortcut_button:
      name: Device
      description: Select an IKEA shortcut button
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: TRADFRI SHORTCUT Button
    button_short:
      name: Single click
      description: 'Choose action(s) when short pressed:'
      default: []
      selector:
        action: {}
    button_double:
      name: Double click
      description: 'Choose action(s) when double pressed:'
      default: []
      selector:
        action: {}
    button_long:
      name: Long click
      description: 'Choose action(s) when long pressed:'
      default: []
      selector:
        action: {}
    button_release:
      name: Release Long Click
      description: 'Choose action(s) when releasing long press:'
      default: []
      selector:
        action: {}
  source_url: https://community.home-assistant.io/t/draft-zha-ikea-tradfri-shortcut-button-firmware-2-0-80-or-greater/402565
mode: single
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'shortcut_button'
action:
- variables:
    command: '{{ trigger.event.data.command }}'
    cluster_id: '{{ trigger.event.data.cluster_id }}'
    endpoint_id: '{{ trigger.event.data.endpoint_id }}'
    args: '{{ trigger.event.data.args }}'
- choose:
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 6 }}'
    - '{{ command == ''on'' }}'
    sequence:
    - choose:
      default: !input 'button_short'
    - wait_for_trigger:
      - platform: event
        event_type: zha_event
        event_data:
          device_id: !input 'shortcut_button'
          endpoint_id: 1
          cluster_id: 6
          command: 'on'
      timeout:
        seconds: 1
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 6 }}'
    - '{{ command == ''off'' }}'
    sequence:
    - choose:
      default: !input 'button_double'
    - wait_for_trigger:
      - platform: event
        event_type: zha_event
        event_data:
          device_id: !input 'shortcut_button'
          endpoint_id: 1
          cluster_id: 6
          command: 'off'
      timeout:
        seconds: 1
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 8 }}'
    - '{{ command == ''move_with_on_off'' }}'
    sequence:
    - choose:
      default: !input 'button_long'
    - wait_for_trigger:
      - platform: event
        event_type: zha_event
        event_data:
          device_id: !input 'shortcut_button'
          endpoint_id: 1
          cluster_id: 8
          command: 'move_with_on_off'
      timeout:
        seconds: 1
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 8 }}'
    - '{{ command == ''stop_with_on_off'' }}'
    sequence:
    - choose:
      default: !input 'button_release'
    - wait_for_trigger:
      - platform: event
        event_type: zha_event
        event_data:
          device_id: !input 'shortcut_button'
          endpoint_id: 1
          cluster_id: 8
          command: 'stop_with_on_off'
      timeout:
        seconds: 1

Since I’ve written this untested I would suspect that these bits would cause issues as I don’t remember the cluster_id and command for the release command I have checked and these are correct.

    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 8 }}'
    - '{{ command == ''stop_with_on_off'' }}'

The automation runs in single mode (which means it can’t be triggered until the last run has finished) which may cause issues with the stop command being blocked, so you may want to try other modes. And/or remove all the wait for trigger blocks as I am not sure they achieve anything and cause the automation to stay in the ‘running’ state for longer.

mode: single

Try this version and see if it works for you: Specifically test brief long-presses.

Version 2 released today. 2023-07-02:

Example:
An example of a version that dims a light until the button is released. Automation Mode: restart is doing the work of ‘stopping’ here - when the button is released the automation is triggered again (but performs no action) which interrupts the previous run which was doing the dimming.

alias: "[ZHA] Shortcut Button - Study"
description: ""
use_blueprint:
  path: HarvsG/zha-ikea-tradfri-shortcut-button-firmware-2-3-075-or-greater.yaml
  input:
    shortcut_button: cf69732507e91ead4a2f4c7ffae3e7b5
    button_short:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.study_light
    button_double:
      - service: light.toggle
        data: {}
        target:
          entity_id: light.study_lamp
    button_long:
      - repeat:
          while:
            - condition: numeric_state
              entity_id: light.study_lamp
              below: 256
              above: 3
              attribute: brightness
          sequence:
            - service: light.turn_on
              data:
                brightness_step_pct: -1
              target:
                entity_id: light.study_lamp
    button_release: []
    automation_mode: restart

If you wanted the button to switch between dimming and brightening, you could create a choose block in the repeat loop that relies on a hidden input boolean and toggle the boolean in button_release. Another solution would be to use a choose block but decide based on the current brightness of the light.

Hi,

I get this error message MANY times in the log. Any idea of what’s wrong??

2023-07-08 19:18:31.877 WARNING (MainThread) [homeassistant.components.automation.beta_zha_ikea_tradfri_shortcut_button] BETA ZHA - IKEA Tradfri Shortcut button: Already running

Thank you for pointing this out. Now fixed in Edit 3.
This shouldn’t have caused any failures, it was expected behaviour of single mode, I have added max_exceeded: silent back in to silence these log messages.

1 Like

Hi @HarvsG - would you be able to create / share a Zigbee2MQTT version of this blueprint?

Unfortunately not as I run ZHA, however with the new events entity introduced in 2022.8 this blueprint will likely become much simpler/obsolete when ZHA and Z2M implement it.