ZHA - Philips Hue Dimmer Switch (RWL021) - The fast&easy way

Hi,

Just made my first Blueprint for taking a paired Philips Hue Dimmer Switch (RWL021) into use with pre-defined settings. My target was to create a Blueprint that would make pairing switch and light as easy and fast as possible because I’m planning to move from Deconz to ZHA and I have about 100 lights to control. So it would have been quite huge work without a suitable Blueprint. I also wanted as less parameters as possible for making this fast so to use this Blueprint you only need to set the switch and light/light group.

g945458141-F

The Blueprint has my own settings that you can modify the way you like. With my settings, pressing

  • "On", will turn the light on with full brightness and 3400 Kelvin.
  • "Increase" will turn the light on with 70% brightness and 3400 Kelvin. Holding the button will just increase the current brightness.
  • "Decrease" will turn the light on with 20% brightness and 2300 Kelvin. Holding the button will just decrease the current brightness.
  • "Off" will turn off the light.

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

blueprint:
  domain: automation
  name: Controlling lights using Philips Hue Dimmer Switch (RWL021)
  description: Take the swith fast into use with pre-set configuration.
  input:
    zha_device:
      name: Philips Hue Dimmer Switch (RWL021 only)
      description: The swith to be taken into use.
      selector:
        device:
          integration: zha
          model: RWL021
          multiple: false
    zha_entity_light:
      name: Light or a light group
      description: Light or a light group to be controlled.
      selector:
        entity:
          multiple: true
          integration: zha
          domain: light
  source_url: https://gist.github.com/Rantaki/33c9e74821e08c4419539e7a8e46007c
mode: queued
max_exceeded: silent
variables:
  device_id: !input zha_device
trigger:
- platform: event
  event_type: zha_event
condition: '{{ trigger.event.data.device_id == device_id }}'
action:
  - variables:
      command_type: '{{ trigger.event.data.command }}'
  - service: logbook.log
    data:
      name: Device
      message: '{{ device_id }}'
  - service: logbook.log
    data:
      name: Command
      message: '{{ command_type }}'
  - service: logbook.log
    data:
      name: device_id
      message: '{{ trigger.event.data.device_id }}'
  - choose:
    - conditions: '{{ command_type == "on_press" }}'
      sequence:
      - service: light.turn_on
        data:
          brightness_pct: 100
          transition: 0.3
        target:
          entity_id: !input zha_entity_light
    - conditions: '{{ command_type == "off_press" }}'
      sequence:
      - service: light.turn_off
        target:
          entity_id: !input zha_entity_light
        data:
          transition: 0.3
    - conditions: '{{ command_type == "down_hold" }}'
      sequence:
      - service: light.turn_on
        data:
          brightness_step_pct: -15
          transition: 0.4
        target:
          entity_id: !input zha_entity_light
    - conditions: '{{ command_type == "up_hold" }}'
      sequence:
      - service: light.turn_on
        data:
          brightness_step_pct: 15
          transition: 0.4
        target:
          entity_id: !input zha_entity_light
    - conditions: '{{ command_type == "up_short_release" }}'
      sequence:
      - service: light.turn_on
        data:
          brightness_pct: 70
          transition: 0.3
        target:
          entity_id: !input zha_entity_light
    - conditions: '{{ command_type == "down_short_release" }}'
      sequence:
      - service: light.turn_on
        data:
          brightness_pct: 40
          transition: 0.3
        target:
          entity_id: !input zha_entity_light
  - choose:
    - conditions: '{{ command_type == "on_press" or command_type == "up_short_release" }}'
      sequence:
      - delay: 0.4
      - service: light.turn_on
        data:
          kelvin: 3400
          transition: 0.5
        target:
          entity_id: !input zha_entity_light
    - conditions: '{{ command_type == "down_short_release" }}'
      sequence:
      - delay: 0.4
      - service: light.turn_on
        data:
          kelvin: 2300
          transition: 0.5
        target:
          entity_id: !input zha_entity_light


I hope someone can save time with this!

3 Likes

Hi mate,

Have tried to use your dimmer switch blueprint twice and only the power on button seems to work with RWL021 Dimmer.

Can see in the logs of device that all buttons are firing and reset and re added device. But still nothing.

That is exactly what I saw when I tried some other blueprint implemented for the newer model remote. I suggest to double check that you have the older model for which this bleprint was implemented.

What light bulbs you are trying to control? I am using this for Ikea bulbs.

Edit.
Now I remember better. I have seen similar issue after pairing the remote. And this occured time after time with several remotes. I think I was using deconz at the time. The remote was in wrong state or something and after strugling for hours and pressing the buttons ”a lot”, it somehow got over it without repairing. I wish I remembered better. Have you tried to reboot the remote by pressing all 4 buttons for 10s? Anyway I believe this is not related to the blueprint. Well, could be different FW version, too.

‘’’
Correct remote. V1.
Lights. I tried Group, Hue and Yeelight
‘’’

Hi, thanks for your Blueprint!
It works for me, however I do get this error message in the log:

Template variable warning: 'dict object' has no attribute 'step_mode' when rendering '{{ trigger.event.data.params.step_mode }}'
22:05:59 – (WARNING) helpers/template.py - ...

Any idea how to solve that?

I have use today quite many hours for debugging why the blueprint did not work with my another RWL021. The same switch worked earlier perfectly fine with Deconz but now suddenly there were no more commands like short press and even off button indicated a different command. So the blueprint did not work at all for this switch.

After (too) many hours I understood that it had something to do with the ZHA and at some point I manually enabled quirks which were supposed to be enabled by default.

zha:
  enable_quirks: true
  zigpy_config:
    network:
      channel: 25

After this change I repaired the switch and suddenly the buttons triggered the same commands than the other switches I have in use. I don’t understand how did this happened but it must have something to do with ZHA. So, anyone having problem with this blueprint, go and have a look what commands your switch sends.

Still, I had problems with the Ikea light I was trying to control. After (again too) many hours I noticed that Ikea bulb cannot sufficiently handle a command which has more than 2 attributes. The blueprint tries to send 3 attributes: brightness, warmness (kelvin) and transition time. What I had to do was to do this on two separate commands. It’s not optimal, but better than switching the scene without transition time. After today I understand that not every light/switch work similarly, hence this blueprint may not be suitable for all devices. Some other bulbs may have even more restrictions. On the other hand some bulbs likely work without this two-phased command, but I suspect two-phased command works those too.

Getting too late… I will try to find time to update the blueprint here at some point, if someone is interested.

Hmm… If it still works I would not be concerned about that. I suspect it is because the blueprint initializes certain variables for later use, such as step_mode, no matter what command was received. Every command does not have step_mode parameter, hence the warning. But the logic can handle this just fine.

I have updated the blueprint. The functionality is the same but works now better at least with Ikea Trådfri lights and Gledopto led strip controller.

I’m a new with HA in general (please bear with me) and I have problem with this blueprint. Blueprint says no matching device found (screenshot: NoDevice hosted at ImgBB — ImgBB) even though the switch can found in devices (screenshot Hue-Switch hosted at ImgBB — ImgBB). Anyone know how to fix this?

1 Like

I found myself having the same issue, did you ever solve it @Pate78?