ZHA - IKEA Tradfri Shortcut button

Explanation

This automation blueprint is for the Ikea shortcut button. This only works if u use ZHA integration to connect the shortcut button. You can add any action to the button for a short press, double press or long press.

Just copy the url of this post and add it to your blueprints.

Blueprint Code

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

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
  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: {}
  source_url: https://community.home-assistant.io/t/zha-ikea-tradfri-shortcut-button/261936
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:

  # short click
  - conditions:
    - '{{ endpoint_id == 1 }}'
    - '{{ cluster_id == 6 }}'
    - '{{ command == ''on'' }}'
    sequence:

    # check for a second click
    - 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:
        milliseconds: 600
      continue_on_timeout: true
    - choose:
      # if single click
      - conditions:
        - condition: template
          value_template: '{{ not wait.trigger }}'
        sequence: !input 'button_short'
      # else double click
      default: !input 'button_double'

  # long click
  - 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: stop
      timeout:
        seconds: 10

Trouble shooting

If you're experiencing problems with this automation it`s probably because zha_events are fired multiple times after a single press. You can check this by monitoring zha_event. I'm not sure why but some people do experience this. Unfortunately, this can't be fixed within the same automation blueprint because this interferes with the double press action. Therefore I created a separate automation to fix this but without double press action:

zha-ikea-tradfri-shortcut-button-debounced

Changelog

  • 2020-12-30: First initial release.
  • 2021-01-05: Make sure the long-press action runs once while pressed.
  • 2021-01-08: Add double press function. Updated description.
5 Likes

First I want to say thanks for making my life my easier. :slight_smile:

However, I am having a little bit of trouble getting this to work smoothly.
zha_event shows that one button press gives 5-6 “on” in a row.
Because of this the smart plug in my automation (based on this blueprint) often turns on and then off. It flashes the lights.

Is there a way of getting the blueprint to put in a wait before acting on the next registered button press? The 5-6 events corresponding to the same button press comes immediately so the wait doesn’t have to be more than a couple of milliseconds.

Hello Mindlight and thank you for using my blueprint :grinning:

I didn’t notice this behaviour on my setup but i already have a fix in mind. I’ll try to update it this evening and let you know when it’s there so you can test it.

@Mindlight I`ve updated the blueprint now to make sure the longpress button action only run once until released. With thanks to @123 for the sequence hack :+1:

Although I can’t replicate the behaviour, I remember noticing this behaviour a while ago. maybe your shortcut button has to be updated? anyway let me know if the updated blueprint works for you!

Today I played around and found out that the problem seems to be related to my Lidl (white labeled Tuya) Smart Plugs. If I use your blueprint with my TrĂĄdfri shortcut button with my TrĂĄdfri Smart plugs it works flawlessly.

Now when I write this it’s evening and I replaced the Lidl Smart Plug with a Lidl 3-way Smart USB Extension Lead earlier today. Didn’t think much of it but when I started writing this tonight I thought I’d remap the automation to the extension lead…and… it just works perfect.
I know I still had trouble this morning with the Lidl Smart Plug… weird… but now it works just fine.
Thanks for the help :slight_smile:

I’m also seeing duplicate events off of my Tradfri shortcut button. I’ve confirmed that it’s on the latest OTA.

Each single tap is raising 5-6 zha_events being caught by this automation. I can handle it by adding a 1s delay at the end of the automation and let the single/silent behavior carry it, but it is going to be non-intuitive for most users.

I updated the blueprint to wait untill its released so it should only run once! Please verify that the blueprint is updated, or remove and install it again. You can find it in the folder config/blueprints/automation/mcflexus/

Confirmed that I’m on the latest version of the blueprint. I’m seeing the duplicate events with the short taps, not the long press, since my button raises 6 events in a very short window.

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:37.093623+00:00",
    "context": {
        "id": "a0f757915f13c6a9673434479f349b59",
        "parent_id": null,
        "user_id": null
    }
}
Event 5 fired 5:24 PM:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:37.003429+00:00",
    "context": {
        "id": "b96232f517f42f791539d7bc101ff04c",
        "parent_id": null,
        "user_id": null
    }
}
Event 4 fired 5:24 PM:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:36.904876+00:00",
    "context": {
        "id": "b33f3757d921dcfd04e90191572960b5",
        "parent_id": null,
        "user_id": null
    }
}
Event 3 fired 5:24 PM:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:36.813881+00:00",
    "context": {
        "id": "301080f1367d7c525186ad5e263c9b55",
        "parent_id": null,
        "user_id": null
    }
}
Event 2 fired 5:24 PM:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:36.723857+00:00",
    "context": {
        "id": "23346a949e898ac0812a143cfdf66f07",
        "parent_id": null,
        "user_id": null
    }
}
Event 1 fired 5:24 PM:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:36.634831+00:00",
    "context": {
        "id": "2fc6efc56e032e563f606593fe2d9a8d",
        "parent_id": null,
        "user_id": null
    }
}
Event 0 fired 5:24 PM:
{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "ec:1b:bd:ff:fe:d4:4a:9c",
        "unique_id": "ec:1b:bd:ff:fe:d4:4a:9c:1:0x0006",
        "device_id": "b64cde51d2dc1d80cd97f67b7b1aa914",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "on",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-08T01:24:36.541861+00:00",
    "context": {
        "id": "a7b053e40129ed7115c3e1dab847e078",
        "parent_id": null,
        "user_id": null
    }
}

I’m able to work around this by adding a 1s delay into my sequence (with single + silent notification), but if we could otherwise debounce within the blueprint, it would be easier for other users to adopt.

I’m currently testing the double click action so i can’t add the delay. Strang thing is I can’t double click to fast or it will show only one zha_event. What is the current firmware of your shortcut? You can find it in integrations>zha>devices>shortcut>manage cluster>cluster: basic>attribute: sw_build_id>press: get zigbee attribute, then press the button a few times.

Just pulled the attributes:

sw_build_id: 2.3.015
hw_version: 1
date_code: 20190715

FWIW, the usual way is to add a condition that checks the elapsed time between updates (last_updated). For example, this confirms at least 1 second has elapsed:

{{ now(). timestamp () - 
   states.binary_sensor.whatever.last_updated.timestamp() > 1 }}

However, that works with a State Trigger but this is an Event Trigger; there’s no direct access to the time of the previous event.

Although I think the multiple zha_events shouldn’t happen in the first place, i’ll add a debounce in the blueprint and combine it with the double click. For now. :+1:

I want to mention again that i don’t have this problem, in fact it looks like I have a sort of debounce in my setup. A second click won’t register within like 300ms after the first click, which just feels slow for a double click. Any way I have no idea where this is coming from. :thinking:

So can you guys press the shortcut a couple of times and tell me the maximum time between first and last event of 1 press. I’ll then add this time plus a small margin to the blueprint.

Also, wich coördinator hardware are you guys using? I use a conbee II USB.

Oke jeremydk`s log shows 550ms between the first and last event, this is way to much to combine with the double press action. therefore i’ll create a different blueprint without the double press and with the debounce. I’ll put the link here when it’s uploaded.

