SOLVED - How to set up a relay on ESP32 with Domoticz MQTT ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
rw11lkx82
Normal user
Posts: 16
Joined: 04 Aug 2024, 13:01

SOLVED - How to set up a relay on ESP32 with Domoticz MQTT ?

#1 Post by rw11lkx82 » 04 Aug 2024, 13:29

Hello,

I followed this link https://espeasy.readthedocs.io/en/lates ... /P029.html to add a relay on my ESP8266 (except the switch part).
I also tried on ESP32. So here is the screenshot of my devices tab (in attachment).
devices tab screenshot
devices tab screenshot
Capture d’écran du 2024-08-04 13-05-49.png (33.25 KiB) Viewed 6256 times
I have a dummy switch in Domoticz with the idx 280. When I use it, I can see the values in ESP EASY (state and output) change from 1 to 0 (or 0 to 1).
So I think my MQTT link works. I also checked with MQTT explorer I have the messages IN and OUT with ON and OFF state.
Actually I have no rules.
Unfortunately, the physical relay switched 1 time and nothing else. It seems it took the value ON and refuses to toggle to OFF :evil:
When I disconnect the data wire from the relay, it toggles to OFF. When I connect the data wire again, it toggles to ON. :evil: :evil:
And I don't see where I made a mistake.

If anyone has an idea to help me... I am stucked with that for 2 days... :roll:
Thanks in advance !
Last edited by rw11lkx82 on 04 Aug 2024, 20:07, edited 1 time in total.
Using Domoticz for many years with Arduino boards, using MySensors and IP.
Trying to improve with ESP boards, ESPEASY and MQTT.

User avatar
Ath
Normal user
Posts: 4331
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#2 Post by Ath » 04 Aug 2024, 14:48

Do you have your relay powered from 5V? As the 3.3V high level of an ESP is too low to be detected as High for most 5V inputs. You can use a transistor or mosfet to switch the relay, (or use a level converter like TXS0108e (8 ports) or TXS0104e (4 ports) to translate the 3.3V to 5V signals).

Something similar to this: (it's showing a motor, but a relay should be the same)
transistor-relay.jpeg
transistor-relay.jpeg (8.17 KiB) Viewed 6253 times
The GPIO and GND connections go to the ESP, the VCC can be 5V.
/Ton (PayPal.me)

rw11lkx82
Normal user
Posts: 16
Joined: 04 Aug 2024, 13:01

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#3 Post by rw11lkx82 » 04 Aug 2024, 14:58

My relay is powered from 5V. I use an expansion board dedicated to ESP32. https://a.aliexpress.com/_EzOe951
Using Domoticz for many years with Arduino boards, using MySensors and IP.
Trying to improve with ESP boards, ESPEASY and MQTT.

User avatar
Ath
Normal user
Posts: 4331
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#4 Post by Ath » 04 Aug 2024, 15:21

But the expansion board doesn't provide any level conversion, so you'll have to include that yourself.

What relay board are you using? Or is it a simple relay, without any logic included, only? (then don't forget to add the fly-back diode to protect the electronics)
/Ton (PayPal.me)

rw11lkx82
Normal user
Posts: 16
Joined: 04 Aug 2024, 13:01

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#5 Post by rw11lkx82 » 04 Aug 2024, 15:35

I power the expansion board in 12V. And there is a conversion to 5V.
The relay is a board with electronics embbeded. It has diode to separate 5V from 230V.
Using Domoticz for many years with Arduino boards, using MySensors and IP.
Trying to improve with ESP boards, ESPEASY and MQTT.

rw11lkx82
Normal user
Posts: 16
Joined: 04 Aug 2024, 13:01

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#6 Post by rw11lkx82 » 04 Aug 2024, 15:48

Using Domoticz for many years with Arduino boards, using MySensors and IP.
Trying to improve with ESP boards, ESPEASY and MQTT.

User avatar
Ath
Normal user
Posts: 4331
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#7 Post by Ath » 04 Aug 2024, 16:37

Hmm, the board already has that transistor logic added, but it doesn't seem to work well with 3.3V input.

Have you tried to set the GPIO pin directly from the Tools page? That would be similar in switching it from Domoticz. You can then measure the actual voltage on the 'in' pin of the relay.

Code: Select all

gpio,23,1 // On?
gpio,23,0 // Off?
As an alternative you can temporarily power the relay board from 3.3V, to see if it works at all, but that might not be enough to switch the relay :?.
Lowering the 5V on the relay to ca. 4.5V may also make it work, as then the 3.3V GPIO signal should be able to trigger it.
/Ton (PayPal.me)

rw11lkx82
Normal user
Posts: 16
Joined: 04 Aug 2024, 13:01

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#8 Post by rw11lkx82 » 04 Aug 2024, 17:47

Send the command from the tools page does not change anything.

BUT using 3.3V WORKS !!! :D :shock: :shock:
I tried with an other relay (same family but maybe an other supplier) : it works with 5V.

I am impressed and warmly thank you !!!
How do you find it could be a voltage issue ???
I would never imagine that...
Using Domoticz for many years with Arduino boards, using MySensors and IP.
Trying to improve with ESP boards, ESPEASY and MQTT.

User avatar
Ath
Normal user
Posts: 4331
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to set up a relay on ESP32 with Domoticz MQTT ?

#9 Post by Ath » 04 Aug 2024, 19:33

rw11lkx82 wrote: 04 Aug 2024, 17:47 Send the command from the tools page does not change anything.

BUT using 3.3V WORKS !!! :D :shock: :shock:
I tried with an other relay (same family but maybe an other supplier) : it works with 5V.

I am impressed and warmly thank you !!!
How do you find it could be a voltage issue ???
I would never imagine that...
Well, usually, a digital input requires a signal above 0.6 to 0.7 * VCC to trigger the input as high/1, and below 0.4 to 0.3 * VCC as a low/0 signal. Because of that rather wide delta, some of these 5V powered devices see 3V as high, but others require 3.5V, but an ESP can't deliver that. I assume that is the case with your different manufactured boards.

If you intend to control multiple 5V relays from your ESP, I suggest to obtain some TXS0108 level converters like these: https://aliexpress.com/item/1005006582837051.html
/Ton (PayPal.me)

rw11lkx82
Normal user
Posts: 16
Joined: 04 Aug 2024, 13:01

Re: SOLVED - How to set up a relay on ESP32 with Domoticz MQTT ?

#10 Post by rw11lkx82 » 04 Aug 2024, 20:07

Congratulations and many many thanks !
Using Domoticz for many years with Arduino boards, using MySensors and IP.
Trying to improve with ESP boards, ESPEASY and MQTT.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 11 guests