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)
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.