Home Assistant : Q&A, Tips & Tricks, Your Configs

Tinuva

The Magician
Joined
Feb 10, 2005
Messages
10,673
@SauRoNZA

Maybe this is what you really wanted when you were looking into the home assistant boxes.


overview.png
 

MidnightZA

Expert Member
Joined
Mar 9, 2013
Messages
1,659
Im trying to learn esphome now and I got myself a 1ch relay just to fiddle with before I get more, but I have no idea why I cant get it to switch

I have a D1 mini (powered from my laptop usb)

My wiring is
ESP 5V ---- Relay Vcc
ESP GND ---- Relay GND
ESP D1 Pin ---- Relay In

Code:
YAML:
esphome:
  name: test-relay
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "xxxx"

wifi:
  ssid: "xxxxx"
  password: "xxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test-Relay Fallback Hotspot"
    password: "xxxxx"

captive_portal:

switch:
  - platform: gpio
    pin: D1
    name: "Test Relay"

What am I doing wrong here? The "test relay" entity shows up in HA but does nothing to the relay when toggled. Ive tried other pins also (D2, D3 ,D4)
 

w1tw0lf

Senior Member
Joined
Sep 29, 2009
Messages
992
Have a look here:


Try an use "GPIOxx" as the pin and not "Dx" as pin.

All mine is using "GPIOxx" as a pin on esp8266. On esp32 you would use "Dx" as the pin.

Try:
D4 would be GPIO2

pin: GPIO2
 

deesef

Expert Member
Joined
Mar 3, 2017
Messages
1,804
Im trying to learn esphome now and I got myself a 1ch relay just to fiddle with before I get more, but I have no idea why I cant get it to switch

I have a D1 mini (powered from my laptop usb)

My wiring is
ESP 5V ---- Relay Vcc
ESP GND ---- Relay GND
ESP D1 Pin ---- Relay In

Code:
YAML:
esphome:
name: test-relay
platform: ESP8266
board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
password: "xxxx"

wifi:
ssid: "xxxxx"
password: "xxxxx"

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Test-Relay Fallback Hotspot"
password: "xxxxx"

captive_portal:

switch:
- platform: gpio
pin: D1
name: "Test Relay"

What am I doing wrong here? The "test relay" entity shows up in HA but does nothing to the relay when toggled. Ive tried other pins also (D2, D3 ,D4)
Those pins output about 3 volts at probably 10ma. That is to low for most relays. You will need a transistor to drive more voltage and current for the relay.

Remember that a relay is an inductive device. It generates a reverse voltage when power is removed. You need to include a diode (1N4007) in reverse configuration in parallel with the relay's coil.
 
Last edited:

deesef

Expert Member
Joined
Mar 3, 2017
Messages
1,804
Have a look here:


Try an use "GPIOxx" as the pin and not "Dx" as pin.

All mine is using "GPIOxx" as a pin on esp8266. On esp32 you would use "Dx" as the pin.

Try:
D4 would be GPIO2

pin: GPIO2
That makes no difference... The esphome software takes both naming configurations.
 

w1tw0lf

Senior Member
Joined
Sep 29, 2009
Messages
992
That makes no difference... The esphome software takes both naming configurations.
Could be... that is the only way it has worked for me.

What is type if relay ? Can you share the model or photo of it ?
 

MidnightZA

Expert Member
Joined
Mar 9, 2013
Messages
1,659
Have a look here:


Try an use "GPIOxx" as the pin and not "Dx" as pin.

All mine is using "GPIOxx" as a pin on esp8266. On esp32 you would use "Dx" as the pin.

Try:
D4 would be GPIO2

pin: GPIO2

Thanks I will give it a go and see if that's the issue

Those pins output about 3 volts at probably 10ma. That is to low for most relays. You will need a transistor to drive more voltage and current for the relay.

Remember that a relay is an inductive device. It generates a reverse voltage when power is removed. You need to include a diode (1N4007) in reverse configuration in parallel with the relay's coil.
Could be... that is the only way it has worked for me.

What is type if relay ? Can you share the model or photo of it ?

The relay looks exactly like this. It's a 5V relay to switch a 220V load

My wiring is also exactly like this. I found this pic on google but I used D1 instead of D3
images (10).jpeg
 

MidnightZA

Expert Member
Joined
Mar 9, 2013
Messages
1,659
Have a look here:


Try an use "GPIOxx" as the pin and not "Dx" as pin.

