Can this be templated or lambda(d?)?

I just found the component that makes a ESP32 S2/S3 work as a HID.
Now I want to set a number in the ESP and this button should then be pressed “on the keyboard”.

number:
  - platform: template
    name: "Digit"
    id: digit
    min_value: 0
    max_value: 9
    step: 1
    icon: 'mdi:cog'
    restore_value: true
    initial_value: 1.0
    optimistic: true


button:
  - platform: template
    name: "Template test"
    on_press:
      then:
        - keyboard.down:
            id: kbd
            keys: 
              - "Digit{{ digit}}"
        - delay: 10ms
        - keyboard.up:
            id: kbd
            keys: 
              - "Digit{{ digit}}"

I assume I could do some type of lambda where if( digit == 0) and so on but the above would be nice.
Or what other options do I have?

Which component are you referring to?

On monday this beauty will be mounted under my desk at work.
When I scan my RFID card used for door access at work the ESP sends an Escape button followed by the base of my password and lastly the current digit set in the ESP web server.

Clever way of writing down the password to your computer in a digital post-it note and affixing it to your desk!