How to configure a smart switch to auto turn off after a given period of time?

I have one of these locks in my house. These connects to a door bell type switch inside house that you can use to trigger them to unlock.

I thinking of buying one of these Sonoff smart switches. But the problem is these are standard turn on/off switches rather then bell type switches. Is there a way I can configure the button inside Home Assistant in such a way that it turns off after say 0.5 or 1 second after I turn it on, so it acts like a bell switch instead?

Sure, flash it with ESPHome and you can build the functionality into the device.

switch:
  - platform: gpio
    name: "Sonoff Basic Relay"
    pin: GPIO12
    id: relay
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: relay

https://esphome.io/components/switch/gpio.html#momentary-switch

The template for that device is here:

Or just do it in Home Assistant with something like this:

trigger:
  - platform: state
    entity_id: switch.my_lock_button
    to: 'on'
    for: 1
action:
  - service: switch.turn_off
    target: 
      entity_id: switch.my_lock_button

The disadvantage with this method is that it relies on home assistant to be running and in contact with the sonoff for it to work.