Sharing an automation to activate lights with IKEA Styrbar remote through ZHA

Hi guys,

I’d like to share an automation for my computer desk lamps and a standing lamp to be controlled via an IKEA Styrbar remote through ZHA. Here I combined many ideas from different topics for my specific need.
While the “building bricks” are taken from different automations and blueprints this automation concentrates more on the hue light color change and has the purpose to share and add room for comments or ideas. :smiling_face:
Big thank you to @epmatt for the blueprint that sparked my idea. Check out his blueprint here: 🎮 ZHA, deCONZ, Zigbee2MQTT - IKEA E2001/E2002 STYRBAR Remote control Universal blueprint - all actions + double click events - control lights, media players and more with Hooks

Setup:
Ikea Styrbar Remote (4 button remote - the square)
3 x Philips hue Play bar named “light.computerlampe1zha”, named “light.computerlampe2zha” and named “light.computerlampe3zha” (will refer only lamp1, 2 & 3)
1 x Philips Centura spot light
1 x light group to combine the Philips lights named (“computerlichter”)
1 x standing lamp (dumb lamp) controlled with on & off through an IKEA smart power plug

Styrbar Remote function:
Pressing up button (short) - Chooses a random hue color for the first (situated left) Philips play bar lamp 1 with full saturation. The next Philips play bar lamp 2 (situated in the center along the Centura spot light) takes the color and adds a value of 60 on the hue color wheel to the already chosen color from lamp1. The same goes for lamp 3 but adding a value of 120 on the color wheel to the initially picked color from lamp 1.
The intention here was to not have 1 color lit up on the computer desk but different colors following each other on the hue color wheel.
Pressing the down button (short) - Switches of the lights on the computer desk
Long press of the previously mentioned buttons dims them.
Left button (short) - Switch on standing lamp behind the computer desk
Right button (short) - Switch off standing lamp behind the computer desk

Automation:

id: 'computertischlampenautomation'
alias: Computertischlampenautomation
initial_state: on
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: 0d79028138c4d79de300fd9d591866d3
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 }}"
- choose:
  - conditions:
      - "{{ command == 'on' }}"
      - "{{ cluster_id == 6 }}"
      - "{{ endpoint_id == 1 }}"
    sequence:
      - variables:
          current_hue: "{{ (range(90)|random + (state_attr('light.computerlampe1zha', 'hs_color')[0] if state_attr('light.computerlampe1zha', 'hs_color') else 0)) % 360 }}"

      - service: light.turn_on
        target:
          entity_id: light.computerlampe1zha
        data:
          hs_color:
            - "{{ current_hue }}"
            - 100
          transition: 1
      - service: light.turn_on
        target:
          entity_id: light.computerlampe2zha
        data:
          hs_color:
            - "{{ (current_hue + 60) % 360 }}"
            - 100
          transition: 1
      - service: light.turn_on
        target:
          entity_id: light.computerlampe3zha
        data:
          hs_color:
            - "{{ (current_hue + 120) % 360 }}"
            - 100
          transition: 1
      - service: light.turn_on
        target:
          entity_id: light.hue_centura_color_spot_1
        data:
          hs_color:
            - "{{ (current_hue + 60) % 360 }}"
            - 100
          transition: 1
  - conditions:
      - "{{ command == 'off' }}"
      - "{{ cluster_id == 6 }}"
      - "{{ endpoint_id == 1 }}"
    sequence:
    - service: light.turn_off
      entity_id: light.computerlichter
      data:
          transition: 1
  - conditions:
      - "{{ command == 'move_with_on_off' }}"
      - "{{ cluster_id == 8 }}"
      - "{{ endpoint_id == 1 }}"
    sequence:
    - repeat:
        while: []
        sequence:
        - service: light.turn_on
          target:
            entity_id: light.computerlichter
          data:
            brightness_step: 10
            transition: 1
        - delay:
            milliseconds: 250
  - conditions:
      - "{{ command == 'move' }}"
      - "{{ cluster_id == 8 }}"
      - "{{ endpoint_id == 1 }}"
    sequence:
    - repeat:
        while: []
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.computerlichter
            data:
              brightness_step: -10
              transition: 1
          - delay:
              milliseconds: 250
  - conditions:
      - "{{ command == 'press' }}"
      - "{{ cluster_id == 5 }}"
      - "{{ endpoint_id == 1 }}"
      - "{{ args == [257, 13, 0] }}"
    sequence:
    - service: switch.turn_on
      target:
        entity_id: switch.stehlampezha
  - conditions:
      - "{{ command == 'press' }}"
      - "{{ cluster_id == 5 }}"
      - "{{ endpoint_id == 1 }}"
      - "{{ args == [256, 13, 0] }}"
    sequence:
    - service: switch.turn_off
      target:
        entity_id: switch.stehlampezha

  default: []

I’m curious if you’d have some improvement suggestions or other ideas. :slight_smile:

1 Like