ZHA - Ikea Tradfri wireless dimmer with options for custom actions

This blueprint controls lights or anything else using an Ikea Tradfri wireless switch. Select a switch and a light, and by default it will create an automation to turn the light on and off, or dim it up and down. However, for each type of press (on, off, hold-on, hold-off), the default action can be overridden with custom actions. In fact, there’s no need to even specify a light!

Requirements:

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

blueprint:
  name: ZHA - IKEA Tradfri dimmer switch
  description: |
    Control lights or anything else using IKEA Tradfri dimmer switch.

    You can specify individual actions for On/Off/Hold On/Hold Off,
    or configure long presses to dim lights.
  domain: automation
  input:
    remote1:
      name: On/Off Switch
      description: IKEA on/off switch to use
      default:
      selector:
        device:
          integration: zha
          manufacturer: 'IKEA of Sweden'
          model: 'TRADFRI on/off switch'
    lights:
      name: Lights
      description: Lights to control when using default light actions
      default:
        entity_id: none
      selector:
        target:
          entity:
            domain: light
    on_short_custom:
      name: Use custom action for short on-button press
      description: 'Specify custom actions to run using a short press of the on button.

        If not specified, the controlled light will be turned on.'
      default: false
      selector:
        boolean: {}
    button_on_short:
      name: On button press
      description: Action to run on press of On button
      default: []
      selector:
        action:
    off_short_custom:
      name: Use custom action for short off-button press
      description: 'Specify custom actions to run using a short press of the off button.

        If not specified, the controlled light will be turned off.'
      default: false
      selector:
        boolean: {}
    button_off_short:
      name: Off button press
      description: Action to run on press of Off button
      default: []
      selector:
        action:
    on_long_custom:
      name: Use custom action for long on-button hold
      description: 'Specify custom actions to run using a long press of the on button.

        If not specified, the controlled light will be increased in brightness.'
      default: false
      selector:
        boolean: {}
    button_on_long:
      name: On button hold
      description: Action to run on long press of On button
      default: []
      selector:
        action:
    off_long_custom:
      name: Use custom action for long off-button hold
      description: 'Specify custom actions to run using a long press of the off button.

        If not specified, the controlled light will be decreased in brightness.'
      default: false
      selector:
        boolean: {}
    button_off_long:
      name: Off button hold
      description: Action to run on long press of Off button
      default: []
      selector:
        action:

trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input remote1
mode: restart

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 }}"
    on_short_custom: !input 'on_short_custom'
    off_short_custom: !input 'off_short_custom'
    on_long_custom: !input 'on_long_custom'
    off_long_custom: !input 'off_long_custom'
    lights: !input 'lights'
- choose:
  - conditions:
    - "{{ command == 'on' }}"
    - "{{ cluster_id == 6 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - choose:
      - conditions: '{{ on_short_custom }}'
        sequence: !input 'button_on_short'
      - conditions: '{{ not on_short_custom }}'
        sequence:
        - service: light.turn_on
          target: !input 'lights'
          data:
            transition: 1
  - conditions:
    - "{{ command == 'off' }}"
    - "{{ cluster_id == 6 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - choose:
      - conditions: '{{ off_short_custom }}'
        sequence: !input 'button_off_short'
      - conditions: '{{ not off_short_custom }}'
        sequence:
        - service: light.turn_off
          target: !input 'lights'
          data:
            transition: 1
  - conditions:
    - "{{ command == 'move_with_on_off' }}"
    - "{{ cluster_id == 8 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - choose:
      - conditions: '{{ on_long_custom }}'
        sequence: !input 'button_on_long'
      - conditions: '{{ not on_long_custom }}'
        sequence:
          repeat:
            while:
            - condition: template
              value_template: "{{ repeat.index < 10 }}"
            sequence:
            - service: light.turn_on
              target: !input 'lights'
              data:
                transition: 1
                brightness_step_pct: 10
            - delay: 1
  - conditions:
    - "{{ command == 'move' }}"
    - "{{ cluster_id == 8 }}"
    - "{{ endpoint_id == 1 }}"
    sequence:
    - choose:
      - conditions: '{{ off_long_custom }}'
        sequence: !input 'button_off_long'
      - conditions: '{{ not off_long_custom }}'
        sequence:
          repeat:
            while:
            - condition: template
              value_template: "{{ repeat.index < 10 }}"
            sequence:
            - service: light.turn_on
              target: !input 'lights'
              data:
                transition: 1
                brightness_step_pct: -10
            - delay: 1

Example use case: Control a light mostly through default actions, but use a long-press to turn the light on to full brightness instead of the last brightness:

Based on these Blueprints:

3 Likes

Has anyone seen this error when running the automation? Error: UndefinedError: ‘dict object’ has no attribute ‘event’

I can’t seem to get it working at all.

Hmm, that’s strange. Did you select an on/off switch device?

Hi,

When trying to use this blueprint, with just a “basic” setup I get the following outout on the trace:

“Stopped because an error was encountered at January 13, 2022, 7:01:21 AM (runtime: 0.01 seconds)
Template rendered invalid entity IDs: [‘none’, ‘light.philips_lct003_5e1b9404_level_light_color_on_off’]”

I’m using ZHA, and have just entered the basics:
“ZHA - IKEA tradfri dimmer switch” in the “Blueprint to use” dropdown.
Then my switch in the switch-select.
And for testing I’ve tried with both the light as a device and as an antity.
If I use it as an entity I get the message above.
If I use it as a device I get the message: “Template rendered invalid entity IDs: [‘none’]”

Any idea what could be wrong?

I encountered the same error, it happens if you have “none” in the list of entities.
Removing it solves the issue.

1 Like

Thanks,
That solved it for me :slight_smile:
(Took me a while to notice/understand that the “none” that defaulted into the list was a problem.

1 Like

Hi,

Same problem here, had to remove the Entity “None” line from the configuration.
Thanks for the tip!

Thanks,
AseKarlsson

Hi,
I’m new to Home Assistant and I have the same error.
Can anybody explain in detail (e.g. with a screenshot) where that “None” is, which should be removed?

Hi Martin,
Open automations.yaml file in the config folder with an editor and find your button automation.
There remove the line entity_id: none

//AseKarlsson

Hi, great blueprint, works without problem. However, is there a way to make to dimming increase/decrease go faster? Not that I’m so inpatient but holding it longer drains the battery faster I assume. Is there a way I can change the blue print myself with a little bit different timing setting?

I also noticed, that pushing on button often switches on the light in some meium brighness instead of going back to brightness level it had when switched off. Anyone know why?

1 Like

I’ve been using this blueprint for quite a few months and it’s worked perfectly - thanks!

However in the last few days the long-press functionality has stopped working. That is, if you short-press the IKEA button 1 or 0 then those actions run fine, but if you long press either then nothing happens.

I’ve looked at the diagnostics (and quickly got out of my depth). It seems that the long-press of the button 1 or 0 triggers the automation, but none of the actions are called.

I’m using IKEA switches with the ConBee II Zigbee integration, not the Tradfri gateway.

Can anyone help me work out what might be going wrong, please?

This is probably because of the breaking change in 2022.04 that was not mentioned in the release notes.

Thanks. At risk of sounding like a total noob, where do I read about breaking changes, if not in the release notes?

I guess you could read the code for changes. But that is obviously not a feasible solution.

I think the issue is that somewhere someone made a mistake.

Ahh, Im having the same issue (using a different blueprint) Did you get anywhere with it?

Same issue here? Do you have any updates? Thanks :slight_smile: