es32d26 espHome.yaml

es32d26 espHome.yaml

# ESPHome Configuration
# Hardware: ESP32-DevKit C installed in Eletechsup ES32D26
#
# ┌─ DIP SWITCH SW1 NOTE ──────────────────────────────────────────┐
# │ Vo1/Vo2 (0-10V AO) and Io1/Io2 (0-20mA AO) share IO25/IO26.  │
# │ Only ONE can be active at a time — set SW1 accordingly.        │
# │ This config assumes SW1 is set to Vo1/Vo2 (0-10V) mode.       │
# └────────────────────────────────────────────────────────────────┘
#
# ┌─ ADC2 LIMITATION ──────────────────────────────────────────────┐
# │ GPIO14 (Vi1) and GPIO27 (Vi3) are ADC2 pins. ADC2 cannot be   │
# │ used while WiFi is active — these inputs are omitted.          │
# └────────────────────────────────────────────────────────────────┘
#
# ┌─ 74HC595 PIN ASSIGNMENT NOTE ──────────────────────────────────┐
# │ The ES32D26 manual lists IO22/IO23/IO12/IO13 for the 74HC595   │
# │ but does not specify which pin is data/clock/latch/OE.         │
# │ Four candidate configurations are provided below as comments.  │
# │ Try each one until relays respond. The OE pin must be active   │
# │ low — if no relays fire at all, OE is likely misconfigured.    │
# │                                                                │
# │ Config A (current — try first):                                │
# │   data=IO23, clock=IO22, latch=IO13, oe=IO12                   │
# │ Config B:                                                      │
# │   data=IO23, clock=IO22, latch=IO12, oe=IO13                   │
# │ Config C:                                                      │
# │   data=IO22, clock=IO23, latch=IO13, oe=IO12                   │
# │ Config D:                                                      │
# │   data=IO22, clock=IO23, latch=IO12, oe=IO13                   │
# └────────────────────────────────────────────────────────────────┘

esphome:
  name: es32d26
  friendly_name: "ES32D26 Controller"

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:

api:
  encryption:
    key: !secret api_encryption_key

ota:
  - platform: esphome
    password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "ES32D26 Fallback"
    password: !secret fallback_password

captive_portal:


# ─────────────────────────────────────────────────────────────────
# RELAY OUTPUTS CH1-CH8
# 74HC595 shift register
# Relays are active low — inverted: true corrects the logic
# restore_mode: ALWAYS_OFF prevents all relays latching on boot
# ─────────────────────────────────────────────────────────────────

sn74hc595:
  - id: sn74hc595_hub
    data_pin: GPIO12
    clock_pin: GPIO22
    latch_pin: GPIO23
    oe_pin: GPIO13
    sr_count: 1

switch:
  - platform: gpio
    name: "CH1 Relay"
    id: relay_ch1
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 0
      inverted: false

  - platform: gpio
    name: "CH2 Relay"
    id: relay_ch2
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 1
      inverted: false

  - platform: gpio
    name: "CH3 Relay"
    id: relay_ch3
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 2
      inverted: false

  - platform: gpio
    name: "CH4 Relay"
    id: relay_ch4
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 3
      inverted: false

  - platform: gpio
    name: "CH5 Relay"
    id: relay_ch5
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 4
      inverted: false

  - platform: gpio
    name: "CH6 Relay"
    id: relay_ch6
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 5
      inverted: false

  - platform: gpio
    name: "CH7 Relay"
    id: relay_ch7
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 6
      inverted: false

  - platform: gpio
    name: "CH8 Relay"
    id: relay_ch8
    restore_mode: ALWAYS_OFF
    pin:
      sn74hc595: sn74hc595_hub
      number: 7
      inverted: false


# ─────────────────────────────────────────────────────────────────
# DIGITAL INPUTS IN1-IN8 (NPN opto-isolated)
# 74HC165 shift register
# PL (load) = IO15, CP (clock) = IO2, Q7 (data) = IO0
# ─────────────────────────────────────────────────────────────────

sn74hc165:
  - id: sn74hc165_hub
    clock_pin: GPIO2
    data_pin: GPIO15
    load_pin: GPIO0
    sr_count: 1

binary_sensor:
  - platform: gpio
    name: "IN1 Digital Input"
    id: din_in1
    pin:
      sn74hc165: sn74hc165_hub
      number: 0
      inverted: true

  - platform: gpio
    name: "IN2 Digital Input"
    id: din_in2
    pin:
      sn74hc165: sn74hc165_hub
      number: 1
      inverted: true

  - platform: gpio
    name: "IN3 Digital Input"
    id: din_in3
    pin:
      sn74hc165: sn74hc165_hub
      number: 2
      inverted: true

  - platform: gpio
    name: "IN4 Digital Input"
    id: din_in4
    pin:
      sn74hc165: sn74hc165_hub
      number: 3
      inverted: true

  - platform: gpio
    name: "IN5 Digital Input"
    id: din_in5
    pin:
      sn74hc165: sn74hc165_hub
      number: 4
      inverted: true

  - platform: gpio
    name: "IN6 Digital Input"
    id: din_in6
    pin:
      sn74hc165: sn74hc165_hub
      number: 5
      inverted: true

  - platform: gpio
    name: "IN7 Digital Input"
    id: din_in7
    pin:
      sn74hc165: sn74hc165_hub
      number: 6
      inverted: true

  - platform: gpio
    name: "IN8 Digital Input"
    id: din_in8
    pin:
      sn74hc165: sn74hc165_hub
      number: 7
      inverted: true


