ZHA - IKEA Tradfri On/Off Switch

Tags: #<Tag:0x00007fc410b14960> #<Tag:0x00007fc410b14758> #<Tag:0x00007fc410b142a8>

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' }}"
          - "{{ cluster_id == 6 }}"
          - "{{ endpoint_id == 1 }}"
        sequence: !input button_on_short

      - conditions:
          - "{{ command == 'off' }}"
          - "{{ cluster_id == 6 }}"
          - "{{ endpoint_id == 1 }}"
        sequence: !input button_off_short

      - conditions:
          - "{{ command == 'move_with_on_off' }}"
          - "{{ cluster_id == 8 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ args == [0, 83] }}"
        sequence: !input button_on_long

      - conditions:
          - "{{ command == 'move' }}"
          - "{{ cluster_id == 8 }}"
          - "{{ endpoint_id == 1 }}"
          - "{{ args == [1, 83] }}"
        sequence: !input button_off_long
6 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.