arendst/Tasmota

adding support for latching relay

Closed this issue · 20 comments

Hello,

I've added the wall switch device from the link below:
[https://ex-store.de/ESP8266-WiFi-Relay-V31]

It uses a latching type relay instead of a normal one. Therefore it needs a secondary output pin to reset the relay.

It would be great if you could add the code snippets to your repository. Maybe someone will use it and for me it becomes easier to follow your updates in future.

file sonoff.ino:

global variable:

uint16_t mqtt_cmnd_publish = 0; // ignore flag for publish command
.
.
uint8_t relay_pulse = 0;
.
.
#ifdef USE_MQTT_TLS

function void do_cmnd_power():

power ^= mask;
}
.
.
if (sysCfg.module == EXS_RELAY){
if (!(power & 0x01)){
power |= 0x02;
}
else power &= (0xFF ^ 0x02);
if (relay_pulse) power &= (0xFF ^ 0x03);
relay_pulse = 2;
}

.
.
setRelay(power);

function void stateloop():

if (!pulse_timer) do_cmnd_power(1, 0);
}
.
.
if (sysCfg.module == EXS_RELAY && relay_pulse){
relay_pulse--;
if (!relay_pulse)setRelay(power & (0xFF ^ 0x03));
}

.
.
if (blink_mask) {
.
.
.
power_now = (power & (0xFF ^ blink_mask)) | ((blink_power) ? blink_mask : 0);
.
.
if (sysCfg.module == EXS_RELAY){
if(!(power_now & 0x01)){power_now |= 0x02;
}
else power_now &= (0xFF ^ 0x02);
relay_pulse = 2;
}

.
.
setRelay(power_now);

file sonoff_template.h:

ELECTRODRAGON,
USER_TEST,
.
.
EXS_RELAY,
.
.
MAXMODULE };
.
.
0, 0
},
.
.
{ "EXS Relay", // latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31
GPIO_USER, // GPIO0 -Modul Pin 8
GPIO_USER, // GPIO01 UART0_TXD; GPIO1 -Modul Pin 2
GPIO_USER, // GPIO02 -Modul Pin 7
GPIO_USER, // GPIO03 Serial RXD and Optional sensor -Modul Pin 3
GPIO_USER, // GPIO04 Optional sensor -Modul Pin 10
GPIO_USER, // GPIO05 Optional sensor -Modul Pin 9
0, 0, 0, 0, 0, 0,
GPIO_REL2, // GPIO12 Relay1 ( 1 = Off)
GPIO_REL1, // GPIO13 Relay1 ( 1 = on)
GPIO_USER, // GPIO14 Optional sensor -Modul Pin 5
0, // GPIO15 not used
GPIO_USER // GPIO16 Optional sensor -Modul Pin 4
} // -Modul Pin 1 VCC 3V3; -Modul Pin 6 GND

.
.

Great, was looking for a wall socket mounted device.

Implemented in next release. Get me one!

Adjusted and implemented in version 3.9.15 just released. Give it a go and let me know if my changes did not break your functionality. I had to test using two leds....

Great! 👍

I've tested it, looks good.

Thanks to you

Hello Github people,

Right now I'm trying to implement a Tasmota ESP8266 smart relay device.
The problem which I face up right now is about how to drive a latching relay with tasmota.
I chose this issue to post because is more similar to my topic.
There is implemented a latching relay command in tasmota?
Attached is a simplified schematic how I want to drive the relay.
The Relay need to be driven with ~50ms pulse for each state trough 2 coils with a common point.

Relay model datasheet: Type 704 L

Best Regards
Rares

![Latching relay](https://user-images.githubusercontent.com/71347548/194311947-ac0fcdd7-16af-4048-ac5e-8fc379ea86a1
__dat_type 704 l_en_ag_2020-04-30.pdf
.PNG)

Did you try if the recently (version 12.1) added Tasmota support for bistable/latching relays is suitable? You can select the pulse length with SetOption45. Config relay pin as Relay_b.

Nope I dont use it, thanks.
I just Upgrade the Firmware and the relay_b looks oke, but only one output is working.
Should I group the relay GPIO somehow that Tasmota know is the same relay?
Attached is the current configuration.
In the second photo you will se the output only for one GPIO.
The Set pulse option is perfect :)

Rares

