Adding Lutron keypad support, unsure about how to model buttons

I’m trying to add support for keypads and switches to the Lutron RadioRA2 component. As someone who is fairly new to Home Assistant, I am a bit uncertain about the most idiomatic way to represent them.

Natively, a keypad is a collection of buttons. The keypad has a name and is in a location (“area” in Lutron terminology). Each of the buttons also has a name. In terms of functionality, a keypad button is a lot like a key on a computer keyboard: it publishes discrete “button pressed” and “button released” events via Lutron’s API. It’s not really a switch in the conventional sense: it doesn’t have “on” and “off” states and also isn’t necessarily a toggle, though it can be configured to act like one. It also has a name of its own, which is often not meaningful outside the context of the keypad, e.g., “On” or “Off” on the “Doorway” keypad in the “Bedroom” area.

First of all, what kind of component(s) should I be exposing? Browsing around the existing components, I don’t immediately see any that have the keydown/keyup semantics of the buttons, such that you could have Home Assistant trigger different behaviors on a long press vs. a short press, say. Hopefully I have just overlooked it and there’s already something like this I can use as a starting point.

Second, what’s the accepted way to model the hierarchy of areas/keypads/buttons, if any? It looks to me like component discovery in Home Assistant doesn’t have a concept of hierarchical structure, preferring to publish every component in a flat namespace and let the user define groupings in the configuration. Is that correct? If so, is the best way to proceed here to expose every button on every keypad as a completely independent entity and then make the user write a bunch of YAML to say which ones should be grouped with which other ones? I would probably combine the names in that case, e.g., give a button a name of “Bedroom / Doorway / On” instead of just “On.”

Thanks!

You’ll want binary sensors for the keypad buttons. They flip to On or True when pressed and flip back to Off or False almost immediately in most cases. That’s enough to trigger automations with an ‘on’ trigger. Since button releases are registered you would also fire the callback for releases as well.

For the button hierarchy, the parsing of the XML in the pylutron library is already arranging them by Area -> Keypad -> Button internally and you just need to grab the names from the objects and combine them into an entity_id. e.g. binary_sensor.<area>_<keypad>_<button engraving>

Motion sensors would also be binary sensors in Home Assistant and there is already a placeholder for it in the pylutron code.

The Lutron component is also missing switches for non-dimmable loads and scenes for all the phantom buttons.

If you implement this and the number of sensors is overwhelming (i.e. 200 sensors), you may also want to look at having an include/exclude list in the configuration. Either whitelist areas (binary_sensor_include: ['Dining Room', 'Living Room']) or perhaps by Integration ID (binary_sensor_exclude: [23,30,31]). It’s always nice to have options when managing Home Assistant.

Thanks! I am indeed using the pylutron library for this and am sending in PRs for the changes I’m needing to make to it.

Were you able to incorporate ra2 keypads into HA? The discovery component in HA added my switches automatically but I do not know how to use the keypad in HA. Thanks for any help. Im running hass.io on a rpi3.

I recently used HA to update my old Lutron Homeworks QS system using the integration here:

After some digging I was able to get the Dimmers working. I’d like to now get the keypads working and successfully added one of my keypads and was able to confirm that HA was listening for events by using Events in Developer Tools. I was able to see the event flow through when I pressed a button on my keypad:
image

Unfortunately, the documentation is sparse so I’m not sure how to use this to make my lights work. I found this thread about creating binary sensors from the data but I’m unsure how do it.

Can anyone provide a bit more details on how to get keypads working? I sincerely appreciate anyone reading this old thread and offering to help!

Hi @koreth & @upsert may I trouble you for some help in taking the homeworks event above and configuring it into a button that i can press in Home Assistant to virtually press the keypad in my Lutron system. I’ve been trying/searching for hours and I just can’t figure it out.