Configuring a callback after a shell command

Hello forum,
on my way to make Asus TB S working, I revise the method to enable the GPIO. The only way I found is to use the program gpio. This program allows to access the memory without special permission.
The first my attempt was to call the python subprocess and send the command encapsulated in a python script. Currently I’m trying to call the shell command within HA directly.

For the output it seems I can manage. But for the inputs I think it would take to setup a callback when the program will resume its idle state.

So the program allows to call the function wfi and remain idle there until the input will trigger the state change. My question is about to arrange the script in a formula that will accept this condition and put the program in background, until the program exit after an interrupt.

At the moment I can’t figure how HA can manage such situation.

I’m trying to figure out how to solve this intent.

I revise the operation that it should be something like an automation. A shell script will be fire and HA will note a hook to wait for the event to change its state. Then, once the state has changed it might have a condition and an action to deal upon, which is mostly similar to other events, binary sensors and similar inputs.

Please I need a bit of an example to get started.