here it is zha-ikea-tradfri-shortcut-button-debounced

1 Like

Awesome, thanks. I’m also using a conbeeII, and the button is only about 8ft away with open line of sight. If it was solely interference, I’d expect to not always have 6 events fired, but it’s repeatable.

I’m using a Nortek HUSBZB-1 and I’m getting multiple events as well. Could it be a button firmware thing? I just bought my button yesterday.

After a few mornings of no devices responding i decided to give zigbee2mqtt a try. It works really good and is easy to setup, no troubles so far. Maybe you guys should give this a try as i see a lot of complaints about zha recently. For further help on the multiple events i advise you to post an isue in zha or zigpy on github.

I now tried the debounced version… and things are REALLY weird and I can’t figure out what is causing all this.

I have used the new blueprint to setup my TrĂĄdfri Shortcut button short press to toggle two devices, my IKEA TrĂĄdfri smartplug and one outlet in my Lidl (Tuya) extension lead.
I also setup long press to turn off both these devices.
Both have lamps connected.

When testing multiple button presses (with 1 second delay) suddenly one of the devices stops reacting on the button press and the two lamps now differ. One is still turned on while the other one is turned off.
Next button press toggles and the one that was turned on is now turned off vice versa.

While there are multiple events sent by the shortcut button it feels like it’s more like the Lidl (Tuya) smart extension lead is more sensitive than the Ikea Trådfri smart plug.

This would only be possible if HA sends out one instruction per event to the smart plugs and that the IKEA one has a built in filter.

It’s an annoying little thing but I guess it is something I have to live with.
Anyone experience the same thing? Is it connected to other smart plugs than the ones from IKEA or does it happen to those too?

Hi, I’m a new user and this is my first post. This is the first blueprint i decided to download and test, and it worked perfectly fine. Until this morning. For some reason i can no longer even make it execute manually in HA. I’ve tried to erase both the button and the automation, and re-added the button i n ZHA and used the blueprint and everything over, but it’s not working. I tried several different actions, and none of them executes. If I check devices in ZHA, the button has no automation added to it, but I guess that’s why we need the blueprint, and it was probably not present before either. Even if I enter the automations and manually execute it, nothing happens. All my other automations work fine. What can have I have done wrong?
Edit: Sorry but when I for the third time reconfigured it it suddenly works. Thanks for a great blueprint!

Edit 2: See the other thread about the button in particular. Seems like the fault in my case was that the battery is drained dead after a few hours only. After changing to a new one it works again, but probably it’s draining this one as well. I thought the problem was with the automation since the execute button didn’t work either but now when I got it working again, it’s just working when physically using the button and not via execute. Nothing is touching the button so I just can’t figure out what’s going on.

I tried but since i moved from Conbee2 to sonoff zbbrige (also tried the sonoff pen), none zha_event shows for ikea button presses like befor :frowning: