You are exactly right! Admittedly this code is more advanced than most users will need. I like to try to challenge my programming abilities from time to time, so I created a script that could handle my various remotes.
Using the following guide, you can create your own automation to handle unique button presses.
- Go to Developer Tools > Events.
- Under Listen to events type
zha_event
.
- Click Start listening.
- Press a button on your MOES Switch.
The event created by pressing the center button once on my IKEA 5 button remote:
{
"event_type": "zha_event",
"data": {
"device_ieee": "ec:1b:bd:ff:fe:23:9c:ee",
"unique_id": "ec:1b:bd:ff:fe:23:9c:ee:1:0x0006",
"device_id": "fc6086430b1711eba700f15cccf019c9",
"endpoint_id": 1,
"cluster_id": 6,
"command": "toggle",
"args": []
},
.
.
.
}
There you can gather the information which is unique to your button presses for each device. For this button I see the "device_ieee"
is the unique identifier for this remote. The unique "command"
identifying which button was pressed is "toggle"
.
Pressing the Top button outputs this event:
{
"event_type": "zha_event",
"data": {
"device_ieee": "ec:1b:bd:ff:fe:23:9c:ee",
"unique_id": "ec:1b:bd:ff:fe:23:9c:ee:1:0x0008",
"device_id": "fc6086430b1711eba700f15cccf019c9",
"endpoint_id": 1,
"cluster_id": 8,
"command": "step_with_on_off",
"args": [
0,
43,
5
]
},
.
.
.
}
By looking for the differences between all of the events I was able to determine most of this remote’s button presses can be distinguished by simply using the "command"
values. However, in this case the right and left buttons are identified with the same "press"
command. Looking for further differences I noticed the first "args"
value was 256
for the right button, and 257
for the left button.
Every button’s "data"
will be a bit different. As long as you can identify a consistent value difference between each button press, you can create code to handle each unique press.
P.S. My code is intended to allow Home Assistant to count multiple rapid button presses in remotes which immediately report single clicks. Some remotes handle multi-clicks internally, which makes this code unnecessary. So try double and triple clicking your buttons to see if it’s event reports how many times the button was clicked. If your remote handles multiple button clicks internally, then the extra complexity of this script is unnecessary for you.