deCONZ - IKEA Trådfri on/off switch (incl dimmer)

dd3e937bf5a20d74f84f1c9ba227eac73332d97f

deCONZ lights blueprint for the IKEA Trådfri on/off switch, including dimming functionality (button hold). Based on poolcactus ZHA blueprint for this switch.

Get started

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: deCONZ - IKEA Tradfri on/off switch
  description: |
    "Control your deCONZ 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: deconz
          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: deconz_event
  event_data:
    device_id: !input 'remote'

action:
- variables:
    event: "{{ trigger.event.data.event }}"

- choose:
  - conditions:
    - "{{ event == 1002 }}"
    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        transition: 1
  - conditions:
    - "{{ event == 2002 }}"
    sequence:
    - service: light.turn_off
      target: !input 'light'
      data:
        transition: 1
  - conditions:
    - "{{ event == 1001 }}"
    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:
    - "{{ event == 2001 }}"
    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:
    - "{{ event == 1003 }}"
    sequence:
    - service: light.turn_on
      target: !input 'light'
  - conditions:
    - "{{ event == 2003 }}"
    sequence:
    - service: light.turn_on
      target: !input 'light'
6 Likes

This looks useful, I tried adding it though and when it runs I get this error

Logger: homeassistant.components.automation.deconz_ikea_tradfri_on_off_switch_2
Source: helpers/script.py:1138
Integration: Automation ([documentation](https://www.home-assistant.io/integrations/automation), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
First occurred: 9:32:18 AM (1 occurrences)
Last logged: 9:32:18 AM

deCONZ - IKEA Tradfri on/off switch: Error executing script. Error rendering template for variables at pos 1: UndefinedError: 'trigger' is undefined

Are you getting the error when importing the blueprint? It looks like something is wrong with the trigger, do you have any IKEA switches in your deCONZ?

Importing the blueprint is fine, creating the automation works as well.

Device is exposed to HA through Deconz

And how does the automation look like in yaml?

Looks truncated, but not overly familiar with how it should look with a blueprint automation, I haven’t gone into it in detail yet.

alias: deCONZ - IKEA Tradfri on/off switch Test
description: ''
use_blueprint:
  path: psychozz/deconz-ikea-tradfri-on-off-switch-incl-dimmer.yaml
  input:
    remote: 8576a0291aa648be947269dddb6f067b
    light:
      entity_id: light.spare_bedroom_lamp

Just noticed in my automation, based on this blueprint, that I’ve chosen the device instead of the entity. Does your bulb show up as a device? Otherwise it looks correct!

Still the same error when I change to the entity rather than the light…

alias: deCONZ - IKEA Tradfri on/off switch Test
description: ''
use_blueprint:
  path: psychozz/deconz-ikea-tradfri-on-off-switch-incl-dimmer.yaml
  input:
    remote: 8576a0291aa648be947269dddb6f067b
    light:
      device_id: 797a3982fe740033c67732381678b254

The only difference is that I imported the blueprint from my github, if you try to import from there instead and base your automation on that. Should be exactly the same as above, but you can try at least :slight_smile:
homeassistant/blueprint-deconz-ikea-onoff-switch.yaml at main · marcuswahlstam/homeassistant (github.com)

I have a question: Short pressing “0” on the IKEA Tradfri On/Off turns it off, but: Short pressing “1” does not recover the lights as they last were (100% brightness), but at 1%.
How can I set this blueprint so that when I short-press “1” it turns on with 100% brightness?

If you find the answer to this, please post the solution here?

Hi @mortenmoss, well, I found a “solution”, I’m using a different blueprint, this one: deConz - IKEA Tradfri on/off switch

Kind regards.

You can edit the blueprint yaml in blueprints/automation/psychozz/deconz-ikea-tradfri-on-off-switch-incl-dimmer.yaml
Changes you should make are:

  • remove data: transition lines from 1002 and 2002 events (that’s what’s causing to not turn on at last intensity)
  • 2003 should call the light.turn_off service, not turn_on
  • optionally use a higher value for brightness_step_pct as that’s rather slow

Restart home assistant and you’re all set.

1 Like

Can you please add a setting to change speed of dimming? It is very slow now.

This seems to work pretty well - thanks. Only caveat is the one vbaros also mentioned - it’s a bit slow with its dimming… I’ll have to tinker with it to see if I can change that… assuming you don’t have a fix coming anytime soon :wink:

This is working great, thanks! one question though. I’m controlling multiple lights with the switch. Sometimes not all the lights are on but I want to dim the lights that are on. When I try this the other lamps that are off at that time will go on as well.

Do you know a way to only dim the active lamps linked to the switch?

You will need to check the states of each bulb before doing the actions.
Definitely possible but not something I can do in yaml.

1 Like

I seem to have an issue - not 100% sure if related to the blueprint.

When controlling Hue lights, when turning them on, they always turn on at a very dim setting. However, the Hue app believes they are set at the previous (high setting)

I want them to come on at the previous brightness.

Any ideas?

Hi, I am pretty new to HA. I managed to get the Switch to work and also changed the lines suggested by @blahlex .

Currently i have two more goals i want to achieve.

  • Only dim lights that are currently on. Like mentioned above. Does anybody have an Idea how this can
    be done?List item

  • Trigger different scenes. Cycle through a few different scenes while pushing the “ON”-Button again.

Maybe somebody can point me in the right direction. :slight_smile:

blueprint:
  name: deCONZ - IKEA Tradfri on/off switch
  description:
    '"Control your deCONZ light(s) with IKEA Tradfri on/off switch/dimmer


    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: deconz
          manufacturer: IKEA of Sweden
          model: TRADFRI on/off switch
          multiple: false
    light:
      name: Light
      description: The lights that will be controlled
      selector:
        target:
          entity:
            domain: light
  source_url: https://community.home-assistant.io/t/deconz-ikea-tradfri-on-off-switch-incl-dimmer/260772
mode: restart
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      device_id: !input "remote"
action:
  - variables:
      event: "{{ trigger.event.data.event }}"
  - choose:
      - conditions:
          - "{{ event == 1002 }}"
        sequence:
          - service: light.turn_on
            target: !input "light"

      - conditions:
          - "{{ event == 2002 }}"
        sequence:
          - service: light.turn_off
            target: !input "light"
      - conditions:
          - "{{ event == 1001 }}"
        sequence:
          repeat:
            while:
              - condition: template
                value_template: "{{ repeat.index < 10 }}"
            sequence:
              - service: light.turn_on
                target: !input "light"
                data:
                  transition: 1
                  brightness_step_pct: 15
              - delay: 1
      - conditions:
          - "{{ event == 2001 }}"
        sequence:
          repeat:
            while:
              - condition: template
                value_template: "{{ repeat.index < 10 }}"
            sequence:
              - service: light.turn_on
                target: !input "light"
                data:
                  transition: 1
                  brightness_step_pct: -15
              - delay: 1
      - conditions:
          - "{{ event == 1003 }}"
        sequence:
          - service: light.turn_on
            target: !input "light"
      - conditions:
          - "{{ event == 2003 }}"
        sequence:
          - service: light.turn_on
            target: !input "light"
1 Like