ZHA - IKEA Tradfri On/Off Switch

This is a general use for the IKEA Tradfi On/Off Switch Remote (square with 1/0)
This works for ZHA only!

You can define any actions for Press On, Press Off, Long Press On, and Long Press Off.

Thanks go to wormie_dk for the IKEA five button remote that I based this from.

blueprint:
  name: ZHA - IKEA wireless on/off switch 
  description: Control anything using IKEA wireless on/off switch

  domain: automation
  input:
    remote:
      name: Remote
      description: IKEA wireless on/off switch to use
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: TRADFRI on/off switch
    button_on_short:
      name: On button press
      description: Action to run on press of On button
      default: []
      selector:
        action:
    button_off_short:
      name: Off button press
      description: Action to run on press of Off button
      default: []
      selector:
        action:
    button_on_long:
      name: On button hold
      description: Action to run on long press of On button
      default: []
      selector:
        action:
    button_off_long:
      name: Off button hold
      description: Action to run on long press of Off button
      default: []
      selector:
        action:

mode: restart
max_exceeded: silent

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

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:
          - "{{ command == 'on' }}"
        sequence: !input button_on_short

      - conditions:
          - "{{ command == 'off' }}"
        sequence: !input button_off_short

      - conditions:
          - "{{ command == 'move_with_on_off' }}"
        sequence: !input button_on_long

      - conditions:
          - "{{ command == 'move' }}"
        sequence: !input button_off_long

[Edit: Changed to reflect new Home Assistant version]

12 Likes

Ah, very nice! Clean and concise, I’ll try to learn from this format. Didn’t realize you could put variables at the top of the action like that, that’s game changing! I’ll have to go read more about what you can do in there.

Thanks for the Blueprint.
I have a comment.If I hold the on or off button, then your code runs the brightness change only one.
The correct operation would be that the brightness change runs repeatly until the “stop” zha_event arrives. I don’t know if this is feasible.

The one I made is more for 4 independent general actions rather than dimming. There is another one from another author geared towards dimming lights that would probably do exactly what you want.

1 Like

Thanks @Xelloss99,
Meanwhile I already found it too. (with dimmer)
I will keep yours too, if I will use the remote for something else then your solution will be perfect.
Thanks again.

i am not sure it is your blueprint or home assistant, but when i and my cousin made an automation of this blueprint the automation did not save correcly . it cut of the last of the automation inside automations.yalm. it made all automations offline until we deleted the defect automation.

did anybody experience this?

I’m thinking of buying this remote, but do the remotes report double/triple taps? I’d love to set it where a single tap turns off one lamp then a double tap turns off another

These remotes just report “on” press, “on” hold, “off” press, and “off” hold and don’t (natively) have actions on double or triple taps (though you could probably do an automation that counts taps and does timing to kludge this, there are other blueprints here that you can examine to adapt this one to do this)

With the native functionality, you could still control two devices, one would be turned on/off with pressing the appropriate button, and the other turned on/off by holding the appropriate button (that is what I am doing with mine)
Or you could use a toggle action and control 4 devices with these 4 actions…

Brilliant! very clean blueprint… this will have great use! so big thanks @Xelloss99 for sharing :slight_smile: :smiley:

I made a Blueprint that combines this with the on/off/dimming blueprint referenced in this topic. By default, it will turn a specified light on/off and dim it, but any of the four presses (on/off/hold-on/hold-off) can be overridden and customized. I wanted a light control button that mostly behaved like normal, but could use a long-press to turn the light on to full brightness instead of the last value. It can be found here: ZHA - Ikea Tradfri wireless dimmer with options for custom actions

My experience with this blueprint is that when the light has been off for a while and I turned it back on, it turns on on the lowest brightness. Is there a way to fix that?

The blueprint just calls the service you specify. If it is a light.turn_on service, without further options/service data, that will normally turn the light on at the same brightness it was last left at.

Depending on the integration of your light, if your light dims over time, it may be that the integration read back the light status after it started dimming, but before it turned off so it may have recorded that it was at a low brightness the last time it was “on” (my GE Z-Wave dimmers seem to do this).

If you always want an action in the the blueprint to turn the light on to full (or any specific) brightness, just specify that in the options/service data.

Is there a way to find that in the blueprint? I wasn’t able to find it

You are not using the blueprint in this thread. Check in that blueprint’s discussion thread.
But likely there will need to be a change to the blueprint itself to add the brightness:100 data to the turn on command.

I tried using this and got this error:

alias: ZHA - IKEA wireless on/off switchdescription: ''use_blueprint: pat - Pastebin.com is giving me the error “Error: UndefinedError: ‘dict object’ has no attribute ‘event’”

I’m not sure if it’s related to the ikea outlet not being paired correctly (however I’ve re-paired it already to test). I say this because if I manually toggle the outlet on in the configuration of the device, it works, same when I toggle it off, but then it sets itself to “On” when it physically is still off.

EDIT / UPDATE: I came back to this issue the next day, and everything was working fine. It seems the zigbee network just needed time to settle in after being paired.

1 Like

I imported this blueprint but my switch isn’t showing up in the device list. I have it among my devices (it’s connected to the IKEA gateway). I tried connecting it directly to deCONZ through the Phoscon web app, but that doesn’t seem possible.

I’m new to HA but I figured this little switch would be the easiest in the world to get working :-/

This blueprint is made for ZHA and not deCONZ.
You might wanna check out this blueprint (deConz - IKEA Tradfri on/off switch) instead.

Hi
Has anyone lost the function of long press since the latest HA update. 2022.4.1

With the latest update to Home Assistant, the long press feature no longer works.

How can I make it work again with this blueprint?

Hi
See this link ZHA - IKEA five button remote - #39 by sanghviharshit
This helped me out, I edited the yaml for this blueprint and long press works again.