How to have my ESPHome device directly communicate state information to and from other devices within/via HA?

I’ve discovered ‘homeassistant.service’ as an action, but have only found examples that work with lights. ‘homeassistant.action’ looks promising, but I’ve found no documentation or examples for general device control. The ‘api’ section looks promising for receiving data from HA, but again I found no examples of how this could be used within the device to track other device state changes.

My motivation:
I have my 4x4 NeoTrellis keypad working, but it’s just an array of lighted buttons with no specific control logic behind them. I’ve connected a lot of functionality within HA through automations, responding to the keypad’s buttons to control other devices and responding to those devices changes in state to update the keypad’s lights. Works well enough, but it can result in dozens of automations, a lot to keep track of. It would be helpful to encapsulate all this in one place for editing. I’d like to think of this keypad device, and its YAML, more like a dashboard, where an editor collects all this in one location and lets me select devices to monitor and control. Being able to receive device state changes and directly affect device states would make this possible.

Home Assistant changed the term ‘service’ to ‘action’ some time ago. So any example using ‘service’ should work if you use ‘action’ instead.

Have you liked at the docs for keypad and key collector?

The documentation for homeassistant.action is quite sparse. But your comment pushed me to explore more (thanks) and I finally figured it out:

    on_press:
      - homeassistant.action:
          service: cover.toggle
          data: {"entity_id": "cover.den_shades"}

So it looks like I have the device-to-HA path in place. Still trying to understand how to setup the HA-to-device path, i.e. to have HA notify my device when other entities change state.

I understand keypad and key collector. I had to write my own external component for the 4x4 NeoTrellis keypad since it is based on I2C, not GPIO-wired. I used the matrix_keypad internal component as a starting point for the code and tested key provider and key collector in the process. But I don’t see how key collector helps here.

The LocalDeck keyboard has a very interesting “configurator” that appears to encapsulate all aspects of specifying the behavior of the keyboard buttons and lights in a way that’s very appealing. It seems to work on the Home Assistant server side, perhaps as a service or integration. May be worthwhile to look into a similar approach. May also be worthwhile just to buy his product!! :wink: