Need help for switch configuration (RPi GPIO)

I need to switch one gpio port OFF automatically 5 seconds after it is switched ON (by Home Assistant or externally).

What I have is:
switch:

  • platform: rpi_gpio
    ports:
    4: MyFirstSwitch

Could someone help how to program the respective automation section. I’ve read the documentatoin and tried some solutions, but cannot get working configuration file. It is my first expirience with Hass.

You need to write an automation something like this…

- alias: "GPIO Switch with delay"
  trigger:
    platform: state
    entity_id: switch.MyFirstSwitch
    from: "off"
    to: "on"
  action:
    - delay: '00:00:05'
    - service: switch.turn_off
      entity_id: switch.MyFirstSwitch

Check in dev tools under states (<> button in the side panel) what the name of the switch is.