Recommendations for self-contained relay box?

I’ve been using the Raspberry Pi GPIO pins to control relays from homeassistant, and would like to do the same at other locations in my house. These are for things like electric strikes, a doorbell, opening/closing a garage door. Might be nice to switch AC, but then only if the box is nicely sealed with no exposed wires. Does anyone have recommendations for a nice self-contained product that can do this?

My ideal product would be something like an ESP32 (or other esphome device) inside a box with GPIO pins driving 4 optically-isolated relays, where I can connect the ESP32 via Ethernet and the relays all have nice breakout screw terminals. WiFi would be okay as my second choice, since few ESP32 dev boards seem to have Ethernet ports. I’d like this to be as compact as possible. I could presumably build something from an esphome dev board and relay board, but without a custom box this would be harder to make compact. Using a breadboard would be kind of clunky, too. I can solder wires, but don’t have access to a 3D printer and am not great at finding the right standoffs etc. to put together a nice box–generally the things I build myself are big and ugly–but maybe if there’s a DIY guide with a complete parts list I could follow it.

Thanks for any recommendations.

Within what region are you based as electrical supplies differ vastly.

In the United States.

@haweb I used this in my garage inside an enclosure to control IR beams:

LilyGo site:
http://www.lilygo.cn/prod_view.aspx?TypeId=50068&Id=1406&FId=t3:50068:3

My setup:

Thanks for the link. That looks like something that would do the job for me. What enclosure did you use, and what are the other two boards in there?

The enclosure was one of the many available on amazon (search for project enclosure). I picked it be just large enough to provide clearance around the boards and dust/water proof. The green board is just a set of 4 PC817 optocouplers that get 12v signals from the barriers and door contact and trigger a GPIO on the board (safer than using 3V and connecting directly to the esp32). The board with all the wires is just a quick and easy way to connect them all as needed using connectors so I can easily make repairs.

I’d recommend going to an electrical wholesale counter - where electricians buy their accessories - they always have a good range of electrical enclosures which can be IP-rated and also include glanded locknuts. Perhaps this is also an option for you?
image
image

I agree with @RonnieLast if you are going to be switching mains powered devices! The enclosure I picked is good for low voltage DC applications and likely not rated for AC applications (in terms of local electricity related regulations).

Just to follow up, I ended up going with the Sonoff 4CH Pro R3. It wasn’t too bad to set up. The only thing I needed to do was solder a 2.5mm header into the board, which was pretty easy. Then I used an $8 HiLetgo CP2102 USB 2.0 to TTL to flash esphome. I had to buy that one because my existing USB-serial converter only had a 5V output, not 3.3V.

The only two tricky things are that A) you have to turn it on while pressing button 1, and I didn’t see the buttons with the cover open, but the buttons are right there, and B) esphome doesn’t work with hidden SSIDs by default. Also, some guides say wire Tx to Tx, but actually you should cross and wire Tx on the USB-TTL device to Rx on the device and vice versa. I highly recommend this device. It works super well with homeassistant, which automatically discovered the device and just asked me to supply the api key. The only downside is that it requires WiFi and in an ideal world I would prefer wired Ethernet.

Here’s my esphome yaml configuration file (passwords and keys changed) for anyone else looking to do this. I’m using this to control electric strikes, so configure the buttons to open momentarily, or you can double-click to leave the latch open.

esphome:
  name: strikerelays

esp8266:
  board: esp8285

logger:

api:
  encryption:
    # Generate with: dd if=/dev/urandom bs=32 count=1 | base64
    key: "bj04XXEAmQzRkTTrmHEPUpCMrzt+c8/3+uAiFCFmCCc="

ota:
  # Generate with: pwgen -ys -1 16
  password: "s3'YfJ'>gZ}5&sA{"
  id: my_ota

wifi:
  networks:
  - ssid: "my SSID"
    password: "my password"
    hidden: true
  domain: .lan

# Configure so pressing button momentarily activates corresponding
# relay and double-clicking leaves relay on.

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Button 1"
    on_press:
      - switch.turn_on: "relay_1"
    on_release:
      - switch.turn_off: "relay_1"
    on_double_click:
      then:
      - delay: 200ms
      - switch.turn_on: "relay_1"
  - platform: gpio
    pin:
      number: GPIO9
      mode: INPUT_PULLUP
      inverted: True
    name: "Button 2"
    on_press:
      - switch.turn_on: "relay_2"
    on_release:
      - switch.turn_off: "relay_2"
    on_double_click:
      then:
      - delay: 200ms
      - switch.turn_on: "relay_2"
  - platform: gpio
    pin:
      number: GPIO10
      mode: INPUT_PULLUP
      inverted: True
    name: "Button 3"
    on_press:
      - switch.turn_on: "relay_3"
    on_release:
      - switch.turn_off: "relay_3"
    on_double_click:
      then:
      - delay: 200ms
      - switch.turn_on: "relay_3"
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: True
    name: "Button 4"
    on_press:
      - switch.turn_on: "relay_4"
    on_release:
      - switch.turn_off: "relay_4"
    on_double_click:
      then:
      - delay: 200ms
      - switch.turn_on: "relay_4"

  - platform: status
    name: "Sonoff 4CH Pro Status"

switch:
  - platform: gpio
    name: "Relay 1"
    pin: GPIO12
    id: "relay_1"
  - platform: gpio
    name: "Relay 2"
    pin: GPIO5
    id: "relay_2"
  - platform: gpio
    name: "Relay 3"
    pin: GPIO4
    id: "relay_3"
  - platform: gpio
    name: "Relay 4"
    pin: GPIO15
    id: "relay_4"
3 Likes