ZHA - Ikea Tradfri wireless dimmer with options for custom actions

Tags: #<Tag:0x00007fc41cf05860> #<Tag:0x00007fc41cf05630> #<Tag:0x00007fc41cf054a0>

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:


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.