Hi there,
it turned out that my wifi relay cannot be controlled by GPIO but only by the serial port of the ESP8266. But I do not know how to set up an appropriate yaml file in ESPhome.
Please find a picture of the relay here: wifi relay
Although stated in the text the relay cannot be controlled by GPIO pin, only by serial port of the ESP8266. Does anyone know how this can be done with ESPhome?
I found the uart switch platform. Another internet source told about some hex numbers. I used these numbers in the uart switch platform, but it did not work. Please see the part of my yaml-file:
The comments on the amazon page (google trans from german)
Works - after intensive research on the net…
Here are a few tips:
Flash MicroPython on the ESP8266-01 and set up WiFi (everything is online)
Connection: NI- to ground, NI+ to 5V - Important: The relay is controlled internally via the serial interface and not via the ESP8266-01
The relay can be programmed in the WebRepl Shell as follows
>>> from machine import UART
>>> uart = UART(0, 9600)
>>> uart.init(9600, bits=8, parity=None, stop=1)
>>> uart.write(b"\xa0\x01\x00\xa1")
# Turn off the relay (blue LED goes off)
>>> uart.write(b"\xa0\x01\x01\xa2")
# Turn on the relay (blue LED is on)
Thanks, azdelivery did not provide any docs for this product. They sell a similar product with a documentation saying that the relay is triggered by GPIO0, but this is wrong.
Thanks again! I had the same problem (switch in HA fell back after 1 second) and I could solve it with your advice (optimistic: true). Really, there is more to it…puh!
But frankly speaking, I have an ever bigger problem. The relay does not work! The ESP8266 receives the signal to switch (led lights up in both ways, open and close). But the relay does not move.
I took a closer look to the relay board: Neither GPIO0 nor GPIO2 seem to be connected to the STC chip on the relay board. So - no wonder why there is no relay working. I tried to declare PIN8 (TXD) of the ESP as tx_pin in ESPHome, but this is not acceted by ESPhome. What to do now?
(Remarks: The line “rx_pin: 4” is not necessary. Moreover the entity “WIFI Relais AUS” is obsolete either, I will delete it also.)
Meanwhile I found a documentation of the relay-board I am using. It is manufactured by LC Technology (www.chinalctech.com). Product name is “LC 5V WIFI Relay Module, LC-WM-Relay-8266-5V”. You can buy it for example on www.icstation.com. Besides others the manual includes a picture of the printed circuit (see attached an extract with the eight contacts of the ESP8266 on the board):
It seems that both, GPIO0 and GPIO2, are not connected anyway. I wonder how the communication with the serial mcu is done.
The documentation of the relay-board describes the programming by a mobile phone app. But this is not what I want to do as I want to flash it with ESPhome.
Anyway, I have contacted az delivery. They promised to send me a new 1-relay-board which switches the relay by GPIO pin, not by serial port.
You are right! Makes no sense!
I modified the yaml-file, playing with the tx- and rx-pins according to the ESPhome manual:
“Please note that the naming of these two pins depends on the chosen perspective and can be ambiguous. For example, while the ESP might send (TX ) on pin A and receive (RX ) data on pin B, from the other device’s perspective these two pins are switched (i.e. it sends on pin B and receives on pin A). So you might need to try with the two pins switched if it doesn’t work immediately.”
Moreover I added this to my yaml-configuration file:
includes:
- my_custom_component.h
GPIO4 is the rx-pin of the ESP8266 and is connected with the rx-pin of the relay-board.
But finally: relay does not work. It’s a pity! I do not have any more ideas.
Hurray, it works!
Setting tx_pin to GPIO1 according to nickrout’s advice makes my wifi relay becoming alive.
This post is especially for nickrout who had infinite patience with my low skills and gave important advices! Thank you very much, nickrout! And thanks to all of you, who have contributed to this topic.
Hi,
I am writing to you, because I can see that you are busy with ESPHome.
I followed your advice and put HA in Docker on Raspi 4 (8GB).
ESPHome works, but for me it’s a mess, has nothing to do with Arduino and I don’t understand anything about it, I have to copy and read a lot…
My problem:
it doesn’t matter which way I want to connect a “device” (pump), it doesn’t matter if it’s “MOFSET” or “Relay”, it doesn’t work…
As a relay: I can’t turn it off
As a “mofset”: nothing happens…
In EasyESP, however, both work, also in Tasmota on the same pin.
In Arduino I type:
ON pin HIHG
Off pin LOW
but there is nothing in ESPHome, neither of “high” or “low”
I also tried “ALLWAYS OFF”, the relay still works…
Do you have any advice for me, where and what should I change?
surely it is insufficient translation (browser in Win11 PC, automatic translation)
Do you mean?
I should edit my question
I should insert my complete code.
("")
May I please know what you need all my code for? This is a general question, everything else in the code works except the pump connected to ESP (which is also switchable with Nextion Display)
GPI25 works as “out” and the relay seems to be “up” because as soon as it gets power it turns on. I would like to define it, as in the arduino, but in ESPHome this definition “if… high” cannot be found…
Everything else works:
DHT sends the data
Bluetooth tracker sends data
Nextion shows all data…
only the relay output does not work
----------- //// ---------
But what I don’t understand is:
in the description it says:
that relay should be defined as “switch”…
But normally switches are “input” not “output”… at least in arduino, or tasmota, or easyesp…
I assume that it has something to do with it… But I don’t have a direct switch… “Switching” is done in the browser, in HA, or on the display (“touch button”) or in the "Home Assistant App, and actually it should switch automatically, but until it works properly I can’t set it up for automation…