All mine is using "GPIOxx" as a pin on esp8266. On esp32 you would use "Dx" as the pin.

Try:
D4 would be GPIO2

pin: GPIO2

Not working. Its controlling the little blue LED on my D1 mini lol.

What is your board type?
 

w1tw0lf

Senior Member
Joined
Sep 29, 2009
Messages
992
Not working. Its controlling the little blue LED on my D1 mini lol.

What is your board type?
Most of my boards are nodemcu's.

try this:

Code:
output:
  - platform: gpio
    id: relay
    pin: GPIO5

switch
  - platform: binary
    name: "Test Relay"
    output: relay


and replace this:


Code:
switch:
  - platform: gpio
    pin: D1
    name: "Test Relay"

GPIO5 would be the pin marked d1

Also share a photo of how you connected it all up.
 
Last edited:

deesef

Expert Member
Joined
Mar 3, 2017
Messages
1,804
Thanks I will give it a go and see if that's the issue




The relay looks exactly like this. It's a 5V relay to switch a 220V load

My wiring is also exactly like this. I found this pic on google but I used D1 instead of D3
View attachment 1149238

If the light on the D1 Mini switches on and off, then the processor is most likely working. Do you have a multimeter? Check the voltage on the D1 pin with the output set to on and also to off.
 

MidnightZA

Expert Member
Joined
Mar 9, 2013
Messages
1,659
Most of my boards are nodemcu's.

try this:

Code:
output:
  - platform: gpio
    id: relay
    pin: GPIO5

switch
  - platform: binary
    name: "Test Relay"
    output: relay


and replace this:


Code:
switch:
  - platform: gpio
    pin: D1
    name: "Test Relay"

GPIO5 would be the pin marked d1

Also share a photo of how you connected it all up.

1631817118362.png

The error X says "Platform not found: 'switch.binary'"

I will edit on my phone and upload a pic shortly
 

MidnightZA

Expert Member
Joined
Mar 9, 2013
Messages
1,659
Sorry, my mistake... remove the "platform: binary"

Code:
switch:
  - name: "Test Relay"
    output: relay

This also doesn't work. Says something about platform missing

I added the pics now from my phone. Hopefully it attached correctly
 

Attachments

  • 20210916_203758.jpg
    20210916_203758.jpg
    183 KB · Views: 32
  • 20210916_203752.jpg
    20210916_203752.jpg
    114.9 KB · Views: 32
  • 20210916_203333.jpg
    20210916_203333.jpg
    141.9 KB · Views: 32

w1tw0lf

Senior Member
Joined
Sep 29, 2009
Messages
992
This also doesn't work. Says something about platform missing

I added the pics now from my phone. Hopefully it attached correctly

Your orange cable needs to move one pin to the right, it is in D2.

Change the code back to what you posted in https://mybroadband.co.za/forum/thr...ips-tricks-your-configs.1059800/post-28046758

Might be that your laptop isn't giving enough power... can also be that either the relay or the board is faulty. Your code and the cables seems to be correct. Just check that the pin specified in the code is the same pin the orange cable is connected to.
 
Last edited:

w1tw0lf

Senior Member
Joined
Sep 29, 2009
Messages
992
This also doesn't work. Says something about platform missing

I added the pics now from my phone. Hopefully it attached correctly

My D1 Mini Pro has 3.3v signal output on the GPIOs, I was powering my 5V Relay module obviously from 5V VIN.. Switched to 3.3v to match the signal voltage and voila!

I would say move blue and purple to the opposite side, where the 3v and gnd is. As per above, make sure pin and code as the same pin location.

From below, on one of the comments.
https://www.reddit.com/r/homeassistant/comments/hyof6u
 

MidnightZA

Expert Member
Joined
Mar 9, 2013
Messages
1,659
Your orange cable needs to move one pin to the right, it is in D2.

Change the code back to what you posted in https://mybroadband.co.za/forum/thr...ips-tricks-your-configs.1059800/post-28046758

Might be that your laptop isn't giving enough power... can also be that either the relay or the board is faulty. Your code and the cables seems to be correct. Just check that the pin specified in the code is the same pin the orange cable is connected to.

The orange cable is correctly placed as in my code. I was alternating the pins and code to see if anything changes.

The relay works, if I put inverted: true in the code then the relay opens and stays open.

I will test the 3V pin tomorrow.
 
Top