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

I had the same need actually, So I have made what we both needed. :slight_smile:
you can find it in the Gist mentioned a few posts earlier.

1 Like

Looks like just the thing I’m after - thanks for your input.
I have the above error coming up. Thoughts?
Cheers.

Reminder for me to do a dry-run on the import.
it is fixed now.

1 Like

Someone on the discord server asked for a version of this that sets the color to white every time it turns it on, so I made a quick tweak for them. I figured I’d share it here too. I don’t actually have one to test, so I’m assuming this will work. If it doesn’t let me know and I’ll take it down in shame lol.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

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
    color:
      name: Turn on Color
      description: What color should it turn on as? (Use a Color Name)
      default: white
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'
      color_name: !input color
      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'
          color_name: !input color
          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'
          color_name: !input color
          data:
            transition: 1
            brightness_step_pct: -10
        - delay: 1
  - conditions:
    - "{{ command == 'stop' }}"
    - "{{ cluster_id == 8 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - service: light.turn_on
      color_name: !input color
      target: !input 'light'

Have not tested it, but the color_name should be in the data:

    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        transition: 1
        color_name: !input color

I made a Blueprint based on this that allows any of the actions of the 4 types of presses (on/off/hold-on/hold-off) to be overridden with custom actions. 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

Hi All!

After adding on of these switches to an automation controlling a Philips Hue light everything works flawlessly. However, when I add a second switch for a different Philips Hue light that second automation does not work, only the first one.

Have anyone of you run into this issue?

Thank you for this blueprint.

I wanted to control a set of lights connected to an Aeotec Z-Wave Nano Dimmer module and observed that On and Off commands work fine. Dimming up and down also work, but as soon as the long press is stopped, the lights return back to their original brightness.

I figured this was due to the “stop” command interfering with persisting the state in the Nano Dimmer module, so I removed this part from the Blueprint YAML file and restarted HA.

This is the section I removed:

Works flawlessly now! :slight_smile:

Thanks again and hope this helps anyone having the same issue.

I just tried to add a second switch today and am having the same issue. Did you ever fix it?

Is there another Blueprint for this button that allow independent assignment of the UP(on) and DOWN(off) buttons as well as exposing all of HA’s actions and not just light-based ones?

Hello poolcactus,

I used your blueprint for a switch of another vendor. For Ikea switch, the blueprint worked fine for me, but with my Paulmann 501.34 switch, I can’t dimm down the lights. It’s always dimming up - independent which button I press. Do you have any idea, why the the dimming down is not working or how I can find the reason by myself?

The commands generated by the Paulmann switch are most likely different than used by the Ikea switch. It would have surprised me if it would have worked.

thanks for this. I have tried, and it seems to not register the Boolean inputs (forced day and night lights), so it is not working.
In the debug, it shows as this variables are false even when I toggle them to true. In addition, when I toggle them, the save button does not appear, as if nothing has changed in the automation.
May it be a HA problem?

I just noticed this exact problem today.

Any info on this?

I have not noticed any differences, but will have to test things to be sure.
The usage of the boolean has not changed, and i’m sure it was working before :slight_smile:

Is there any way to stop dimming all the way to 0% and switching bulbs off eventually?

What would I need to edit to stop the brightness delay when the lights are turned on? Also, the light group turns back on about 3 seconds after I turn it off. This happens with both blueprints.

I have the same problem with the light restore with the Hue Bridge…I guesss it’s because of the dimming/transiton time when power off. becuase when i turn the light off with the original hue and power on with the tradfri it works with the restore. when oi turn them off with the tradfri the light turn on with very low brightness.
is it posssible to deactivate the traniston time ?

@poolcactus hmm something might have changed in home assistant.
When I turn my lights off, around 3 seconds later it turns back on? Only way to keep them off is to turn the light off in home assistant GUI.

I tried testing just now. I click off on my remote, couple seconds after it turns back on.

and here:

Something to do with

mode: restart

maybe?

I think i added this when i made the first version, not sure now why its here… I do think its safe to remove.