Page 1 of 1

ESP8266 - Relay switches, but shouldn't

Posted: 21 Feb 2024, 08:54
by nolimal.design
Hi,

a year ago I started a project here.
A few weeks ago I changed something.
I have tried many different rules and this current one is the best.
Unfortunately it switches where it shouldn't.

Let me explain:

- RelayHeat (GPIO-5) have only to switch, if the temperature TempWater is under FormalALL.

- RelayTime (GPIO-0) have to switch, between 22:00 and 06:00, to heat the Watertank in the Night.

- RelayTime2 (GPIO-14) have to switch, between 23:30 and 04:00, for an additional heater.

On the pictures you can't see it, but the RelayTime works fine. But not the other ones.

RelayHeat switches several times, but it shouldn't.

RelayTime2 switches in the time between 22:00 and 06:00, but it should switch constantly between 23:30 and 04:00.

My question is, can I change it in the Rules?

Code: Select all

On System#Boot do
 TimerSet,1,10
endon

On Rules#Timer=1 do
 TaskValueSet 4,1,([TempExtern#temperature]-24)
  TimerSet, 2,10
endon

On Rules#Timer=2 do
 TaskValueSet 5,1,([DAR#Dummy]*[DAR#Dummy])
 TimerSet,3,10
endon

On Rules#Timer=3 do
 TaskValueSet 6,1,(24+12.3-(0.67*[DAR#Dummy]*(1.4347+0.021*[DAR#Dummy]+247.9*0.000001*[DAR2#Dummy])))
 TimerSet,4,10
endon

On Rules#Timer=4 do
 if [FormelAll#Dummy]>[TempWater#temperature]
  gpio,5,0
 else
  gpio,5,1
 endif
 TimerSet,5,20
endon

on WiFi#Disconnected do
  TimerSet,5,20
endon

on WiFi#Connected do
  TimerSet,5,0
endon

On Rules#Timer=5 do
  Reboot
  TimerSet,1,10
endon

On Clock#Time=All,**:** do
 if %eventvalue2%>=06:00 and %eventvalue2%<=22:00
  gpio,0,1
 else
  gpio,0,0
 endif
endon

On Clock#Time=All,**:** do
 if %eventvalue2%>=04:00 and %eventvalue2%<=23:30
  gpio,14,1
 else
  gpio,14,0
 endif
endon
ESP - Log
13442: EVENT: Rules#Timer=1,1
13454: ACT : TaskValueSet 4,1,(7.9-24)
13460: ACT : TimerSet, 2,10
13585: Dummy: value 1: 48.8
13603: EVENT: FormelAll#Dummy=48.8
15247: DS : Temperature: 76.4 (28-ff-0a-c2-21-17-04-17 [DS18B20])
15262: EVENT: TempWater#temperature=76.4
23463: EVENT: Rules#Timer=2,1
23479: ACT : TaskValueSet 5,1,(-16.1*-16.1)
23486: ACT : TimerSet,3,10
23586: Dummy: value 1: 48.8
23599: EVENT: FormelAll#Dummy=48.8
25223: DS : Temperature: 7.9 (28-ff-54-99-21-17-04-6c [DS18B20])
25239: EVENT: TempExtern#temperature=7.9
25262: DS : Temperature: 76.4 (28-ff-0a-c2-21-17-04-17 [DS18B20])
25277: EVENT: TempWater#temperature=76.4
33520: EVENT: Rules#Timer=3,1
33538: ACT : TaskValueSet 6,1,(24+12.3-(0.67*-16.1*(1.4347+0.021*-16.1+247.9*0.000001*259.2)))
33546: ACT : TimerSet,4,10
33585: Dummy: value 1: 48.8
33602: EVENT: FormelAll#Dummy=48.8
34779: WD : Uptime 1 ConnectFailures 0 FreeMem 18712 WiFiStatus: WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
35250: DS : Temperature: 76.4 (28-ff-0a-c2-21-17-04-17 [DS18B20])
35264: EVENT: TempWater#temperature=76.4
36223: EVENT: Clock#Time=Wed,8:41
36234: ACT : gpio,0,1
36236: GPIO: port#0: set to 1
43578: EVENT: Rules#Timer=4,1
43600: ACT : gpio,5,1
43603: GPIO: port#5: set to 1
43606: ACT : TimerSet,5,20
43612: Dummy: value 1: 48.8
43626: EVENT: FormelAll#Dummy=48.8
45221: DS : Temperature: 7.9 (28-ff-54-99-21-17-04-6c [DS18B20])
45238: EVENT: TempExtern#temperature=7.9
45265: DS : Temperature: 76.4 (28-ff-0a-c2-21-17-04-17 [DS18B20])
45285: EVENT: TempWater#temperature=76.4
53585: Dummy: value 1: 48.8
53603: EVENT: FormelAll#Dummy=48.8
55249: DS : Temperature: 76.4 (28-ff-0a-c2-21-17-04-17 [DS18B20])
55263: EVENT: TempWater#temperature=76.4

Re: ESP8266 - Relay switches, but shouldn't

Posted: 21 Feb 2024, 16:33
by chromo23
When you have two of the same event blocks in rules only the first one will be processed.
Here the solution:

Code: Select all

On Clock#Time=All,**:** do
 if %eventvalue2%>=06:00 and %eventvalue2%<=22:00
  gpio,0,1
 else
  gpio,0,0
 endif
 if %eventvalue2%>=04:00 and %eventvalue2%<=23:30
  gpio,14,1
 else
  gpio,14,0
 endif
endon

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 09:31
by nolimal.design
I tried it. After an hour I could see that it was still making the same switches.
Then I wrote the event into my other ESP8266.
This is intended as a backup to switch off at a temperature of 85.
And it turns on perfectly.

Now the first ESP switches correct and reacts more smoothly.

In my case, is it better to put a LoopTimerSet in my Rules?

Like ...

Code: Select all

On System#Boot do
 LoopTimerSet,1,10
 LoopTimerSet,2,10
 LoopTimerSet,3,10
 LoopTimerSet,4,10
endon

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 10:21
by TD-er
Can you take a look at if the ESP board maybe reboots?
Some relay boards have a really bad power supply and relais draw quite a lot of power.

Also if you made the boards yourself, please make sure to have a diode over the relay in "opposite" direction to protect electronics controlling the relay as the coil will generate a high voltage when turned off.

Is there something else like a button which may also toggle the relay? Switching a relay may cause some magnetic flux which can trigger other signals close to it.

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 11:50
by nolimal.design
Can you take a look at if the ESP board maybe reboots?
Yes he did it a lot time since I have them.
And, what I think too, is that the Boards and Relais and DS18B20, working with 3.3 V.
I want to change it, but I can't find the time.
But I have a Power Supply, with 12V and 5V with around 80W or 120W.

Here is the Picture of the 8 CH Relais

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 13:09
by TD-er
OK, so the diodes are clearly visible. That's good.

If I'm not mistaken, this board has optocouplers to switch the relais.
So from the ESP it isn't anything other than switching LEDs.

Maybe you can power the relay board with 5V and I think you may need to change something where there is the green jumper on the picture.
That's likely a jumper to connect the high level of the LED in the optocoupler to the Vcc pin powering the relays.
As it is now, it will probably put > 3V3 on the GPIO pins connected to the ESP if you switch to 5V.
So I think (not 100% sure, please check for yourself) you need to remove the jumper and on the most right pin of those 3 pins you connect 5V.
And do not connect the jumper to the left 2 pins or else you may short stuff.

Since the relais do draw quite some power, it makes sense to also connect the GND of the 5V power supply to that GND pin of the 3 pins near that jumper.

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 18:05
by nolimal.design
I found this for the 8 CH Relais.
The associated jumper can be used to determine whether the relay switches at a high or low level.
High level = 5V is present at the switching input
Low level = ground is present at the switching input
and this
GND - Ground reference for the module
IN1 - Input to activate relay 1
IN2 - Input to activate relay 2
IN3 - Input to activate relay 3
IN4 - Input to activate relay 4
IN5 - Input to activate relay 5
IN6 - Input to activate relay 6
IN7 - Input to activate relay 7
IN8 - Input to activate relay 8
VCC - Power supply for the relay module


GND - Ground reference for the module
VCC - Power supply selection jumper
RY-VCC - Alternate power pin for the relay module
As I read this, I can change the power to 5.0 Volt, without change anything.

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 18:22
by TD-er
But what will then be the voltage on the "INx" pins when you don't have it connected to the ESP?

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 20:42
by nolimal.design
I have or I did!

IN1 - ESP.198 - RelaySafe - GPIO-0 (D3)
IN2 -
IN3 - ESP.198 - RelayTime - GPIO-14 (D5)
IN4 - ESP.197 - RelayHeat - GPIO-5 (D1)

Under the Tab - Hardware / GPIO boot states all are by default.

The picture was only for an example for the 5V input.

Sorry for the misunderstanding.

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 22:52
by TD-er
OK, and what are the voltages of those pins when you power the relay board with 5V and not having the ESP connected to those pins?
So the voltage between GND and IN1 for example.

Re: ESP8266 - Relay switches, but shouldn't

Posted: 22 Feb 2024, 23:22
by nolimal.design
Sorry again. I misunderstood your question.

I connected the Relay Board with 5V for a short time, and there are 2V between GND and INx.

I will try to change the Voltage to 5V on all Boards this Weekend.

Re: ESP8266 - Relay switches, but shouldn't

Posted: 23 Feb 2024, 18:29
by nolimal.design
Okay, I changed the voltage on all boards to 5V. Between GND and INx on the Relay Board, it's now 2,2V.
I removed the jumper and tried to switch a relay. But the ESP immediately switched off and rebooted.
With the jumper it works correctly.

I hope now, with the 5V, the ESPs will not reboot to much.

Thx