shell_command:
  gpio17_init: (echo 17 > /sys/class/gpio/export) && (sleep 1) && (echo out > /sys/class/gpio/gpio17/direction)
  gpio17_turn_on: (echo 1 > /sys/class/gpio/gpio17/value)
  gpio17_turn_off: (echo 0 > /sys/class/gpio/gpio17/value)
  gpio17_deinit: (echo 17 > /sys/class/gpio/unexport)

binary_sensor:
  - platform: command_line
    name: gpio17_value
    command: cat /sys/class/gpio/gpio17/value
    payload_on: 1
    payload_off: 0
    scan_interval: 1

light:
  - platform: template
    lights:
      gpio17_led_light:
        friendly_name: GPIO17_LED
        turn_on:
          service: shell_command.gpio17_turn_on
        turn_off:
          service: shell_command.gpio17_turn_off
        value_template: "{{ states.binary_sensor.gpio17_value.state }}"

automation:
  - alias: create GPIO17 sysfs
    initial_state: True
    trigger:
      - platform: homeassistant
        event: start
    action:
      service: shell_command.gpio17_init
  - alias: delete GPIO17 sysfs
    initial_state: True
    trigger:
      - platform: homeassistant
        event: shutdown
    action:
      service: shell_command.gpio17_deinit