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
- 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:
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
Pressing the Top button outputs this event:
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.
"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.