# =============================================================================
# Configuration Complète DOMO22 - All-in-One
# Version: 1.0
# Date: 2025-10-31
# Produit: ECO-DOMO-22 - Centrale Domotique Compacte
# =============================================================================
# Contenu:
#   - Configuration de base (WiFi, API, OTA, Logger, I2C)
#   - 8 Sorties relais 10A
#   - 8 Entrées numériques avec anti-rebond
#   - Capteurs BME280 + BH1750 + DS18B20
#   - Interface web de diagnostic
#   - Automatisations de base
# =============================================================================

# -----------------------------------------------
# BASE
# -----------------------------------------------
esphome:
  name: domo22
  friendly_name: "Centrale DOMO22"
  platform: ESP32
  board: esp32dev

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "DOMO22 Fallback"
    password: !secret ap_password

web_server:
  port: 80

api:
  encryption:
    key: !secret api_encryption_key

ota:
  password: !secret ota_password

logger:
  level: DEBUG

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  frequency: 400kHz

# -----------------------------------------------
# SORTIES RELAIS (8 canaux 10A)
# -----------------------------------------------
switch:
  - platform: gpio
    pin: GPIO13
    name: "Relais 1 - Éclairage Principal"
    id: relay_1
    icon: "mdi:lightbulb"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio
    pin: GPIO12
    name: "Relais 2 - Éclairage Secondaire"
    id: relay_2
    icon: "mdi:lightbulb-outline"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio
    pin: GPIO14
    name: "Relais 3 - Prise Salon"
    id: relay_3
    icon: "mdi:power-socket-eu"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio
    pin: GPIO27
    name: "Relais 4 - Ventilation"
    id: relay_4
    icon: "mdi:fan"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio
    pin: GPIO26
    name: "Relais 5 - Chauffage"
    id: relay_5
    icon: "mdi:radiator"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio
    pin: GPIO25
    name: "Relais 6 - Pompe"
    id: relay_6
    icon: "mdi:pump"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: gpio
    pin: GPIO33
    name: "Relais 7 - Portail"
    id: relay_7
    icon: "mdi:gate"
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: relay_7

  - platform: gpio
    pin: GPIO32
    name: "Relais 8 - Réserve"
    id: relay_8
    icon: "mdi:power"
    restore_mode: RESTORE_DEFAULT_OFF

# -----------------------------------------------
# ENTRÉES NUMÉRIQUES (8 canaux)
# -----------------------------------------------
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO34
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 1 - Bouton Poussoir"
    id: input_1
    device_class: button
    filters:
      - delayed_on: 50ms
      - delayed_off: 50ms
    on_press:
      - switch.toggle: relay_1

  - platform: gpio
    pin:
      number: GPIO35
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 2 - Détecteur Mouvement"
    id: input_2
    device_class: motion
    filters:
      - delayed_on: 100ms

  - platform: gpio
    pin:
      number: GPIO36
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 3 - Contact Porte"
    id: input_3
    device_class: door

  - platform: gpio
    pin:
      number: GPIO39
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 4 - Contact Fenêtre"
    id: input_4
    device_class: window

  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 5"
    id: input_5
    filters:
      - delayed_on: 50ms

  - platform: gpio
    pin:
      number: GPIO16
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 6"
    id: input_6

  - platform: gpio
    pin:
      number: GPIO17
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 7"
    id: input_7

  - platform: gpio
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
      inverted: true
    name: "Entrée 8"
    id: input_8

# -----------------------------------------------
# CAPTEURS
# -----------------------------------------------
sensor:
  - platform: bme280
    temperature:
      name: "Température Ambiante"
      id: temp_ambient
      oversampling: 16x
      filters:
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
    humidity:
      name: "Humidité Ambiante"
      id: humidity_ambient
      filters:
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
    pressure:
      name: "Pression Atmosphérique"
      id: pressure
      filters:
        - sliding_window_moving_average:
            window_size: 10
            send_every: 10
    address: 0x76
    update_interval: 60s

  - platform: bh1750
    name: "Luminosité"
    id: light_sensor
    address: 0x23
    update_interval: 30s
    filters:
      - lambda: |-
          if (x < 10) return 0;
          else return x;

  - platform: dallas
    address: 0x1c0000031edd2a28
    name: "Température Précise"
    id: temp_precise
    resolution: 12
    filters:
      - offset: -0.5

  - platform: wifi_signal
    name: "Signal WiFi"
    update_interval: 60s

  - platform: uptime
    name: "Uptime"
    update_interval: 60s
