I can definitely see the draw of using sensors for buttons. I was also initially confused about how they worked (particularly from a coding perspective) in HA. Stateful devices, like sensors, are more approachable and visible than event emitters in Home Assistant. The internal APIs around them are easier to work with, too.
However…buttons aren’t actually stateful devices, so I can see why Home Assistant treats them as event emitters. When you push a button, you haven’t changed the state of the button controller, you’ve just caused a “pushed” event. Hubitat does treat button devices as stateful, which doesn’t really make a lot of sense. If you look at the state of a button device in Hubitat, it will have a ‘pushed’ property set to the number of the last pushed button. What’s that telling you, though? The button isn’t currently pushed (even in Hubitat, the state change happens after a button event). It was pushed at some point in the past, but that’s not terribly useful to know.
You can make a sensor to expose button presses in Hubitat or Home Assistant easily enough, but, as @code-in-progress mentioned, it’s going to be pretty limited. You’d have to make a separate sensor for each button, and for each type of operation (push, hold, double-tap), which could get out of hand pretty quickly. Plus, the sensors should reset themselves after some arbitrarily short amount of time, so they’d need a bit of logic attached (I’ve used virtual momentary switches for that sort of thing in Hubitat in the past).
Home Assistant actually makes using device events pretty easy through the UI. You create an automation, choose Device as the trigger type, pick your device, and pick the trigger. It’s not much different from triggering on a sensor value change.
As far as using events in external apps like Node-RED or AppDaemon, there’s only one event type to listen to from the Hubitat integration – hubitat_event
, which will look like
{
"event_type": "hubitat_event",
"data": {
"device_id": "180",
"attribute": "pushed",
"value": "1"
},
...
}
All of that said, I’m not opposed to adding an option to generate binary sensors for all the button events, but it might be more worthwhile (and less messy) to make a visualizer card for Lovelace that would show button presses.