substitutions:
  
  device_name: "plugstrip01"
  friendly_name: "plugstrip01"
  
  main_icon: "power-socket-uk"
  
  
  
  default_state: "RESTORE_DEFAULT_OFF"
esphome:
  name: "${device_name}"
esp8266:
  board: esp01_1m
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  ap:
    ssid: "${device_name} Fallback Hotspot"
    password: !secret hotspot_wifi_password
captive_portal:
logger:
api:
ota:
time:
  - platform: sntp
    id: sntp_time
binary_sensor:
  
  - platform: gpio
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Button"
    on_press:
      if:
        condition:
          light.is_on: led
        then:
          - switch.turn_off: relay_socket_1
          - switch.turn_off: relay_socket_2
          - switch.turn_off: relay_socket_3
          - switch.turn_off: relay_socket_4
          - switch.turn_off: relay_usb
          - light.turn_off:
              id: led
              transition_length: 0s
        else:
          - switch.turn_on: relay_socket_1
          - switch.turn_on: relay_socket_2
          - switch.turn_on: relay_socket_3
          - switch.turn_on: relay_socket_4
          - switch.turn_on: relay_usb
          - light.turn_on:
              id: led
              brightness: 100%
              transition_length: 0s
  - platform: status
    name: "${friendly_name} Server Status"
switch:
  
  - platform: gpio
    name: "${friendly_name} socket 1"
    icon: "mdi:${main_icon}"
    pin: GPIO13
    id: relay_socket_1
    restore_mode: "${default_state}"
    on_turn_on:
      - light.turn_on:
          id: led
          brightness: 100%
          transition_length: 0s
    on_turn_off:
      if:
        condition:
          and:
            - switch.is_off: relay_socket_1
            - switch.is_off: relay_socket_2
            - switch.is_off: relay_socket_3
            - switch.is_off: relay_socket_4
            - switch.is_off: relay_usb
        then:
          - light.turn_off:
              id: led
              transition_length: 0s
  
  - platform: gpio
    name: "${friendly_name} socket 2"
    icon: "mdi:${main_icon}"
    pin: GPIO12
    id: relay_socket_2
    restore_mode: "${default_state}"
    on_turn_on:
      - light.turn_on:
          id: led
          brightness: 100%
          transition_length: 0s
    on_turn_off:
      if:
        condition:
          and:
            - switch.is_off: relay_socket_1
            - switch.is_off: relay_socket_2
            - switch.is_off: relay_socket_3
            - switch.is_off: relay_socket_4
            - switch.is_off: relay_usb
        then:
          - light.turn_off:
              id: led
              transition_length: 0s
  
  - platform: gpio
    name: "${friendly_name} socket 3"
    icon: "mdi:${main_icon}"
    pin: GPIO4
    id: relay_socket_3
    restore_mode: "${default_state}"
    on_turn_on:
      - light.turn_on:
          id: led
          brightness: 100%
          transition_length: 0s
    on_turn_off:
      if:
        condition:
          and:
            - switch.is_off: relay_socket_1
            - switch.is_off: relay_socket_2
            - switch.is_off: relay_socket_3
            - switch.is_off: relay_socket_4
            - switch.is_off: relay_usb
        then:
          - light.turn_off:
              id: led
              transition_length: 0s
  
  - platform: gpio
    name: "${friendly_name} socket 4"
    icon: "mdi:${main_icon}"
    pin: GPIO5
    id: relay_socket_4
    restore_mode: "${default_state}"
    on_turn_on:
      - light.turn_on:
          id: led
          brightness: 100%
          transition_length: 0s
    on_turn_off:
      if:
        condition:
          and:
            - switch.is_off: relay_socket_1
            - switch.is_off: relay_socket_2
            - switch.is_off: relay_socket_3
            - switch.is_off: relay_socket_4
            - switch.is_off: relay_usb
        then:
          - light.turn_off:
              id: led
              transition_length: 0s
  
  - platform: gpio
    name: "${friendly_name} USB"
    icon: "mdi:${main_icon}"
    pin: GPIO14
    id: relay_usb
    restore_mode: "${default_state}"
    on_turn_on:
      - light.turn_on:
          id: led
          brightness: 100%
          transition_length: 0s
    on_turn_off:
      if:
        condition:
          and:
            - switch.is_off: relay_socket_1
            - switch.is_off: relay_socket_2
            - switch.is_off: relay_socket_3
            - switch.is_off: relay_socket_4
            - switch.is_off: relay_usb
        then:
          - light.turn_off:
              id: led
              transition_length: 0s
sensor:
  
  - platform: wifi_signal
    name: "${friendly_name} WiFi Status"
    update_interval: 60s
output:
  - platform: esp8266_pwm
    id: state_led
    pin:
      number: GPIO1
      inverted: true
light:
  - platform: monochromatic
    output: state_led
    id: led