I am very new in this ESP/Tasmota-World and actually working on my first little project: converting a solar LED spot with PIR to become smart. As soon as the LED gets ON the little ESP shall send a message to HA so that the system knows it is on (and can initiate some action).
The Hardware works fine: I use a stepdown converter for the battery-power to 3.3V, an optopcoupler (3-5V) to read out if the Spot is ON and last but not least the tasmotized ESP-02S. All components are working.
The optocoupler-module has three pins at the “output”-side which are VCC, GND and OUT. If the “input”-side is ON, the OUT-Pin shows power, if the input-side is OFF Power the OUT-Pin shows 0V. I connected this OUT-Pin to GPIO14 on the ESP.
My issue: which component is to be assigned to the GPIO in Tasmota? I tried several options (Button, Switch etc.) but this results in nothing in best case, the crash of the ESP in the worst case!
Please have a friendly look at the circuit diagram. I can’t see an error in the hardware. So it must be a Tasmota issue.
Okay,
throughout the day I found out that the realization with Tasmota will overburden my simple mind …
I have already tasmotised a Tuya Power Plug and this was totally easy with Tasmota. But this project is to complicated for me.
So I tried ESPHome fairly successfully. I was able to migrate from Tasmot to ESPHome and I’m wondering that there is no Web-UI. But YAML-Scripting and Installing on the chip works fine.
After that the sensor was implemented inside HA, but the status is always OFF. As written in my opener:
if the “input”-side is ON, the OUT-Pin shows certain Voltage,
if the “input”-side is OFF, the OUT-Pin shows 0,00V
(Multimeter-measurement!).
So there might be just a little issue with the definition in the .yaml-file. I already tried “device_class: power” but this was not accepted by the installer.
That’s exactly - not!
The ESP-02S has no GPIO17. And I don’t need the real voltage. I just need to know if there is any voltage or not. So in my opinion this should just be a binary sensor with “YES” or “NO”.
Ok - got confused. So your issue is that the binary sensor is not turning on when you expect it to? For starters, you don’t need that second optocoupler. You can simply use a voltage divider to connect the output of the first device.
Also - why inverted: true? That would mean that the input is considered off when voltage is present and on when zero volts.
As you can see in the circuit diagram the optocoupler runs with 3.3V - so the voltage on the OUT-Pin/GPIO is lower (I haven’t measured yet with 3.3V, but i will tomorrow). I actually assume that the voltage is just a bit too low to be recognized by the Chip. What do you think about that?
Sorry, but I have to go to bed now - it’s very late over here.
I have measured 3.37V at OUT when the output is running on the primary circuit. This is battery power between 3.6V and 3.9V (depending on the load). Actually it was 3.8V.
When I put the output on the secondary circuit (stable 3.3V) I receive 3.16V at OUT.
So this should be enough for the ESP to recognize it.
BUT: I did the measurement on a model with identical devices. There might be an issue on the original devices. So I unfortunately have to deconstruct my masterpiece … but not now. I will do this in the evening.
You should have pretty close to VCC on output. For sure it’s recognized.
Output is obviously inverted.
I once did something similar. I brutally replaced the LED light by Esp01, leaving original li-ion battery, charging circuit, MCU and PIR untouched.
When motion was detected it powered Esp (instead of LED), which sent MQTT and went to deep sleep.
One of the three batteries was bad! She lost her load very quickly and so the voltage went down to under 3V - don’t ask me why the system was still working. I have been testing the batteries twice – except the bad one . Now I have a set of completely new batteries (NiMh) from an identical batch.
With these freshly loaded batteries I have measured the installation inside the lamp (not a test setup). I receive 4.21V in the primary circuit and 3,28V in the secondary circuit. The optocoupler sends 3,28V on the OUT-Pin if the input is OFF and 2,76V if the input is ON. The LED circuit is 2,92V (but that’s enough to switch the optocoupler). The actual sensor definition is:
There is something seriously wrong here. Should be 0 when ON.
If you really have that 3-5V input optocoupler wired to Esp without additional components between them, you have some damaged devices.
Feel free to post a photo.
Why not, Esp is fine down to ~2.8 voltages, maybe even lower.
Fortunately, the devices were so cheap that I bought several of them. I will install another optocoupler and another converter tomorrow. Those from my test setup seemed to work correctly.
Thanks very much so far. As soon as it works I will post complete instructions an photos here. I’m sure that everybody needs such a spot!!!