How to use Sonoff SV GPIO pins

Hi All, I am new to the home automation space and would like confirmation on how to use the exposed GPIO pins on a Sonoff SV flashed with Tasmota.

I want to use a sonoff sv to control my gate as well as determine whether the gate is open or closed. Controlling the gate appears to be straight forward using the sonoff in the dry contact configuration.

I am struggling to get the state(open/closed) of the gate reflected in Tasmota. The gate controller has a contact exposed which emits 2v when the gate is closed and 0v when open. I was hoping I could connect the contact and ground of the gate controller to the Signal and Ground pins of GPIO14 on the sonoff sv. However, after having tried this the 2v hitting the GPIO14 pin appears to cause the sonoff to perform a hard reset, losing all of the wifi configuration ect.

Is it possible to use a Sonoff SV GPIO pin to determine whether or not a high or low voltage is being emitted? if so what tasmota gpio pin configuration should be used (switch etc)

1 Like

Hi Warwick

I am not sure how to get the Sonoff SV to detect 2V and 0V but I setup something similar with the Sonoff SV using a reed switch to detect if a door was open or closed and then setup an automation to switch a light on and then off, you should quite easily be able to mount a reed switch to your gate in which case my example below should work.

Login to the Sonoff SV and go to Configuration --> Configure Other then set GPIO 14 sensor to switch 2 (oh and also make sure its set to Sonoff SV (3)

Then go back to Main Menu --> Console and type
switchmode1 0
switchmode2 2

The GND and GPIO14 pins are located on the row closest to the relay with the first pin on the left being GND and the last pin on the right being GPIO14 like below

image

Connect a reed switch up to that and it will switch from state on to state off when you open and close the reed switch, you can then setup an automation based on whether the switch is in the on or off position or let it display if the gate is open or closed.

Hope this helps.

@Jatho thank you for the detailed feedback.

I previously had a reed switch connected to the gate but had quite a bit of instability with it being out in the rain, so I was looking for alternatives. Given that I haven’t been able to get the sonoff sv to safely read the live wire input i am going to revert to the reed switch.

Have a quick read through Tasmota ADC Pin. I think you want to use the ADC pin (Not the digital GPIO) which is not available broken out on the Sonoff SV. This will allow you to read voltage in 1000 steps between 0-1V. You would need to use 2 resistors (Google: voltage divider circuit) to step down the 2v to a 1v max that the ESP8266 can measure on its ADC pin. This would also require careful soldering onto the ADC pin directly onto the 8266 chip

1 Like

Thanks @thombain

Given your response I think it would be easier to do the voltage check/analog input with a D1 mini instead of the sonoff sv.

I’ve noticed on my gate controller that there is also a led contact which emits 5v when the gate is open. I had thought of using a zener diode to reduce the input signal from 5v to 3.3v and connect that to one of the digital input gpio pins on the sonoff sv. I’m hoping that if I set the gpio as a switch in the tasmota configuration it will indicate if the gate is open or closed.
Any thoughts on whether or not the above is a viable solution?

What did you wind up doing with this project. I have something similar that I am trying to accomplish with determining if an LED is on.

Technically the right approach is to use an octocoupler to bridge the two circuits.

As I understand it the octocoupler is effectively a little led and photoresistor incorporated into a single component. Your controller/sonoff can then read the resistance of the photoresistor (in the sonoff case only on or off ) and determine the state of the would be led on the other circuit.

I’ve had issues getting it to work in practice. The tolerances of the octocoupler seem very particular. In one case I think I over exposed a octocoupler to excessive voltage and in another I suspect there wasn’t sufficient amperage to drive the led within the octocoupler to get the photoresistor to be considered off.

Let me know if you have any success

1 Like

Agree with @Warwick here. Use an opto coupler on the 2V/0V line.
If the SonOffSV and the Gate have a shared ground, then you may be able to use the 2V as a High signal as the SonOff SV uses 3.3V logic and technically 2V should be registered as a High signal, but this is a kludge at best and if there are spikes on that 2V line you have a fried ESP chip. A pull-up resistor may work here, with a smaller value protection resistor on the line so when it is 0 the Sonoff sees logic 0 and that means if it floats it would be logic high (pullup)

You may need a logic shifter to convert the 2V logic to 3.3V logic for the optocoupler, depending on the type.

I’d avoid any kind of Zener dioded on the line. That is asking for trouble. If you have 5V logic, use a logic shifter to convert it to 3V logic, but an LED output is not really going to give good results.

Can I use GPIO to send latching signal to control a latching type water valve?
The latching valve will require 9DC positive pulse to turn it on and negative pulse to turn it off.

1 Like