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

Tags: #<Tag:0x00007fc3fc9b7158> #<Tag:0x00007fc3fc9b7068> #<Tag:0x00007fc3fc9b6fa0>

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'
4 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.

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: