Zigbee2mqtt - Ikea on/off button with dimmer V2

blueprint:
  name: zigbee2mqtt - Ikea on/off button with dimmer V2
  description: Control on off switch from IKEA Tradfri.
  domain: automation
  #source_url: https://community.home-assistant.io/t/zigbee2mqtt-ikea-on-off-switch-with-dimming/261280
  input:
    switch:
      name: switch
      description: Ikea on/off switch
      selector:
        entity:
          domain: sensor
    light:
      name: Light
      description: The light to control
      selector:
        target:
          entity:
            domain: light
mode: restart
max_exceeded: silent
trigger:
  - platform: state
    entity_id: !input "switch"
    attribute: action
condition:
  - condition: template
    value_template: '{{ trigger.to_state.attributes.action in ("on","off","brightness_move_down","brightness_move_up","brightness_stop") }}'
action:
  - variables:
      command: "{{ trigger.to_state.state }}"

  - choose:
      - conditions:
          - "{{ command == 'off' }}"

        sequence:
          # - variables:
          #     lstatus: "{{ states('light.paere_kontor_nord') }}"
          # - choose:
          #     - conditions:
          #         - "{{ lstatus == 'off' }}"
          #         #- condition: state
          #         #  entity_id: light.paere_kontor_nord
          #         #  state: "off"
          #       sequence:
          #         - service: light.turn_on
          #           data: {}
          #           target: !input "light"
          #     - conditions:
          #         - condition: state
          #           entity_id: light.paere_kontor_nord
          #           state: "on"
          #       sequence:
          #         - service: light.turn_off
          #           data: {}
          #           target: !input "light"

          - service: light.turn_off
            target: !input "light"
            data: {}

      - conditions:
          - "{{ command == 'on' }}"
        sequence:
          - service: light.turn_on
            data: {}
            target: !input "light"

      - conditions:
          - "{{ command == 'brightness_move_down' }}"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: !input "switch"
                  state: brightness_stop
                  attribute: action
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step_pct: -15
                    transition: 0
                  target: !input "light"
                - delay: "0.5"
      - conditions:
          - "{{ command == 'brightness_move_up' }}"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: !input "switch"
                  state: brightness_stop
                  attribute: action
              sequence:
                - service: light.turn_on
                  data:
                    brightness_step_pct: 15
                    transition: 0
                  target: !input "light"
                - delay: "0.5"
1 Like