# ─────────────────────────────────────────────────────────────────
# 0-10V ANALOG OUTPUTS Vo1 & Vo2
# GPIO25=DAC1 (Vo1), GPIO26=DAC2 (Vo2)
# ─────────────────────────────────────────────────────────────────

output:
  - platform: esp32_dac
    pin: GPIO25
    id: dac_vo1

  - platform: esp32_dac
    pin: GPIO26
    id: dac_vo2

number:
  - platform: template
    name: "Vo1 Output (0-10V)"
    id: vo1_level
    min_value: 0
    max_value: 100
    step: 1
    unit_of_measurement: "%"
    icon: "mdi:sine-wave"
    optimistic: true
    restore_value: true
    initial_value: 0
    set_action:
      - output.set_level:
          id: dac_vo1
          level: !lambda "return x / 100.0;"

  - platform: template
    name: "Vo2 Output (0-10V)"
    id: vo2_level
    min_value: 0
    max_value: 100
    step: 1
    unit_of_measurement: "%"
    icon: "mdi:sine-wave"
    optimistic: true
    restore_value: true
    initial_value: 0
    set_action:
      - output.set_level:
          id: dac_vo2
          level: !lambda "return x / 100.0;"


# ─────────────────────────────────────────────────────────────────
# ANALOG INPUTS
#
# Vi2 (GPIO33) and Vi4 (GPIO32) — ADC1, work with WiFi active
# Vi1 (GPIO14) and Vi3 (GPIO27) — ADC2, disabled (incompatible with WiFi)
#
# Filter formula from ES32A08 reference: x / 10.0 * (10.0 + 43.0)
# This accounts for the onboard resistor divider (10K + 43K).
# Adjust the 43.0 value if your readings don't match a known input voltage.
# ─────────────────────────────────────────────────────────────────

sensor:
  - platform: adc
    pin:
      number: GPIO33
      mode:
        input: true
    name: "Vi2 Voltage Input"
    id: vi2
    attenuation: auto
    update_interval: 5s
    unit_of_measurement: "V"
    accuracy_decimals: 2
    filters:
      - lambda: return x / 10.0 * (10.0 + 43.0);
      - round: 2
    icon: "mdi:flash"

  - platform: adc
    pin:
      number: GPIO32
      mode:
        input: true
    name: "Vi4 Voltage Input"
    id: vi4
    attenuation: auto
    update_interval: 5s
    unit_of_measurement: "V"
    accuracy_decimals: 2
    filters:
      - lambda: return x / 10.0 * (10.0 + 43.0);
      - round: 2
    icon: "mdi:flash"

  # Current inputs — all on ADC1, work with WiFi active
  # Shunt resistor on ES32A08 is 91 ohm (4mA=0.364V, 20mA=1.82V)
  # Adjust min_v/max_v if your board uses a different shunt value
  - platform: adc
    pin:
      number: GPIO34
      mode:
        input: true
    name: "Ii1 Current Input"
    id: ii1
    attenuation: auto
    update_interval: 5s
    unit_of_measurement: "mA"
    accuracy_decimals: 2
    filters:
      - lambda: |-
          float min_v = 0.364;
          float max_v = 1.82;
          float ma = (x - min_v) * 20.0 / (max_v - min_v);
          if (ma < 0.0) ma = 0.0;
          if (ma > 20.0) ma = 20.0;
          return ma;
      - round: 2
    icon: "mdi:current-dc"

  - platform: adc
    pin:
      number: GPIO39
      mode:
        input: true
    name: "Ii2 Current Input"
    id: ii2
    attenuation: auto
    update_interval: 5s
    unit_of_measurement: "mA"
    accuracy_decimals: 2
    filters:
      - lambda: |-
          float min_v = 0.364;
          float max_v = 1.82;
          float ma = (x - min_v) * 20.0 / (max_v - min_v);
          if (ma < 0.0) ma = 0.0;
          if (ma > 20.0) ma = 20.0;
          return ma;
      - round: 2
    icon: "mdi:current-dc"

  - platform: adc
    pin:
      number: GPIO35
      mode:
        input: true
    name: "Ii3 Current Input"
    id: ii3
    attenuation: auto
    update_interval: 5s
    unit_of_measurement: "mA"
    accuracy_decimals: 2
    filters:
      - lambda: |-
          float min_v = 0.364;
          float max_v = 1.82;
          float ma = (x - min_v) * 20.0 / (max_v - min_v);
          if (ma < 0.0) ma = 0.0;
          if (ma > 20.0) ma = 20.0;
          return ma;
      - round: 2
    icon: "mdi:current-dc"

  - platform: adc
    pin:
      number: GPIO36
      mode:
        input: true
    name: "Ii4 Current Input"
    id: ii4
    attenuation: auto
    update_interval: 5s
    unit_of_measurement: "mA"
    accuracy_decimals: 2
    filters:
      - lambda: |-
          float min_v = 0.364;
          float max_v = 1.82;
          float ma = (x - min_v) * 20.0 / (max_v - min_v);
          if (ma < 0.0) ma = 0.0;
          if (ma > 20.0) ma = 20.0;
          return ma;
      - round: 2
    icon: "mdi:current-dc"

  - platform: template
    name: "Vo1 Voltage (estimated)"
    lambda: "return id(vo1_level).state / 10.0;"
    unit_of_measurement: "V"
    accuracy_decimals: 1
    update_interval: 5s
    icon: "mdi:flash"

  - platform: template
    name: "Vo2 Voltage (estimated)"
    lambda: "return id(vo2_level).state / 10.0;"
    unit_of_measurement: "V"
    accuracy_decimals: 1
    update_interval: 5s
    icon: "mdi:flash"

Back to blog

Leave a comment