esphome:
  name: uptime-heart
  friendly_name: uptime-heart

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "YOUR_ENCRYPTION_KEY_HERE"

web_server:
  port: 80

ota:
  - platform: esphome
    password: "YOUR_OTA_PASSWORD_HERE"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Uptime-Heart Fallback Hotspot"
    password: "fallback_password"

captive_portal:

# Time component for scheduling
time:
  - platform: sntp
    id: sntp_time
    
output:
  - platform: ledc
    pin: GPIO17
    id: output_red
  - platform: ledc
    pin: GPIO18
    id: output_green

light:
  - platform: monochromatic
    name: "Rote LED"
    output: output_red
    id: led_red
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - light.turn_off: led_green
    effects:
      - strobe:
          name: "Fast Heartbeat"
          colors:
            - state: true
              brightness: 100%
              duration: 200ms
            - state: false
              duration: 200ms
      - strobe:
          name: "Slow Pulse"
          colors:
            - state: true
              brightness: 100%
              duration: 1s
            - state: false
              duration: 1s

  - platform: monochromatic
    name: "Grüne LED"
    output: output_green
    id: led_green
    restore_mode: ALWAYS_OFF
    on_turn_on:
      - light.turn_off: led_red
    effects:
      - pulse:
          name: "Breathing"
          transition_length: 1s
          update_interval: 1s
          min_brightness: 30%
          max_brightness: 100%

# Switches for Home Assistant control
switch:
  - platform: template
    name: "Monitoring Enabled"
    id: monitoring_enabled
    restore_mode: RESTORE_DEFAULT_ON
    optimistic: true
    icon: "mdi:monitor-eye"
    
  - platform: template
    name: "Force Red LED"
    id: force_red
    restore_mode: RESTORE_DEFAULT_OFF
    optimistic: true
    icon: "mdi:alert-circle"
    turn_on_action:
      - switch.turn_off: force_green
      - light.turn_off: led_green
      - light.turn_on: led_red
    turn_off_action:
      - light.turn_off: led_red
    
  - platform: template
    name: "Force Green LED"
    id: force_green
    restore_mode: RESTORE_DEFAULT_OFF
    optimistic: true
    icon: "mdi:check-circle"
    turn_on_action:
      - switch.turn_off: force_red
      - light.turn_off: led_red
      - light.turn_on: led_green
    turn_off_action:
      - light.turn_off: led_green

  - platform: template
    name: "Quiet Hours Active"
    id: quiet_hours
    restore_mode: RESTORE_DEFAULT_OFF
    optimistic: true
    icon: "mdi:sleep"
    turn_on_action:
      - light.turn_off: led_red
      - light.turn_off: led_green
