Raspery Pi Cover Help

I need some help with this please.
I was using the pi with a different setup and liked the idea of HA way better.
This is a snip of the python code I was using for the garage door.

import RPi.GPIO as GPIO #import the GPIO library
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)

And this worked fine
How do i translate that into HA?

cover:
  - platform: rpi_gpio
    relay_time: 0.2
    invert_relay: false
    state_pull_mode: 'UP'
    invert_state: true
    covers:
      - relay_pin: 4
        state_pin: 27
        name: Garage

The part that I am confused about it the state pin. What is that?
I have a magnetic sensor also that is setup like this and work great. Is that what I use for the state pin?

binary_sensor:    
  - platform: rpi_gpio
    ports:
      27: Garage Door

I should probably explain what happens with this setup.
Once HA restarts the door will automatically open and wont close. None of the cover commands work and the physical button no longer works. I need to comment everything out and restart be for I can close the door.

Any help would be appreciated.
Thanks