Want relay to turn off after 3 seconds

You should post code as a code-section. Take 3 minutes time to learn how to do it with even less effort than uploading a picture

Your code has to be modified to detect the transitions from low to high
if this transition is detected switch on relay and start a timer

check if 3 seconds of time have passed by if yes switch relay off

then check for transition from high to low to reset

The best way to do this is to use a code called state-machine

state 1: wait for IO-pin to change to HIGH
if this happends switch relay on, start timer and switch to state 2

state 2: check if 3 seconds of time have passed by
if this happends switch relay off and change to state 3

state 3: check if switch changes to low
if this happends change to state 1

Here is a tutorial that shows the principle of state-machines