Zigbee2mqtt - Tradfri on/off switch

This is based on https://community.home-assistant.io/t/zigbee2mqtt-ikea-five-button-remote/255308/8

it’s the code to control your lights with the on/off switch, it has 2 function.
short press and long press.

blueprint:
  name: zigbee2mqtt - Tradfri on/of button
  description: 'Control on off switch from IKEA Tradfri.

  The button has 2 functions

  - short press

  - long press

  This blue print is 

  Inspired by the blueprint of @starbuck93 (https://community.home-assistant.io/t/zigbee2mqtt-ikea-five-button-remote/255308)
  
  Choce only sensor type action.
  

      '
  domain: automation
  input:
    switch:
      name: switch
      description: Tradfri on/off switch
      selector:
        entity:
          domain: sensor
    light_1:
      name: Short press action
      description: The light(s) to control
      selector:
        target:
          entity:
            domain: light
    light_2:
      name: Long press action
      description: The light(s) to control
      selector:
        target:
          entity:
            domain: light
mode: restart
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input 'switch'
  attribute: action
action:
- variables:
    command: '{{ trigger.to_state.state }}'
- choose:
  - conditions:
    - '{{ command == ''off'' }}'
    sequence:
    - service: light.turn_off
      target: !input 'light_1'
      data: {}
  - conditions:
    - '{{ command == ''on'' }}'
    sequence:
    - service: light.turn_on
      data: {}
      target: !input 'light_1'
  - conditions:
    - '{{ command == ''brightness_move_down'' }}'
    sequence:
    - service: light.turn_off
      data: {}
      target: !input 'light_2'
  - conditions:
    - '{{ command == ''brightness_move_up'' }}'
    sequence:
    - service: light.turn_on
      data: {}
      target: !input 'light_2'

Works great to dim a bunch of lights without using Z2M binding. Too bad it only does on/off and not brightness level though.

This is because i only use the on/off function.
maybee you could rewrite it yourself for dimming, there are so examples on how to do this.

I have a question that I can’t answer because I don’t own an IKEA Switch (or use ZigBee2MQTT).

The State Trigger monitors the sensor’s action attribute.

platform: state
  entity_id: !input 'switch'
  attribute: action  <--- This

However, the variable refers to the sensor’s state and not its action attribute.

command: '{{ trigger.to_state.state }}'
                                ^
                                |

Is it because the sensor’s state has the same value as its action attribute? If it does, why does the Stage Trigger monitor the action attribute instead of the state?

i realy don’t know why i did that. i’m a hobby programmer that rebuild a already made product.
i will look into it.