Rules in ESPeasy

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#101 Post by dr.zorg82 » 26 Apr 2023, 12:49

Thank you. for now I'll leave it as it is. I will watch

bidrohini
Normal user
Posts: 105
Joined: 03 Nov 2022, 16:24

Re: Rules in ESPeasy

#102 Post by bidrohini » 29 Apr 2023, 17:52

Here is the A to Z of interfacing DS18B20 with ESPEasy: https://espeasy.readthedocs.io/en/lates ... 18b20.html
You can also use DHT22 instead of DS18B20. Here is an ESPeasy based project: https://www.pcbway.com/project/sharepro ... e5a39.html

It features DHT22 and ESP8266.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#103 Post by dr.zorg82 » 30 Apr 2023, 17:41

Good afternoon. please see my rules.

Code: Select all

on Time#Initialized Do
  LoopTimerSet_ms,5,1000 //this is just for monitoring
Endon

On Rules#Timer=5 do
  TaskValueSet,11,1,[plugin#gpio#pinstate#13] // salt pump rotation speed
  TaskValueSet,9,1,[plugin#gpio#pinstate#17] //sound alarm (Buzzer)
Endon  

On up#gerkon Do
if %eventvalue1%=1
  GPIO,12,0 // osmos
  GPIO,26,0 //waterPump
  GPIO,16,0 // karat
  GPIO,13,0 // pump solt
  Endif
Endon

On down#gerkon Do
if %eventvalue1%=1
  GPIO,26,1
  TimerSet,1,1200 // delay to turn on karat
  Endif
Endon

On Rules#Timer=1 do 
   GPIO,16,1
   GPIO,12,1
   TimerSet,2,420 //  karat duration
   LoopTimerSet_ms,4,300
Endon

On Rules#Timer=2 do 
   GPIO,16,0
   GPIO,12,0
   GPIO,13,0
   TimerSet,4,0
Endon

On Rules#Timer=3 do
   If [var#4]=0
   PWM,17,500 //sound alarm (Buzzer)
   Let,4,1
   GPIO,16,0
   GPIO,12,0
   GPIO,13,0
   TimerSet,4,0
Endon

On stop#bottom=1 Do
  TimerSet,6,1
Endon

On stop#bottom=11 Do
   If [osmos#osmos]=0
 GPIO,12,1
 Elseif [osmos#osmos]=1
 GPIO,13,0
 GPIO,16,0
 GPIO,12,0
 TimerSet,4,0
 TimerSet,3,0
  Let,2,0
 Endif
  TimerSet,6,0
Endon

On Rules#Timer=6 Do
  If [var#4]=0 And [karat#State]=0 And [osmos#osmos]=0
  GPIO,16,1
  GPIO,12,1
  TimerSet,2,300 // karat duration
LoopTimerSet_ms,4,300
  Elseif [var#4]=0 And [karat#State]=1 Or [osmos#osmos]=1
 GPIO,13,0
 GPIO,16,0
 GPIO,12,0
 TimerSet,4,0
 TimerSet,3,0
  Let,2,0
  Endif
   If [var#4]=1 And [var#2]=1
  PWM,17,0
   Let,4,0
   Let,2,0
  Endif
  TimerSet,6,0
Endon

On Rules#Timer=4 do //salt pump operating mode
   If [garag#analog]< 3100.00 And [plugin#gpio#pinstate#13]<= 1010
   Let,1,[plugin#gpio#pinstate#13]+5
   PWM,13,[int#1]
 Elseif [garag#analog]> 3101.00 And [plugin#gpio#pinstate#13] >= 470 
   Let,1,[plugin#gpio#pinstate#13]-5
   PWM,13,[int#1]
 Endif
 If [garag#analog]< 2400.00 And [var#2] = 0
  TimerSet,3,45
  Let,2,1
 Elseif [garag#analog]>= 2400.00
  TimerSet,3,0
  Let,2,0
 Endif
Endon

2023-04-30_18h20_55.png
2023-04-30_18h20_55.png (52.89 KiB) Viewed 5207 times
it should be like this:
if down#gerkon=1, then GPIO 26 is turned on and with a time delay of 20 minutes, GPIO 12 and GPIO 16 are turned on. then after 420 seconds 12 and 16 turn off. and so on when up#gerkon=1 GPIO 26 turns off and just in case they turn off again 12, 13, 16.
stop#bottom operation is a separate story and no problems have been noticed so far.
but in fact what happens is that when the karat is turned off after 420 seconds, GPIO 26 is also turned off. please tell me why is this happening?
in the log, at the moment when timer 2 should fire, there is a failed fatch
however, this does not always happen. sometimes the rules work as they should

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#104 Post by dr.zorg82 » 01 May 2023, 08:38

Is it possible that the unstable operation of the module is related to the use of gpio 5 and 12?
although there were never any problems loading the module.
now I tried several times to emulate the problem, but the module worked correctly.

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#105 Post by TD-er » 01 May 2023, 10:54

GPIO-12 should not be a problem on ESP8266.
GPIO-5 is by default assigned to be part of the I2C pins on ESP8266, but if you set those to use another pin (or no pin when I2C is not needed) then GPIO-5 is one of the most problem-free pins you can use on ESP8266.
See: https://espeasy.readthedocs.io/en/lates ... on-esp8266

For ESP32 it is a completely different story with those specific pins.
Using GPIO12 might even destroy your ESP board as the state of pin 12 during boot determines the voltage applied to the flash chip.
See: https://espeasy.readthedocs.io/en/lates ... e-on-esp32

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#106 Post by dr.zorg82 » 01 May 2023, 11:11

TD-er wrote: 01 May 2023, 10:54 For ESP32 it is a completely different story
I forgot to say that I have exactly ESP32. but there is no problem with booting the module. that is, I turn on the module, it booting and waits for one of the conditions of the rules to come. the module fulfills the initial rules well, for example, when the down#gerkon= 1 or stop#bottom=1. but at the moment when timer 2 should be activated, there are failures and the module disconnects all GPIOs

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#107 Post by TD-er » 01 May 2023, 12:12

I now see you have a switch input on GPIO-12.
Please do NOT!! use that pin as an input which can be at a specific state during boot of the ESP.
As I said, the state of this pin does determine the voltage of the flash chip.

So either it is pulled high or low by the board or module manufacturer to match the used flash chip.
If the state during boot of the ESP is wrong, either the flash chip will be unstable as it is supplied with a voltage lower than required, or it will be fried as you would apply a voltage which is too high.

GPIO 16 and 17 are a bit tricky also, as on some boards these may be connected to PSRAM, which is on the same SPI bus as the flash.
By toggling those pins you may activate the PSRAM chip and thus interact with the flash chip signals.
So if you have an ESP32 with PSRAM, then please don't use GPIO 16 and 17.
This is also explained in the docs I linked.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#108 Post by dr.zorg82 » 01 May 2023, 13:46

ок. Thank you! I'll try to change 12.16 and 17

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#109 Post by dr.zorg82 » 08 May 2023, 08:52

TD-er wrote: 01 May 2023, 12:12 Please do NOT!! use
it still crashes. changed all specific pins, but did not help. please tell me what could be the problem?
Screenshot_2023-05-08-09-51-22-92.jpg
Screenshot_2023-05-08-09-51-22-92.jpg (232.82 KiB) Viewed 5062 times
Screenshot_2023-05-08-09-52-13-86.jpg
Screenshot_2023-05-08-09-52-13-86.jpg (126.61 KiB) Viewed 5062 times

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#110 Post by dr.zorg82 » 08 May 2023, 09:41

could it be due to multiple concurrent tasks? Maybe needed to optimize the rules?

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#111 Post by TD-er » 08 May 2023, 09:57

I didn't remember you mentioning the unit actualy crashed, so I read back to the last thing you mentioned:
dr.zorg82 wrote: 01 May 2023, 11:11 [...]
the module fulfills the initial rules well, for example, when the down#gerkon= 1 or stop#bottom=1. but at the moment when timer 2 should be activated, there are failures and the module disconnects all GPIOs
What do you mean by "disconnects all GPIOs" ?
Does the unit reboot? Or is it completely unresponsive?

How are things wired to the ESP?
Could it be that at some point there is some much higher voltage at some pin?

Can you draw a schematic of how things are wired?
Also, is the GND of the ESP the same as on the things you connect to it? Is GND always connected (for example are external switches switching the GND or the other end) ?

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#112 Post by dr.zorg82 » 09 May 2023, 12:55

IMG_20230509_133519.jpg
IMG_20230509_133519.jpg (3.65 MiB) Viewed 5018 times
schematically depicted only one area, since GPIOs 13,18,19,21,26,32 are the same
TD-er wrote: 08 May 2023, 09:57 What do you mean by "disconnects all GPIOs" ?
Does the unit reboot? Or is it completely unresponsive?
good day. that is, switches the state GPIOs 13,19,21 and 26 from 1 to 0, although according to rules GPIO 26 it should be 1. whether the module is reboot or not, I cannot say, since this situation is not permanent. Now I tried several times to reproduce this error, but the module worked as it should. What is the reason for the failure of the module, I can not understand.

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#113 Post by TD-er » 09 May 2023, 13:04

Are you still using the same rules as you posted on the 30th of April ?
If not, can you post the updated rules, so we can be sure we're looking at the same rules.

Also I have to check online what the FET will do when it is turned on/off.
Maybe the resistor between the GPIO pin and the gate is too low, so the FET may pull the state to GND?

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#114 Post by dr.zorg82 » 09 May 2023, 13:34

TD-er wrote: 09 May 2023, 13:04 Are you still using the same rules as you posted on the 30th of April ?
The rules are the same, only the GPIOs numbers have changed. but just in case

Code: Select all

on Time#Initialized Do
  LoopTimerSet_ms,5,1000
Endon

On Rules#Timer=5 do
  TaskValueSet,11,1,[plugin#gpio#pinstate#13]
  TaskValueSet,9,1,[plugin#gpio#pinstate#18]
Endon  

On up#gerkon Do
if %eventvalue1%=1
  GPIO,21,0 // осмос
  GPIO,26,0
  GPIO,19,0 // карат
  GPIO,13,0 // нас соль
  TimerSet,4,0
  Endif
Endon

On down#gerkon Do
if %eventvalue1%=1
  GPIO,26,1
  TimerSet,1,1200 
  Endif
Endon

On Rules#Timer=1 do 
   GPIO,19,1
   GPIO,21,1
   TimerSet,2,480 // вр раб карат
   LoopTimerSet_ms,4,300
Endon

On Rules#Timer=2 do 
   GPIO,19,0
   GPIO,21,0
   GPIO,13,0
   TimerSet,4,0
Endon

On Rules#Timer=3 do
   If [var#4]=0
   PWM,18,500
   Let,4,1
   GPIO,19,0
   GPIO,21,0
   GPIO,13,0
   TimerSet,4,0
Endon

On stop#bottom=1 Do
  TimerSet,6,1
Endon

On stop#bottom=11 Do
   If [osmos#osmos]=0
 GPIO,21,1
 Elseif [osmos#osmos]=1
 GPIO,13,0
 GPIO,19,0
 GPIO,21,0
 TimerSet,4,0
 TimerSet,3,0
  Let,2,0
 Endif
  TimerSet,6,0
Endon

On Rules#Timer=6 Do
  If [var#4]=0 And [karat#State]=0 And [osmos#osmos]=0
  GPIO,19,1
  GPIO,21,1
  TimerSet,2,300 // вр раб карат
LoopTimerSet_ms,4,300
  Elseif [var#4]=0 And [karat#State]=1 Or [osmos#osmos]=1
 GPIO,13,0
 GPIO,19,0
 GPIO,21,0
 TimerSet,4,0
 TimerSet,3,0
  Let,2,0
  Endif
   If [var#4]=1 And [var#2]=1
  PWM,18,0
   Let,4,0
   Let,2,0
  Endif
  TimerSet,6,0
Endon

On Rules#Timer=4 do 
   If [garag#analog]< 3100.00 And [plugin#gpio#pinstate#13]<= 1010
   Let,1,[plugin#gpio#pinstate#13]+5
   PWM,13,[int#1]
 Elseif [garag#analog]> 3101.00 And [plugin#gpio#pinstate#13] >= 450 
   Let,1,[plugin#gpio#pinstate#13]-8
   PWM,13,[int#1]
 Endif
 If [garag#analog]< 2400.00 And [var#2] = 0
  TimerSet,3,45
  Let,2,1
 Elseif [garag#analog]>= 2401.00
  TimerSet,3,0
  Let,2,0
 Endif
Endon

on temp#boiler do 
  if %eventvalue1% <=67.0
    GPIO,32,1
  endif
   if %eventvalue1% >=68.0
    GPIO,32,0
  endif  
Endon
TD-er wrote: 09 May 2023, 13:04 Maybe the resistor between the GPIO pin and the gate is too low, so the FET may pull the state to GND?
Don't know. took a typical wiring schematic :oops:

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#115 Post by TD-er » 09 May 2023, 14:04

I see the pins you mentioned are all set to 0 when this event happens:

up#gerkon=1

Is it possible that this pin received some noise which shortly may alter its logic state?
For example long cables, not strong enough pull-up resistor, no small capacitor (100 nF) over the GPIO pin and GND?

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#116 Post by dr.zorg82 » 09 May 2023, 14:29

TD-er wrote: 09 May 2023, 14:04 I see the pins you mentioned are all set to 0 when this event happens:

up#gerkon=1
It seems to me that this is not connected, since the cable is only 1.5 meters long and the failure occurs exactly at the moment when 19.13 and 21 should turn 0 (at the moment when timer 2 should be activated). that is, if the problem was in the noise (for example, the length of the cable), then the problem would appear at different times.
now I asked the electronics about connecting the mosfet, maybe they will tell something.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#117 Post by dr.zorg82 » 10 May 2023, 09:19

electronics say that this is possible because of the mosfet, but this is unlikely. All the same, I will change the mosfets to others and I will observe.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#118 Post by dr.zorg82 » 18 May 2023, 09:43

Good afternoon. there is such a code.

Code: Select all

on Time#Initialized do
If %systm_hm_0% <= 22:00 And %systm_hm_0% >= 01:00
  gpio,33,1
  gpio,12,1
else
  gpio,33,0
endif
If %systm_hm_0% >= 01:00 And %systm_hm_0% <= 01:25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif
If %systm_hm_0% >= 06:00 And %systm_hm_0% <= 06:25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif
If %systm_hm_0% >= 11:00 And %systm_hm_0% <= 11:25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif
If %systm_hm_0% >= 16:00 And %systm_hm_0% <= 16:25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif
If %systm_hm_0% >= 21:00 And %systm_hm_0% <= 21:25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif
TimerSet,8,90
LoopTimerSet_ms,9,10000
endon

On Clock#Time=All,22:00 do //выкл. насос
If [boiler#boiler] =1
  gpio,33,1
else
  gpio,33,0
Endif
endon

On Clock#Time=All,01:00 do // вкл. нас
  gpio,33,1
endon

on Clock#Time=All,01:00 do
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
endon

on Clock#Time=All,01:25 do
  GPIO,27,0
  TimerSet,4,0
endon

on Clock#Time=All,06:00 do
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
endon

on Clock#Time=All,06:25 do
  GPIO,27,0
  TimerSet,4,0
endon

on Clock#Time=All,11:00 do
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
 endon

on Clock#Time=All,11:25 do
  GPIO,27,0
  TimerSet,4,0
endon

on Clock#Time=All,16:00 do
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
endon

on Clock#Time=All,16:25 do
  GPIO,27,0
  TimerSet,4,0
endon

on Clock#Time=All,21:00 do
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
endon

on Clock#Time=All,21:25 do
  GPIO,27,0
  TimerSet,4,0
endon
that is, the same action is performed five times a day. Is it possible to somehow optimize the code so that it is shorter?

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#119 Post by TD-er » 18 May 2023, 10:49

You can shorten this in a number of ways.

One way can be to simply use LongPulse for those 25-minute pulses, but then timer 4 will not be cleared.
You don't seem to use this timer, unless this isn't the complete rules set.

Another way can be to use some feature I fixed quite recently.
That is to use variables in the "on Clock#Time=All,01:00 do" line.
This way you only need to set "the next" time in variables.

Another not really generic way, but quite suitable for this timing schema is to simply compare hours and minutes.

For example:

Code: Select all

If %systm_hm_0% >= 06:00 And %systm_hm_0% <= 06:25
Can also be seen as something like this:

Code: Select all

if %syshour% = 6 and %sysmin% <= 25
So a large chunk of your Time#Initialized block can be reduced to something like this:

Code: Select all

if (%syshour% = 1 or %syshour% = 6 or %syshour% = 11 or %syshour% = 16 or %syshour% = 21) and %sysmin% <= 25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif
The same can be done for these blocks:

Code: Select all

on Clock#Time=All,01:00 do
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
endon

on Clock#Time=All,01:25 do
  GPIO,27,0
  TimerSet,4,0
endon
(and all similar other blocks)

into this:

Code: Select all

on Clock#Time=All,**:00 do
  if (%syshour% = 1 or %syshour% = 6 or %syshour% = 11 or %syshour% = 16 or %syshour% = 21)
	  GPIO,27,1
	  TimerSet_ms,1,2500
	  TimerSet,3,60
  endif
endon

on Clock#Time=All,**:25 do
  if (%syshour% = 1 or %syshour% = 6 or %syshour% = 11 or %syshour% = 16 or %syshour% = 21)
    GPIO,27,0
    TimerSet,4,0
  endif
endon

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#120 Post by dr.zorg82 » 19 May 2023, 08:26

TD-er wrote: 18 May 2023, 10:49

into this:
THANKS FOR THE HELP
almost 1000 characters shorter :)
and if I want to do this action 6 times a day, can I add one more hour? What is the data limit?
for example is it possible?

Code: Select all

if (%syshour% = 1 or %syshour% = 6 or %syshour% = 11 or %syshour% = 16 or %syshour% = 21 or %syshour% = 23) and %sysmin% <= 25
  GPIO,27,1
  TimerSet_ms,1,2500
  TimerSet,3,60
else
  gpio,27,0
endif

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#121 Post by TD-er » 19 May 2023, 10:23

Not sure what is the limit, if there is one.
But you can easily split it into if...elseif...else...endif
See: https://espeasy.readthedocs.io/en/lates ... lseif-else

Keep in mind that nesting if's is essentially the same as an "AND".

Code: Select all

if A=0 and B=0
 ...
endif
Is the same as:

Code: Select all

if A=0 
  if B=0
    ...
  endif
endif
Thus you can wrap it all in a single check for "if %sysmin%<=25"
For readablility you may need to write the "gpio,27,0" twice then, but you'll find out if it comes to splitting the OR's :)

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#122 Post by dr.zorg82 » 21 Jun 2023, 19:39

Good afternoon . maybe it will be useful and interesting for someone.
here I asked a question about the work of the rules and could not understand why they do not work
it was all about writing the rules, more precisely the use of spaces and = and>/<
it was

Code: Select all

On Rules#Timer=4 do //salt pump operating mode
   If [garag#analog]< 3100.00 And [plugin#gpio#pinstate#13]<= 1010
   Let,1,[plugin#gpio#pinstate#13]+5
   PWM,13,[int#1]
 Elseif [garag#analog]> 3101.00 And [plugin#gpio#pinstate#13] >= 470 
   Let,1,[plugin#gpio#pinstate#13]-5
   PWM,13,[int#1]
 Endif
 If [garag#analog]< 2400.00 And [var#2] = 0
  TimerSet,3,45
  Let,2,1
 Elseif [garag#analog]>= 2400.00
  TimerSet,3,0
  Let,2,0
 Endif
Endon
this is how it became

Code: Select all

On Rules#Timer=4 Do
   If [garag#analog] <=3200.00 And [plugin#gpio#pinstate#13] <=1010
   Let,1,[plugin#gpio#pinstate#13]+5
   PWM,13,[int#1]
 Elseif [garag#analog] >= 3201.00 And [plugin#gpio#pinstate#13] >=350 
   Let,1,[plugin#gpio#pinstate#13]-9
   PWM,13,[int#1]
 Endif
 If [garag#analog] <=2400.00 And [var#2] =0
  TimerSet,3,45
  Let,2,1
 Elseif [garag#analog] >=2401.00
  TimerSet,3,0
  Let,2,0
 Endif
Endon
everything works now
and of course removed GPIOs 12, 5 from work

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#123 Post by dr.zorg82 » 28 Jul 2023, 10:20

Good afternoon. Is there a difference in coding between the two rules?

Code: Select all

on Clock#Time=All,**:** do
  if [int#9] = 0
    if %sysmin% >= 01 
      asyncevent,startDisinfection
    endif
  endif
endon

Code: Select all

on Clock#Time=All,**:** do
  if [int#9] = 0 AND %sysmin% >= 01 
      asyncevent,startDisinfection
  endif
endon

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#124 Post by TD-er » 28 Jul 2023, 10:52

There should not be a difference.

However when comparing numericals like "> 01" in your rules, it is best not to have a leading zero.

The number parsing in ESPEasy is done using a more elaborate function which will not consider octal numbering.
But I'm not 100% sure all compares use this function, so there might be some piece of code which can consider a leading 0 as an octal number.
For "01" this does not make any difference, but for values > 7 it might yield strange results.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#125 Post by dr.zorg82 » 28 Jul 2023, 11:03

TD-er wrote: 28 Jul 2023, 10:52 There should not be a difference.

However when comparing numericals like "> 01" in your rules, it is best not to have a leading zero.

The number parsing in ESPEasy is done using a more elaborate function which will not consider octal numbering.
But I'm not 100% sure all compares use this function, so there might be some piece of code which can consider a leading 0 as an octal number.
For "01" this does not make any difference, but for values > 7 it might yield strange results.
thank you

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#126 Post by dr.zorg82 » 14 Sep 2023, 08:59

Good afternoon. I'm trying to change the speed of an AC motor to 220 volts. I connect via a triac according to this scheme
Безымянный.png
Безымянный.png (76.2 KiB) Viewed 4030 times
I'm writing a simple rule

Code: Select all

On bot#State=1 Do
PWM,27,1
Endon
and the motor rotates at maximum speed. that is, the rotation speed is always maximum, regardless of the PWM value. at least like that PWM,27,1. at least like that PWM,27,1000.
if the PWM,27,0. then the motor does not rotate
please tell me what could be the problem

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#127 Post by TD-er » 14 Sep 2023, 09:31

Typically a triac only opens at the zero-crossing of the AC voltage.
So you may have to alter the PWM frequency.

However, I don't know whether the PWM pulse should also be somehow synced with the mains frequency as it may otherwise cause unpredictable behavior.

I really doubt this will work well and I don't know what would be a good PWM frequency for this.

Seems like you have taken the schematic from this site:
https://circuitdigest.com/microcontroll ... -and-triac
Here they also suggest to sample the AC frequency.
And ESPEasy is probably not fast enough to respond to this using rules.

One other thing to realize...
They do have the mains voltage parts on separate prints, but they have drawn it as if it were mounted to a breadboard.
Don't ever use a breadboard for mains voltage.

Also the experimental board they used isn't really suited for mains voltage without taking special care of removing copper.
Each hole of such a board does have a copper 'island', each with a distance of less than 3 mm from eachother.
This allows for sparks when switching mains voltage.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#128 Post by dr.zorg82 » 14 Sep 2023, 09:45

TD-er wrote: 14 Sep 2023, 09:31 ESPEasy is probably not fast enough to respond to this using rules
that is, I won’t be able to change the rotation speed?
What options are there to solve my problem?
The diagram was taken from the Internet, I had a ready-made board, but it was similar to the one I showed. there was a processor MEGA (I don’t remember the number). I decided to remove it and put ESP32 in its place

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#129 Post by TD-er » 14 Sep 2023, 10:56

Those ATmega microprocessors don't do anything else.

So their loop() call is really simple and something like this:

- Read potentiometer value + compute delay
- Wait for zero-crossing
- pull pin high
- Wait for computed 'delay' number of msec
- pull pin low.

Since that's all they need to do, I would wire up that microcontroller again and just try to 'emulate' the potentiometer.
That's just a DC analog value, which can be easily generated via ESPEasy.
Either via one of the ESP32 DAC pins, or send a PWM signal and add some resistor + capacitor to make the value more stable.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#130 Post by dr.zorg82 » 14 Sep 2023, 13:29

This is a sliding gate drive. It's fully functional, but I wanted to control the gate via the Internet. Therefore, I decided to change the standard microprocessor to ESP32. It is necessary to regulate the rotation speed of the motor so that the gate does not hit the gate trap. that is, the speed must be reduced before stopping.

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#131 Post by TD-er » 14 Sep 2023, 15:52

Since the ESP32 is doing so much more, it is not the best choice for truly real-time tasks.
It is best to have a small microcontroller responsible for the really tight loop you need to control the motor speed.
This leaves only a slowly changing input option which can be controlled by the ESP.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#132 Post by dr.zorg82 » 24 Sep 2023, 11:56

TD-er wrote: 14 Sep 2023, 10:56 again and just try to 'emulate' the potentiometer.
That's just a DC analog value, which can be easily generated via ESPEasy.
Either via one of the ESP32 DAC pins, or send a PWM signal and add some resistor + capacitor to make the value more stable.
please tell me how to remove the potentiometer in this circuit and put ESP32 in its place
2023-09-24_12h48_54.png
2023-09-24_12h48_54.png (73.46 KiB) Viewed 3804 times
all that comes to my mind is to install an optocoupler instead of a potentiometer, and apply a PWM signal to the optocoupler input. but not sure if it will work
2023-09-24_12h48_54.png
2023-09-24_12h48_54.png (73.55 KiB) Viewed 3804 times

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#133 Post by TD-er » 24 Sep 2023, 12:20

To control it purely digital, you need to detect the zero crossing.
But maybe you can exchange the potentiometer with some LDR and add a PWM controlled LED in front of the LDR and put it in a black tube to keep out other light?
Got the idea of using an LDR via Google image search which led me here: https://www.eleccircuit.com/ac-lights-dimmer-circuit/
Section "The automatic Daylight dimmer circuit"

Maybe you need some small capacitor across the LDR if it may change too quickly.
I have no idea how fast an LDR may respond to light changes, but PWM is pulsating light.
Or just put a small capacitor over the LED.

Edit:
Found an even better blog post describing what you want to achieve.
http://jespereklund.blogspot.com/2012/1 ... duino.html

But maybe whenever you have questions like these, it is better to open a new topic next time.
As this doesn't have much to do with ESPEasy rules.

Edit2:
Here some more info on LDRs: http://lednique.com/opto-isolators-2/li ... 20darkness.

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#134 Post by dr.zorg82 » 24 Sep 2023, 13:49

I also thought about LDR when I wrote the previous question. Thank you. And I apologize for the off-topic questions.
Maybe it's worth creating a topic about one-time questions

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#135 Post by dr.zorg82 » 03 Nov 2023, 19:45

Good afternoon. I have sliding gates. I need the gate to start moving smoothly and end moving smoothly.there is a pulse counter on the motor. and everything is fine when the gate moves from start to finish, that is, the gate starts moving smoothly and slows down before stopping.but if you stop the gate manually and start moving again, the gate will move in the other direction, and the pulse counter will continue to count pulses and there will be no reduction in speed before stopping.

Code: Select all

On Rules#Timer=1 Do
    If [datchik#Total] <=4999 And [plugin#gpio#pinstate#19] <=900 
 Let,3,[plugin#gpio#pinstate#19]+50
 PWM,19,[int#3]
   Elseif [datchik#Total] >=5000 And [plugin#gpio#pinstate#19] >=150
 Let,3,[plugin#gpio#pinstate#19]-15
  PWM,19,[int#3]
   Endif
Endon
2023-11-03_21h31_51.png
2023-11-03_21h31_51.png (49.45 KiB) Viewed 3389 times
that is, with each increase in datchik#Total need to subtract odd numbers from the datchik#Total.
please tell me how to teach the gate to stop smoothly in the extreme position from any initial position

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#136 Post by dr.zorg82 » 05 Nov 2023, 08:41

did it differently

Code: Select all

On Rules#Timer=1 Do
    If [datchik#Total]<=4999 And [plugin#gpio#pinstate#19]<=900 
 Let,3,[plugin#gpio#pinstate#19]+50
 PWM,19,[int#3]
   Elseif [datchik#Total]>=5000 And [plugin#gpio#pinstate#19]>=100 And [var#4]=0
 Let,3,[plugin#gpio#pinstate#19]-25
  PWM,19,[int#3]
  Elseif [datchik#Total]>=[var#4]-1500 And [plugin#gpio#pinstate#19]>=100 And [var#4]<>0
 Let,3,[plugin#gpio#pinstate#19]-25
  PWM,19,[int#3]
   Endif
Endon


On Rules#Timer=4 Do
  Let,4,[datchik#Total]*2
  TaskValueSet,6,1,[var#4]
Endon

TD-er
Core team member
Posts: 8748
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Rules in ESPeasy

#137 Post by TD-er » 05 Nov 2023, 10:13

Not sure if this will work:

Code: Select all

Elseif [datchik#Total]>=[var#4]-1500 
Just to be sure, you could change it to this:

Code: Select all

On Rules#Timer=1 Do
  If [datchik#Total]<=4999 And [plugin#gpio#pinstate#19]<=900 
    Let,3,[plugin#gpio#pinstate#19]+50
    PWM,19,[int#3]
  Elseif [datchik#Total]>=5000 And [plugin#gpio#pinstate#19]>=100 And [var#4]=0
    Let,3,[plugin#gpio#pinstate#19]-25
    PWM,19,[int#3]
  Elseif [plugin#gpio#pinstate#19]>=100 And [var#4]<>0
    let,3,[var#4]-1500
    if [datchik#Total]>=[var#3]
      Let,3,[plugin#gpio#pinstate#19]-25
      PWM,19,[int#3]
    Endif
  Endif
Endon

dr.zorg82
Normal user
Posts: 81
Joined: 02 Feb 2023, 07:32
Location: russia

Re: Rules in ESPeasy

#138 Post by dr.zorg82 » 05 Nov 2023, 16:01

my version also works, but yours is probably more reliable. Thank you

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests