Best way to integrate 4 buttons RF remote?

I did setup a SonOff RF bridge with Tasmota. I would like to integrate a 4 buttons remote. It sends a simple MQTT message when one of the button is pressed, the data field corresponds to the button.

“{“Time”:“2021-06-12T10:00:19”,“RfReceived”:{“Sync”:10330,“Low”:340,“High”:1040,“Data”:“640A88”,“RfKey”:“None”}}”

Of course, I can just use rednode to get this mqtt message (as I did for debug), but I do not find this very “clean”. I have 4 remotes with 4 buttons each, they only differ by the value of the data field. This does not leads to very readable code.
I would like to have some sort of entity, sensor, etc defined in HA with a readable name (e.g. ButonA_Remote1) . To make a comparison with programming, it’s like using a constant well defined in a program instead of using a value hard coded. Both works, but having a constant makes things more clear. So having an ‘entity’, sensor, etc natively from HA would ease maintenance and readability.

What is the best way to integrate such a remote into HA ? my remote does not seems to be a binary_sensor since the remote button has no state (i.e. the MQTT message is only send when the button is released).
So from my understanding, it would be something like an “event” but I do not really know how to define it.

Can you help me with this: what kind of HA 'object (entity, sensor, etc) is the most suitable and how to implement it (a link to en example would be enough)

Thanks for your help

Read this :

Thanks. Seems it potentially solve my pb. I will have a detailed look asap

Thanks a lot for your answer. So I successfully programmed the script, it works.

However, according to the doc it seems that the best approach would be to use a MQTT Device Trigger.

The mqtt device trigger platform uses an MQTT message payload to generate device trigger events.
An MQTT device trigger is a better option than a binary sensor for buttons, remote controls etc.

The approach seems more suitable, however, I did not find any example on how to do it.
Do you have any info on how to use that?

Example of 1 of my 4 buttons remote to switch on an ikea outlet :

automation

- id: '1565365902539'
  alias: Ikea switch2
  trigger:
  - payload: 'ON'
    platform: mqtt
    topic: sensor/ikea_switch2_sensor
  condition: []
  action:
  - data:
      entity_id: switch.ikeaoutlet2_switch
    service: switch.toggle

pyscript :

d = { '9823336':['ikea_switch1_sensor','ON','false'],
      '9823332':['ikea_switch2_sensor','ON','false'],
      '9823330':['ikea_switch3_sensor','ON','false'],
      '9823329':['ikea_switch4_sensor','ON','false'],
      '14163857':['doorbell_sensor','ON','false'],
      '13666408':['firealarm','ON','false'],
      '564886':['garagedoor','ON','false'],
      '16726408':['lichteetkamerboven','ON','false'],
      '16765268':['impuls','ON','false'],
      '16766303':['impulsb','OFF','false'],
      '16765265':['flamingo1','ON','false'],
      '352003':['buurvrouw','ON','false'],
      '1213858':['lichtwaskot','ON','false'],
      '1224498':['buurvrouw1','ON','false'],
      '16762193':['impulsa','OFF','false'],
      '16762196':['impulsa','ON','false'],
      '2291358':['voordeur','ON','true'],
      '2291351':['voordeur','OFF','true'],
      '2283159':['voordeur','OFF','true'],      
      '152232' :['schuindak','ON','false'],
      '16762196':['onbekend','ON','false'],
      '14783052':['firealarm','ON','false'],
      '8345702':['onbekend','ON','false'],
      '774915':['achterdeur','ON','true'],
      '774921':['achterdeur','OFF','true'],
      '951715':['voordeur','ON','true'],
      '951721':['voordeur','OFF','true']
    }


p = str(data.get('payload'))

if p is not None:
  if p in d.keys():
    service_data = {'topic':'sensor/{}'.format(d[p][0]), 'payload':'{}'.format(d[p][1]), 'qos':0, 'retain':'{}'.format(d[p][2])}
  else:
    service_data = {'topic':'sensor/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
#    logger.error('<rfbridge_demux> Received unknown RF command: {}'.format(p))
#    hass.services.call('notify','notifier_rf_unknown', '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}} <rfbridge_demux> Received unknown RF command: {}'.format(p))
  hass.services.call('mqtt', 'publish', service_data, False)

I don’t use tasmota on my sonoff rf-bridge, but openmqttgateway, but the flow is the same.