ESP32 controlling 12V powered din rail relay please help

hello,

I am trying to control a 12v din rail relay, this one https://www.amazon.com/gp/product/B0BRM9ZQGX/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1
I am confuse about the wiring
from what I understood I need to power the relay com port with the positive of the 12v power supply then x1 x2 x3 and x4 to gpio of the esp32 and the negative of esp32 to the negative of the 12v power supply
I ve tried this everything is fine in home assistant relay light is on but I can’t control it from home assistant

does somebody can help
sorry if my explanation are confused I am a noob

No yaml makes it hard to help.

No wiring diagram makes it hard to help.

No log makes it hard to help.

No datasheet makes it … am I repeating myself?

2 Likes

sorry as I said I am a noob

esphome:
  name: poolsarace

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "02ba74739f28a70f42ee9ea6428c304c"

wifi:
  ssid: 
  password: 

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Comp Led Fallback Hotspot"
    password: "dSOAxFnGLCWd"

web_server:
  port: 80
  version: 1  

  
  
  
  # Example configuration entry



captive_portal:

switch:
  - platform: gpio
    pin: GPIO23
    name: "testiswitch"
    id: testiswitch
    restore_mode: ALWAYS_OFF
   
    
  - platform: gpio
    name: buttontest
    pin:
      number: GPIO33
    id: button1
    on_turn_on:
    - delay: 500ms
    - switch.turn_on: testiswitch
  
  



    

log :

INFO Reading configuration /config/esphome/poolbox.yaml…
INFO Starting log output from poolsarace.local using esphome API
INFO Successfully connected to poolsarace.local
[12:55:04][I][app:102]: ESPHome version 2023.5.1 compiled on May 18 2023, 12:00:30
[12:55:04][C][wifi:505]: WiFi:
[12:55:04][C][wifi:363]: Local MAC: C8:C9:A3:C9:D2:F4
[12:55:04][C][wifi:364]: SSID: ‘The View’[redacted]
[12:55:04][C][wifi:365]: IP Address: 192.168.0.146
[12:55:04][C][wifi:367]: BSSID: 84:D8:1B:82:42:99[redacted]
[12:55:04][C][wifi:368]: Hostname: ‘poolsarace’
[12:55:04][C][wifi:370]: Signal strength: -41 dB ▂▄▆█
[12:55:04][C][wifi:374]: Channel: 3
[12:55:04][C][wifi:375]: Subnet: 255.255.255.0
[12:55:04][C][wifi:376]: Gateway: 192.168.0.1
[12:55:04][C][wifi:377]: DNS1: 192.168.0.1
[12:55:04][C][wifi:378]: DNS2: 0.0.0.0
[12:55:04][C][logger:301]: Logger:
[12:55:04][C][logger:302]: Level: DEBUG
[12:55:04][C][logger:303]: Log Baud Rate: 115200
[12:55:04][C][logger:305]: Hardware UART: UART0
[12:55:04][C][switch.gpio:068]: GPIO Switch ‘testiswitch’
[12:55:04][C][switch.gpio:091]: Restore Mode: always OFF
[12:55:04][C][switch.gpio:031]: Pin: GPIO23
[12:55:04][C][switch.gpio:068]: GPIO Switch ‘buttontest’
[12:55:04][C][switch.gpio:091]: Restore Mode: always OFF
[12:55:04][C][switch.gpio:031]: Pin: GPIO33
[12:55:04][C][captive_portal:088]: Captive Portal:
[12:55:04][C][web_server:151]: Web Server:
[12:55:04][C][web_server:152]: Address: poolsarace.local:80
[12:55:04][C][mdns:108]: mDNS:
[12:55:04][C][mdns:109]: Hostname: poolsarace
[12:55:04][C][ota:093]: Over-The-Air Updates:
[12:55:04][C][ota:094]: Address: poolsarace.local:3232
[12:55:04][C][ota:097]: Using Password.
[12:55:04][C][api:138]: API Server:
[12:55:04][C][api:139]: Address: poolsarace.local:6053
[12:55:04][C][api:143]: Using noise encryption: NO

I am looking to a diagram to control the relay with the esp32 but can’t figure out how to wire correctly
don’t hesitate to tell me how to format my questions in a better way

thank you

1 Like

it should be easier to help
feel free to mention the good way to formulate again
don’t hesitate to correct again if needed
thanks

1 Like

I’m also a newbie to relays (but to ESPHome or HA).

My reading of the link is that the relay needs to be switched/controlled by 12V logic.

An esp is only 3.3v pin logic (5v tolerant).

See how this one can be driven by 3.3v…
AU $0.63 35%OFF | 3V 3.3V 1/2/4 Channel Relay Module Low Level Trigger Liluminated Relay with Lamp Relay Output 4 way Relay Module for Arduino
https://a.aliexpress.com/_mqjvIsG

I might well be wrong here on switching voltage but that’s my thoughts.

1 Like

thank you

I know ho to make it works wit classical 3,3 or 5v relay, but for this application I need din rail relay, some of them need to be 30 amp so most of them can only be powered by 12 or 24v
I have the 12v power supply, just need to know how to wire it.

1 Like
  1. In the webpage that the esp32 generates, can you switch the relay? What log do you get when you try?
  2. Have you imported the esp32 into HA via this page Open your Home Assistant instance and show your integrations. and hitting “Add Integration”?
1 Like

1 yes I can switch the relay from the webpage but nothing change on the physical relay

2 yes I have imported the esp32 into HA

with traditional 5v and 3,3 relay I have no problem
just this one in 12v the connection is different because of the 12v

now I have connected one of the com port on the relay to the 12v power supply positive, the number 4 port to gpio23 and the ground of esp32 to the ground of the power supply

this way the relay light up but I doesn’t move when I use the switch in HA or via the webpage