Directly controlling a relay from Home Assistant Blue - preferably via USB

I currently have (had) a very neat functioning number of automations using ESP8266’s (about 26 of them) but something has gone wrong with my network/wifi/ESP8266/MQTT/Tasmota. Not sure what.

(See here: Strange (Recent) Behavour with Tasmota - Reboots every 3 hours - #25 by Tamsy)

We have a gate about a mile away from our house, we cannot visibly see the gate from our house.

One of the critical automations I have been using for the last few years is that guests can send a text to a number, that gets picked up via webhook in Home Assistant, and it tells an ESP8266 to close a relay for 1 second (An automation repeats this every few seconds) that triggers a Garage-Door opener that causes the gate to open.

This has been a great success with our friends, and has a very high WAF.

With the ESP8266’s going haywire, this automation has stopped working.

I would like to be able to directly control the relay via USB from the Home Assistant Blue. I haven’t really found a way yet of having a USB connected relay be controlled via HASS while directly connected to Home Assistant Blue.

Thoughts?

Easy ways of pulling this off?

I found one of these things, they are inexpensive - I will give it a try:

Will just need to figure out how to get Home Assistant to talk to it and send a trigger message.

What kind of method did you find to control this thing directly from Home Assistant?

I am looking at ICSE012A USB relay board, it seems that except this old Python script

there’s nothing new inveneted (like MQTT).

I actually did not use it, as I found that an ETH-01 ESP32 running Tasmota was better for my use case.

I’ve got one of those USB relay things to help me control garage gates from HA.

To drive it, I put this bit of Python in HA at /config/bin/relay.py:

#!/usr/local/bin/python
#
# USB relay driver
#
# For this and similar:
#
# https://www.amazon.co.uk/dp/B07DJ549LX
#

import argparse
import time

import serial

# To operate, send the relay a 4-byte sequence:

ON=b'\xa0\x01\x01\xa2'
OFF=b'\xa0\x01\x00\xa1'

DEFAULT_DEV='/dev/ttyUSB1'

p = argparse.ArgumentParser()
p.add_argument('--device', '-d', type=str, help='Path to device', default=DEFAULT_DEV)
g=p.add_mutually_exclusive_group()
g.add_argument('--on', action='store_true', help='Switch on')
g.add_argument('--off', action='store_true', help='Switch off')
g.add_argument('--click', type=int, metavar='MILLIS', help='Switch on for MILLIS milliseconds')

args = p.parse_args()

dev = serial.Serial(args.device)

if args.on:
    dev.write(ON)
elif args.off:
    dev.write(OFF)
else:
    dev.write(ON)
    time.sleep(args.click/1000)
    dev.write(OFF)

Then I configure a shell_command service (in configuration.yaml):

shell_command:
  gate_trigger: /config/bin/relay.py --click 350

Now when an automation calls the shell_command.gate_trigger service, the relay closes for 350ms, then opens again.

2 Likes

Hi, new ha user here. Can you please share how you set this up?

thanks

I didn’t use the USB device - I used an ESP32 (ETH-01 Model) to trigger the relay.

Hardest part was finding and installing the specific firmware on this device as you need a very specific compiled version of Tasmota to make it work with the Ethernet Cable.

Using the jumpers on the board, I hooked it up to a 2 channel relay board - mostly because its what I have on hand. I don’t actually need the 2 channels.

Something like this:

I then hooked up USB power to “pretend” to be an CR2032 battery. This powers the garage door opener that triggers the gate.

Finally, I soldered wires to the garage door opener switch, so that the relay triggers the switch on the opener.

When you tell home assistant to open the gate, it closes the relay 10 times (1 second each) in a 30 second window to ensure that the signal reaches the gate.

I even did a further automation with Twilio so you can text a cell number and it tells Home Assistant to open the gate.

I had more detailed specifics of the plans, but I can’t find them at the moment.

1 Like

Thanks for the update. I was able to use bobs code. also calling relay.py --on or relay-py --off turns the relay on and off. Pretty cool.

1 Like