{% set devicename = "esphome_plug02"  %}

{% include "/includes/ansible.inc.yaml" %}
{% include "/includes/board.esp01_1m.inc.yaml" %}

  comment: LED Theke
{% include "/includes/common.inc.yaml" %}

  on_message:
    - topic: ESPHome/{{ devicename }}/state/command
      payload: "ON"
      then:
        - switch.turn_on: relay
    - topic: ESPHome/{{ devicename }}/state/command
      payload: "OFF"
      then:
        - switch.turn_off: relay
    - topic: warpzone/door/status
      payload: "CLOSED"
      then:
        - switch.turn_off: relay
    - topic: warpzone/door/status_once
      payload: "OPEN"
      then:
        - switch.turn_on: relay

status_led:
  pin:
    number: GPIO13
    inverted: false

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "{{ devicename }} Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "{{ devicename }} Status"

switch:
  - platform: gpio
    name: "{{ devicename }} Relay"
    pin: GPIO12
    id: "relay"
    restore_mode: RESTORE_DEFAULT_ON