ZHA - IKEA Tradfri on/off switch (incl dimmer)

Blueprint for the Ikea tradfri 2 on / off switch, including dimming functionality
button

Blueprint

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.

Or import this Blueprint by using the forum topic URL:

blueprint:
  name: ZHA - IKEA Tradfri on/off switch
  description: |
    "Control your light(s) with IKEA Tradfri on/off switch
    
    Select the Tradfri remote and your lights.
    You can turn the lights On / Off, or hold the buttons to dim the lights"
  domain: automation
  input:
    remote:
      name: Remote
      description: The remote that will control the lights
      selector:
        device:
          integration: zha
          manufacturer: 'IKEA of Sweden'
          model: 'TRADFRI on/off switch'
    light:
      name: Light
      description: The lights that will be controlled
      selector:
        target:
          entity:
            domain: light
mode: restart
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 }}"
- choose:
  - conditions:
    - "{{ command == 'on' }}"
    - "{{ cluster_id == 6 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        transition: 1
  - conditions:
    - "{{ command == 'off' }}"
    - "{{ cluster_id == 6 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - service: light.turn_off
      target: !input 'light'
      data:
        transition: 1
  - conditions:
    - "{{ command == 'move_with_on_off' }}"
    - "{{ cluster_id == 8 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
      repeat:
        while:
        - condition: template
          value_template: "{{ repeat.index < 10 }}"
        sequence:
        - service: light.turn_on
          target: !input 'light'
          data:
            transition: 1
            brightness_step_pct: 10
        - delay: 1
  - conditions:
    - "{{ command == 'move' }}"
    - "{{ cluster_id == 8 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
      repeat:
        while:
        - condition: template
          value_template: "{{ repeat.index < 10 }}"
        sequence:
        - service: light.turn_on
          target: !input 'light'
          data:
            transition: 1
            brightness_step_pct: -10
        - delay: 1
  - conditions:
    - "{{ command == 'stop' }}"
    - "{{ cluster_id == 8 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - service: light.turn_on
      target: !input 'light'
5 Likes

thanks for the blueprint. I have added 4 identical lamps. When I turn it off it works fine, but when I turn it on again, the bulbs start in different brightnes, and very faintly.

The automation calls light.turn_on with a transition of 1second for the lights, when pressing the “on” button. Normally lights will restore their old brightness from before they turned off.

My Phillips Hue bulbs turn on at the lowest brigthnes. My zigbee dimmer modules turn on at the same brightnes as when I turned it off.
If I hold 1 inside for 1 second after I turn on, then everyone is set to max brightnes

EDIT:
I found out it’s hue bridge it does not work with. works fine if I put the bulb on another bridge

Hey @poolcactus, thanks! I’ve been using this blueprint with a group of lights for a couple of days, and it’s working great. I just tried adding a second ikea switch, but it doesn’t seem to work with it. I can see the zha events coming through, so the switch is paired correctly. My original automation from this blueprint works fine, still. Is it possible there’s some sort of “conflict” so this works only with one switch at a time? I made sure the name was different, but still doesn’t seem to work…

The trigger is based on the entity id, which you select as the remote. I have multiple remotes setup and working

1 Like

Ok, thanks for the info, I’ll keep exploring as to why I can’t get multiple remotes working.

Worked well for me, thanks for sharing!

One thing that I found though was that one of my livarno lux bulbs didn’t like light.turn_off with a transition, and basically stayed on on the lowest brightness. I configured two such bulbs (identical) and only one of them didn’t turn off :man_shrugging:. In the end, I modified the blueprint to not have a transition on the turn_off/turn_on calls and it works well. :+1:

Great work with the IKEA on/off button!

I’m trying to use this with Zigbee2mqtt and almost everything is working. The one thing that doesn’t work is the repeating dimming function - it dim the lights 5% up/down, but only once.
(I also added an input to determine how much to inc/ dec each time, but could not find a way to decrease => get the negative value)

I’ve been using this for a while now, and it’s great.

One thing I’d like to be able to do is make it dim faster - can you make that into a variable? (I think I know how to do it, but I’d rather not fork your blueprint)

You could alter the code in your installation to increase the dimmer step. (now +/-10%).
I’ll have a look at your request later on.

FWIW, I changed it to a smaller step (5%), and a shorter time (0.25). Having both of these bits be configurable would be ideal.

So does this work only with zha integration or it does work with deconz as well?

I have only tested this for ZHA.

I found some time to make this for you:

I am seeing error when trying to import this… is it a bug in HA?

What are the different between the hue bridges?

I am seeing that on but dimmed issue, and trying to see how best to fix it.

My bridge is on latest firmware…

Copy/Paste mistake…it is fixed

confirmed it is fixed. Thanks.

This is great, thanks.
Would it be possible to add a default turn on value?
Or, even better yet a default turn on value based on time - so hitting the on button will make the light go to 100% (holding will dim up from zero) but between 21:00:00 and 05:00:00 the light will default to 40%

I’ve seen some other blueprints with a setting for default on value but I haven’t seen any which include an editable time value.

Cheers, thanks again for your efforts in the community.