I’m trying to work around the lack of an Unifi Access API by wiring an ESPHome to some of the terminals of the UA Hub. The hub expects push button types of devices on those terminals, for stuff like doorbells or motion sensors, so I went with this 2 channel relay.
That page says the trigger current is 5 mA.
I wired GPIO2 and GPIO32 to the IN terminals, and I’m providing 12v to the relay from a PoE → 12v adapter wired separately from the esp board. I’m using this config :
The board is an olimex esp32-poe (non iso), and it’s plugged directly into the UA Hub which provides connectivity and power over ethernet.
Now when I click the buttons in HA, I can see LEDs on that relay board turn on and then off. So presumably it is indeed seeing the signal.
But the relays never actually switch, for some reason.
I’ve tried moving those jumpers (to switch between high / low triggers) and when I do I can hear the relays move on startup, so the relays themselves aren’t stuck.
Any idea on what I might be doing wrong ? My first thought was those PINs might not be good for outputs, but since LEDs do light up on the relay board the pins are definitely doing something. The LEDs are unmarked of course, so I can’t be sure of what they mean but I assume they represent the signal IN terminal statuses.
The GPIO’s from the ESP send 3.3V when HIGH and something around 0V when LOW. Can you confirm you relays do actually toggle when you (manually) apply 3.3V on the trigger pins of the relay board?
Some relays request a minimum of 5V for the relay to be switched (while many are already accepting something like north of 2.5V as “HIGH” state).
In the typical relay module, the LED you see is in series with the LED in the opto-coupler. So, what’s left is the coil voltage. Since you said POE to 12V, can we assume that you bought the 12-V version of the relay module? Does the POE adapter provide enough current to power a relay?
Have you tried powering the module from a 12V power supply?
The image of the product shows aa SRD-12VDC-SL-C relay. According to the specifications, the 12V coil requires 37.5mA. Measure the 12V from the POE when you try to energize the relay.
I bought the one linked, there’s no actual choice available on that page but the title says 5V/12V/24V(12V) so I’m assuming it’s the 12v version. There’s also absolutely no labels on the board itself, so I suppose there’s a chance it’s not the 12v version.
The PoE → 12v is providing 2 amps. I do have my door connected to it as well but even if it was using the full amp it’s calling for, that should still be providing a full amp to the relay. But the lock isn’t actually drawing anything when I’m testing anyway, so the full 2 amps should be available to the relay.
I have not tried powering it from a power supply, because the PoE adapter is the only 12v thing I have to power it. But the motorized multipoint lock it’s also powering operates fine, so I’m confident the adapter is working well and providing more than enough power.
I haven’t tried applying 3.3V manually to the relay, I guess you mean just wire it directly to the esp 3.3v pin ?
Some relays request a minimum of 5V for the relay to be switched (while many are already accepting something like north of 2.5V as “HIGH” state).
If that is indeed the case, I’ll just have to buy another one. Do you have one to recommend that would work reliably with an esp’s outputs ? Doesn’t have to be high power rated, this is just to act as a push button for the 12v contacts of the UA Hub and there shouldn’t be any real current flowing through it.
Thanks
If the LED on the board lights, then the GPIO voltage is not a problem. All the GPIO signal does is to light an LED inside the optoIsolator which turns on the relay. As I said, the indicator LED is normally in series with the optoisolator, so if it lights all that remains is the power to the coil. The LED says nothing about the relay coil- only that the optoisolator is getting lit.
The voltage of the relay has nothing to do with the signal voltage. The optoisolator isolates the signal from the coil voltage.
The UA Hub is powering everything (over two PoE links, one for the esp and one for PoE → 12v for the relay + door), and is itself powered from a PoE switch over a single Ethernet cable so presumably they have to be, yes. Should I connect the GND of the esp to the - of the adapter to be sure, maybe ?
I thought because they were powered from the same source that wouldn’t be required, but indeed after connecting the GND pin of the esp to the DC - of the relay & door, it started working.
At the time I had two issues that appeared :
Rebooting the ESP would trigger both relays once (meaning my doorbell chime would ring and the front door would open … argh)
Triggering the multipoint lock motor would cut the PoE power off the hub for a second or two, which would in turn make the ESP reboot
I lowered the output times from 5 to 1s, and applying that also updated it to the latest esphome version and both issues seem to have gone away. I wonder if maybe the hub is running out of power, it’s only plugged into a PoE+ source so I may try getting it a PoE++ injector to be safe.
I’m going to try to do more tests soon and cut power in various ways to make sure the relays don’t trigger on boot, that’d be real bad.
GPIO5 and GPIO4 are the only safe GPIOs you can use to drive relays if you don’t want them to operate autonomously at boot. The rest will go high at boot briefly. I can’t help with the power question as I have never used POE.
Oh that’s interesting, haven’t heard it before, that’s not a lot of free gpio. Where can you find that info ? Is that for all ESP or specific to the esp32-poe from olimex ?
Thanks
for the “classic” esp32 (like your esp32-poe) you can consult:
for the esp82xx it would be:
Can’t back this. I’m using plenty of esp82xx’s (mainly d1 mini clones) and I have no problems driving relays on other pins than 4 and 5 (for example 12, 13, 14 to name a few)…
Any source/docs for this behauviour?
By default esphome will do a early_pin_init when the esp8266 platform is used:
early_pin_init (Optional, boolean): Specifies whether pins should be initialised as early as possible to known values. Recommended value is false where switches are involved, as these will toggle when updating the firmware or when restarting the device. Defaults to true.
Right that’s what I had looked at, 2 and 32 on that pinout are marked as OK for output so I went with these.
I also crossed reference with specific esp32-poe pinouts since I know the ethernet adapter uses quite a few pins, so I avoided those as well.
I’ve got a proper PoE++ adapter coming in this week so power the UA Hub, hopefully that’ll at least address the reboot issue. If that’s not what it is I’m out of ideas and I’ll probably just scrap the whole thing and wait for UI to finally release an access API, if that ever happens. Maybe I’ll buy a wireless chime for now, instead of trying to piggy back off the hub’s connection to the mechanical one.
If you have an oscilloscope available it would be nice to see the voltage drop that is causing the reboot. Maybe a large capacitor on the power lines would keep the ESP alive.
That’s a good idea, unfortunately I don’t own one. They’re not cheap either
I just installed the new PoE++ injector, and a quick test didn’t show any reboots, so it does look like it might have been a power supply issue. Or it’s a coincidence.
Thinking of it now 12v 1 amp should be 12 watts for the motor, plus 12 watts at idle for the rest, that’s 24 watts which is dangerously close to the PoE+ max. I haven’t found any mentions of it in the doc but it’s very possible that the hub decides to turn off attached PoE devices to protect itself when it gets close to the limit, plus I’m sure these ratings aren’t exact.
PoE++ is 60 watts, it should be way more than enough. I’ll keep triggering it from time to time today to make sure it’s stable, and I’m also going to add a contact sensor on that door, just to be extra sure nothing weird happens (or at least I’ll know immediately if it does).
As for the reboot triggering the relays, it hasn’t happened again since. I wonder if that was a bug in the ESPHome version I was using or something, seems weird that it just went away, or maybe it was a weird brownout issue.
So it’s been working perfectly since I changed the injector & updated esphome, so whatever the real cause was I’m not going to touch anything, all good now !
Thanks for the help