I’m working with my brother (in a different state so unfortunately makes testing a bit challenging) with this very same dimmer, trying to replicate the behavior provided by the Hue bridge but using HA/ZHA instead. I’ve found that the RWL021 generates the following zha_event
entities that you can catch:
on
-
off_with_effect
(I have yet to see a plain off
event)
-
step
with an arg list where arg[0]
is either 0 (increase) or 1 (decrease) and arg[1]
is the intended step size, usually 30 but not always?
-
stop
when a held button is released (only tested this with step
events so far)
Here is an example of what the event watcher captures (I’ve removed unnecessary data and duplicate events):
Event 21 fired 8:53 PM:
{
"event_type": "zha_event",
"data": {
"unique_id": "0xb03b:1:0x0008",
"command": "stop",
"args": []
}
}
Event 20 fired 8:53 PM:
{
"event_type": "zha_event",
"data": {
"unique_id": "0xb03b:1:0x0008",
"command": "step",
"args": [
0,
56,
9
]
}
}
Event 12 fired 8:53 PM:
{
"event_type": "zha_event",
"data": {
"unique_id": "0xb03b:1:0x0006",
"command": "off_with_effect",
"args": [
0,
0
]
}
}
Event 0 fired 8:48 PM:
{
"event_type": "zha_event",
"data": {
"unique_id": "0xb03b:1:0x0006",
"command": "on",
"args": []
}
}
I’ve been able to create automations that work with most of this data so far, though I’m still struggling a bit with the brightness control. Here’s what I have (note, there’s also a counter
entity tied in here meant to track repeated presses of the ON
button to potentially trigger different actions, something the Hue bridge also does):
- id: office_light_remote_on_handler
alias: Office Light Remote On Handler
trigger:
- platform: event
event_type: zha_event
event_data:
unique_id: "0xb03b:1:0x0006"
command: "on"
action:
- service: counter.increment
entity_id: counter.office_light_remote_counter
- service: light.turn_on
entity_id:
- light.office_desk_lamp
- light.office_bloom_right
- light.office_bloom_left
- light.office_hue_go
- id: office_light_remote_brightness_handler
alias: Office Light Remote Brightness Handler
trigger:
- platform: event
event_type: zha_event
event_data:
unique_id: "0xb03b:1:0x0006"
command: "step"
action:
- service: light.turn_on
entity_id:
- light.office_desk_lamp
- light.office_bloom_right
- light.office_bloom_left
- light.office_hue_go
data_template:
brightness: >
{% if state_attr("binary_sensor.office_light_remote", "level") > 30 %}
{{ state_attr("binary_sensor.office_light_remote", "level") }}
{% else %}
30
{% endif %}
- id: office_light_remote_off_handler
alias: Office Light Remote Off Handler
trigger:
- platform: event
event_type: zha_event
event_data:
unique_id: "0xb03b:1:0x0006"
command: "off_with_effect"
action:
- service: counter.reset
entity_id: counter.office_light_remote_counter
- service: light.turn_off
entity_id:
- light.office_desk_lamp
- light.office_bloom_right
- light.office_bloom_left
- light.office_hue_go
One challenge to overcome is that the real Hue system doesn’t turn off the lights if you dim them all the way down, whereas Home Assistant does–at least if you rely on the binary_switch
implementation and state changes currently triggered by ZHA with this device. I suspect that’s not ZHA’s fault, but rather just the way HA reacts if you have a level-enabled binary sensor and you set the level to 0. To solve this, the automations above rely on zha_event
triggers for everything instead of state changes, and brightness is limited to never go below 30 (out of 255). The lights are only turned off if the off
command comes, not if the binary sensor state changes to off
as reported by HA. (As noted above, brightness is currently not quite working as expected…I think there’s something wrong with my trigger or the data template.)
It would be preferable for this device (and maybe others) to split brightness and power states more cleanly, since it’s technically just a remote and not necessarily tied directly to lights. I’m not sure if it’s possible to do this cleanly and easily without modifying some well-established HA behaviors concerning binary sensors (obviously a bad idea) or if there’s maybe a different entity type that this device could be mapped to, or what. Maybe it’s doable with some minor zhaquirks
additions. I haven’t dug that far.