Capture
98d59486-596d-4ea4-9f32-2593fe04e1ea

Same channel number (dropdown to the right) cannot work, each occurrence of a component needs a separate number. I'm not aware of an option to suggest that it is really the same relay, but not having worked with bistable relays, I have no conclusive info on how to deal with this.

Here's an example of a device config with one bistable relay, and two Relay_b pins configured.
https://templates.blakadder.com/sonoff_THR320D
I'd guess that this works smoothly.

You need a gpio pair for every bistable relay called relay_b1 and relay_b2

I can confirm that @arendst solutions works,
Thanks guys, much appreciated.

363f66bf-68fc-4dc7-9b2b-572f221fe3ce
Tasmota_Bistable_Relay

Hello @arendst,
Is there any change to have multiple latching relays on same ESP Board ?
What should be needed for this configuration.
Attached I put the schematic with pinout for 4 relays and the configuration witch I run right now.
The configuration I run right now is done for my bench test(see picture), but in final revision will be as is in the pinout schematic (table from the schematic)
First relay works well after your recommendation from this post. But the second one doesn't work.

Thanks
Rares

50962fba-bbbc-444c-ac06-fef1caab279e
latch_relay_brd
ef6e0c96-eed2-4b6b-a68c-133830e8fb95

Latest tasmota supports a number of bistable relays. Every supported bistable relay needs to have a GND or Vcc connection and two coils (mostly using driver transistors) connected to two gpios configured in a pair as Relay_b1 and Relayb_2. The next relay would be connected to GPIOs called Relay_b3 and Relay_b4.

The default pulse length is set to 40 mS but can be changed online with command SetOption45

NOTE1: From the datasheet I see the coils need 240mA (12V / 50ohm) to be driven so you definitly need drivers to connect it to the ESP8266/ESP32 as they can only drive 10mA.

NOTE2: I just tried with three bistable dummies and they seem to work just fine:
image

I'm testing this with 4 led's connected to each relay_b1-4. I expect when I toggle 1 on led 1 will pulse and when i toggle 1 off led 2 will pulse. Same goes for toggle 2 on led 3 pulse / off led 4 pulse.

This is no the behavior I'm experiencing.
Toggle 1 on = led 1 and 4 pulse
toggle 1 off = led 2 and 4 pulse
Toggle 2 on = led 3 pulse
toggle 2 off = led 2 and 4 pulse

Is this behavior I'm experiencing they way it should be?

Use case is to use a h bridge motor controller to have generate positive pulse from relay_b1 and then a negative pulse from relay_b2, this does work as expected but then when adding relay_b3/4 things get messed up.

image

Your expectation is wrong.

On a "normal" relay power switch every configured relay is set to the state of the 32-bit power register to make sure Tasmota knows the state of every relay.

The same is true for bi-stable relays; every bistable relay is set to the position the 32-bit power register holds. So what you see exactly expresses the designed functionality.

So do not mis-use bi-stable relays control for H-bridge control.

so what is the best option, if i set them as normal relay then i would have two buttons used to control the on and the off functions.

I want to control a solenoid that requires a positive pulse to open and then a negative pulse to close. the h bridge motor controller can do that and requires 2 inputs.

@ahmaddxb you can use normal relays with a pulsetime to insure only a brief on pulse will occur. If you need to maintain a state of the solenoid the you can use rules to set a variable accordingly.
I admit that will not give you a virtual relay that represent the state of the solenoid.

Yes i did use pulse time before. I was hoping for a way to keep it all in tasmota but I guess I can make a single virtual switch in home assistant that can toggle each relay. Thanks both of you.

@ahmaddxb
Looking again on how bi-stable relays works, I don't see that a problem with your solenoid
What it does is repeating all states for all Power
so when toggling Power1 (=Relay_b1+Relay_b2) it also repeat the value of Power2 (if Power2 is off, it will pulse Relay_b3, if it's one it will pulse Relay_b4)
Which means that this Power2 (or your 2nd solenoid in your case) will just receive a pulse for the position it is already there

So it shouldn't be a problem

@barbudor
Yes, I already came to that conclusion after i thought about it and understood what was going on. Testing on the breadboard and seeing other led's start flashing just throw me off, I didnt know about the 32-bit power register. I assumed it was weird behavior and might cause me issues.