First, please see the sticky post about code formatting.
Second, you’ll want an automation
Something very roughly like:
automation:
- alias: "Turn it off"
trigger:
- platform: state
entity_id: switch.gamer_pc
to: 'on'
for: '00:00:02'
action:
- service: switch.turn_off
data:
target: switch.gamer_pc