Rules in ESPeasy

Moderators: grovkillen, Stuntteam, TD-er

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

Re: Rules in ESPeasy

#51 Post by TD-er » 05 Feb 2023, 21:59

OK, so you did understand the question :)

I will try to create some rules for you.

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

Re: Rules in ESPeasy

#52 Post by dr.zorg82 » 06 Feb 2023, 08:23

thank you/ it's should be godd :oops:

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

Re: Rules in ESPeasy

#53 Post by TD-er » 06 Feb 2023, 10:07

I think this is just about all you need:

Disinfection start procedure:
set flag indicating we did start the procedure (set variable #1 to '1')
GPIO,27,1
2500 ms
LongPulse_mS,32,1,500,500,0
2500 ms
LongPulse_mS,13,1,500,500,0

Disinfection stop procedure:
GPIO,27,0
clear flag indicating we did stop the procedure (set variable #1 to '0')

Start periods disinfection:
06:00 to 07:30
18:00 to 19:30

End disinfection:
90 minutes after starting

Requirements:
Disinfection & boiler not together
Not sure if the pump should also be enabled???
Boiler controlled by temperature


What we need to do:
If in start period disinfection, check if boiler is active.
When boiler not active, perform "Disinfection start procedure" + set stop timer for 90 minutes

Code: Select all

on Clock#Time=All,**:** do
  if [int#1]=0
    if %systm_hm_0% >=06:00 And %systm_hm_0% <=07:30
      asyncevent,startDisinfection
    endif
    if %systm_hm_0% >=18:00 And %systm_hm_0% <=19:30
      asyncevent,startDisinfection
    endif
  endif
endon

on startDisinfection do
  if [int#1]=0
    // TD-er: Should also check for pump state?
    if [boiler#boiler]=0 // and [pump#pump]=1
      let,1,1  // set variable #1 to '1'
      gpio,27,1
      TimerSet_ms,1,2500
      TimerSet,3,5400 // 90 minutes timer to stop disinfection run
    endif
  endif
endon


On Rules#Timer=1 do // Press 1st button to activate disinfection
  LongPulse_mS,32,1,500,500,0
  TimerSet_ms,2,2500
Endon

On Rules#Timer=2 do // Press 2nd button to activate disinfection
  LongPulse_mS,13,1,500,500,0
Endon

On Rules#Timer=3 do // Stop disinfection procedure
  GPIO,27,0
  let,1,0 // clear flag indicating we did stop the procedure (set variable #1 to '0')
Endon


on temp#water do 
  if %eventvalue1% <=25.00
    // темп. воды в бассдля вкл. обогрева 
    GPIO,12,1
    gpio,33,1
  else
    // темп. воды в бассдля выкл. обогрева
    GPIO,12,0  
  endif
Endon

on temp#air do 
  if %eventvalue1% <=-0.5 
    // темп. воздуха вкл. греющ. кабеля
    GPIO,25,1
  endif
  if %eventvalue1% >=0.0
    // темп. воздуха выкл. греющ.кабеля
    GPIO,25,0
  endif  
Endon
The only thing I was wondering is, what happens when the pump is turned off and the disinfection procedure is still active?
Should it be turned off immediately?

I also added the temperature checks, temp#water without hysteresis, as it seemed like this would be integer degrees?
The other with the hysteresis of 0.5 degree.
You should check for yourself whether it needs 2 if..endif checks (with hysteresis) or an if...else...endif check (without hysteresis)

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

Re: Rules in ESPeasy

#54 Post by dr.zorg82 » 06 Feb 2023, 10:31

Thanks a lot. I'll try a little later. :)
and the pump is always running, the water must constantly circulate. only from 22.00 to 02.00 I turn it off. but if the water temperature drops, then the boiler turns on and the pump also turns on
now I see why it was easier for you to write the code yourself than to explain to me :oops:
Last edited by dr.zorg82 on 06 Feb 2023, 10:43, edited 1 time in total.

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

Re: Rules in ESPeasy

#55 Post by TD-er » 06 Feb 2023, 10:42

The timer to turn off the pump is not included, but that can be added to the
on Clock#Time=All,**:** do
part.

Code: Select all

on Clock#Time=All,**:** do
  if [int#1]=0
    if %systm_hm_0% >=06:00 And %systm_hm_0% <=07:30
      asyncevent,startDisinfection
    endif
    if %systm_hm_0% >=18:00 And %systm_hm_0% <=19:30
      asyncevent,startDisinfection
    endif
  endif
  if %systm_hm_0% <22:00 And %systm_hm_0% >02:00
    // Turn pump on (GPIO 33?)
    
  else
    // Turn pump off (GPIO 33?)
    
  endif
endon

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

Re: Rules in ESPeasy

#56 Post by dr.zorg82 » 06 Feb 2023, 10:48

Fine. I understand. Thank you. I will study the code and try in practice.
By the way, I'll get back to you. I will need to make control of the current in the circuit and adjust the speed of rotation of the collector motor. and I feel like I can't do it myself. but this is later, while I'm waiting for a current sensor (acs712) from China :oops: ;)

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

Re: Rules in ESPeasy

#57 Post by TD-er » 06 Feb 2023, 11:35

That's just a simple hall-effect sensor, outputting an analog value, right?

No idea what you try to measure, but make sure you also check the signal from it using a multimeter and preferably some oscilloscope or using a multimeter which can also give some info on whether it is an AC or DC signal coming from this sensor.

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

Re: Rules in ESPeasy

#58 Post by dr.zorg82 » 06 Feb 2023, 12:22

TD-er wrote: 06 Feb 2023, 11:35 That's just a simple hall-effect sensor, outputting an analog value, right?
it's right.
oscilloscope and multimeter are available. I will use them when setting up the current sensor

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

Re: Rules in ESPeasy

#59 Post by dr.zorg82 » 06 Feb 2023, 12:27

or maybe you will recommend another current sensor that will be easier to set up in espeasy? my task is to measure the direct current in the circuit and, according to the values ​​of this current, increase or decrease the speed of the collector motor

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

Re: Rules in ESPeasy

#60 Post by TD-er » 06 Feb 2023, 12:42

Not sure if the current is a good indicator to control speed.
For example if the thing that needs to be driven by this motor is somehow stuck or experiencing a lot more friction, then the current will also go up. But trying to increase the "speed" may even be damaging to the motor.

IMHO, feedback from a tacho will be better to control the speed of a motor.
The current measurement would then still be useful, but more like to protect the motor instead of driving it harder.

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

Re: Rules in ESPeasy

#61 Post by dr.zorg82 » 06 Feb 2023, 13:26

I'll try to explain. disinfection of water in the pool is carried out using a device that produces chlorine from a 10% salt solution (NaCl). but the solution is not always the same, sometimes there is more water, sometimes more salt, and the current in the reactor of the device and, accordingly, the amount of chlorine depend on this. salt solution is supplied by a peristaltic pump. so I want to measure the direct current in the reactor (maximum 10A) and thereby regulate the speed of rotation of the peristaltic pump motor. that is, if the salt concentration is low, the current in the reactor decreases and the pump speed must be increased to increase the salt concentration
seems to be able to explain :D
all this so that there is no excess consumption of salt and the concentration of chlorine in the water is the same.

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

Re: Rules in ESPeasy

#62 Post by TD-er » 06 Feb 2023, 13:40

The reason I started about the current measurement you plan on doing is about whether you're measuring AC or DC current.
A simple Hall Effect sensor measures the magnetic field.
But since this is an analog sensor, it may very quickly respond to changes in current. (no idea whether the chip used in that sensor also tries to 'flatten' this signal)
Both AC and DC motors generate a quite complex current. Brushed DC motors even more complex than others.
So if the sensor doesn't 'average' the signal, you need to average it yourself before measuring.
Otherwise you need an incredible high sampling rate to make sense of the current being drawn.

That's why I mentioned you should be able to 'look' at the signal output of the sensor before trying to make sense of it using rules.

I do think using a contact-less way of measuring the current is a good idea, from a safety point of view.
So if you can make it work using such a sensor, then that would be the preferred way.

However, as always;
Measuring is knowing, only if you know what you're measuring.

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

Re: Rules in ESPeasy

#63 Post by dr.zorg82 » 06 Feb 2023, 13:50

TD-er wrote: 06 Feb 2023, 13:40
That's why I mentioned you should be able to 'look' at the signal output of the sensor before trying to make sense of it using rules.

If I understand you correctly, I will answer: this sensor has an analog signal at the output. for every ampere of current it produces 100 mV of DC voltage. that is, on my 10a, the output of this sensor will be 1 v.
and the speed of the collector motor (12 volts) will be regulated using a field effect transistor, which will be controlled by PWM

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

Re: Rules in ESPeasy

#64 Post by TD-er » 06 Feb 2023, 13:57

Yes, but the question is, how 'constant' is this 10A of current?
And how quickly does the sensor respond to changes in current?
If for example the motor is a brushed DC motor, the current will change every time the brush connects to the next coil and the currents will be 'all over the scale'. Maybe even spike >100A for a very short time.
So it all depends on what will be on the output of the Hall effect sensor, to see if we can use the signal at all.

Especially if you control the motor using PWM, the signal will be extremely noisy.

If this sensor does reply immediately, then its raw output voltage should first be filtered before we can use it.
That's why I mention you should be able to 'view' this signal using some scope or something like that as I suspect it will not be a nice flat signal coming out of this sensor given the source you will try to measure.

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

Re: Rules in ESPeasy

#65 Post by dr.zorg82 » 06 Feb 2023, 14:20

TD-er wrote: 06 Feb 2023, 13:57
If for example the motor is a brushed DC motor, the current will change every time the brush connects to the next coil and the currents will be 'all over the scale'. Maybe even spike >100A for a very short time.
No. motor current does not need to be measured. brine enters the reactor. a constant voltage is applied to the reactor and chlorine is produced. the more salt solution, the greater the current. current must be measured in the reactor. and the motor of the peristaltic pump is powered by a different voltage source. that is, we measure the current in the reactor, and change the voltage on the pump motor. if the current in the reactor decreases, then you need to increase the voltage on the pump so that it increases the supply of brine. if the supply of salt solution increases, then the current in the reactor will increase.
the artist, like the programmer, is not very good of me, but I hope it turned out clearly :oops:
IMG_20230206_161823.jpg
IMG_20230206_161823.jpg (4.43 MiB) Viewed 6106 times
the current sensor, of course, through the esp32 affects the speed of the pump.

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

Re: Rules in ESPeasy

#66 Post by TD-er » 06 Feb 2023, 14:53

Ah, now I understand... it is the current through the liquid, not the current drawn by the motor.

I guess that would be a rather constant current indeed.

Not sure if this will cause some gas to be formed, as I can imagine this might constantly change the contact area of the electrodes, causing changes in current.
So maybe you still might need to add some light filtering on the measured signal. For example a small capacitor could be enough.

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

Re: Rules in ESPeasy

#67 Post by dr.zorg82 » 06 Feb 2023, 15:04

TD-er wrote: 06 Feb 2023, 14:53
I guess that would be a rather constant current indeed.
yes, this current does not change very often. it's pretty constant. although I'll still look at the oscilloscope to be sure. thank you for your patience. :)

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

Re: Rules in ESPeasy

#68 Post by dr.zorg82 » 06 Feb 2023, 16:10

TD-er wrote: 06 Feb 2023, 10:07 I think this is just about all you need:
put your code. everything works as it should. I bow before you :)

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

Re: Rules in ESPeasy

#69 Post by TD-er » 06 Feb 2023, 16:16

Ah good to know :)

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

Re: Rules in ESPeasy

#70 Post by dr.zorg82 » 19 Mar 2023, 17:01

https://letscontrolit.com/forum/viewtop ... 958#p62958
Good afternoon. finally I got the second module and the analog current sensor. and I can keep asking questions :oops: I need to maintain a stable current in the reactor by using a salt pump. that is, if the current in the reactor is lower than the required value, then needed to increase the speed of the pump, and if the current is higher, then needed to reduce the speed of the pump. configured analog input. This is where my knowledge ends. :roll: please tell me how to make the pump speed increase (decrease) until the current reaches the specified level? the response of the current to the pump speed is almost instantaneous.
2023-03-19_18h42_05.png
2023-03-19_18h42_05.png (27.66 KiB) Viewed 5709 times
for example, during normal operation, the analog input should be 1000,. and if the analog input is 500, then the PWM(gpio 25) should increase until the input becomes 1000

Is it enough in my case to do so?

Code: Select all

ON garag#analog do
 if %eventvalue1% < 1000.00
  PWM,25,++2
 if %eventvalue1% > 1000.00
  PWM,25,--2
EndIf
endon

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

Re: Rules in ESPeasy

#71 Post by dr.zorg82 » 20 Mar 2023, 17:06

dr.zorg82 wrote: 19 Mar 2023, 17:01

Is it enough in my case to do so?

Code: Select all

ON garag#analog do
 if %eventvalue1% < 1000.00
  PWM,25,++2
 if %eventvalue1% > 1000.00
  PWM,25,--2
EndIf
endon
doesn't work like that.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#72 Post by Ath » 20 Mar 2023, 19:18

dr.zorg82 wrote: 20 Mar 2023, 17:06

Code: Select all

  PWM,25,++2
What do you expect that to do?
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#73 Post by chromo23 » 20 Mar 2023, 19:22

At first you need an interval for "garag#analog" ..like 1s,
then you need a value for PWM you can refer to:

Code: Select all

PWM,25,[Value]+2 //where two is a fairly low value...
This value you can get from here: [plugin#gpio#pinstate#25] (to use this you must have set pin25 to a pwm value elsewhere before)
And maybe it is a good idea to give the whole thing a hysteresis.
And last but not least: every "If" needs an "Endif" unless you want to use an "Elseif" ...https://espeasy.readthedocs.io/en/lates ... lseif-else

Code: Select all

On garag#analog Do
 If %eventvalue1% < 900.00
  PWM,25,[plugin#gpio#pinstate#25]+2
 Elseif %eventvalue1% > 1000.00
  PWM,25,[plugin#gpio#pinstate#25]+2
 Endif
Endon
Edit: but to be honest, i doubt that your approach will work very well...

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

Re: Rules in ESPeasy

#74 Post by dr.zorg82 » 21 Mar 2023, 05:54

chromo23 wrote: 20 Mar 2023, 19:22 At first you need an interval for "garag#analog" ..like 1s,
Good morning. Thanks, I'll try it tonight.
but why do you think it won't work very well?
Fine. if you forget about my project. how to make smooth adjustment of the LED in espeasy? For example, in C++ it can be done like this (taken from the Internet):

Code: Select all

#define LED_PIN 25

void setup() {
    pinMode(LED_PIN, OUTPUT); 
}

void loop() {
	for(int i=0;i<=255;i++) {
	analogWrite(LED_PIN, i);
	delay(5);
   }

	for(int i=255;i>=0;i--) {
	analogWrite(LED_PIN, i);
	delay(5);
   }

}
I have now Build: ESP_Easy_mega_20230306_neopixel_ESP32_4M316k Mar 6 2023. maybe something else needs to be added?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#75 Post by chromo23 » 21 Mar 2023, 09:13

dr.zorg82 wrote: 21 Mar 2023, 05:54 but why do you think it won't work very well?
I actually don’t know... it was more of a hunch without really knowing how your system works and how fast it needs to react.
Give it a try. :)

Inline calculations doesn’t seem to work, so you should do the math before and put it in a variable...
...and you probably should add some limits since the pwm-value can be set out of range:

Code: Select all

On garag#analog Do
 If %eventvalue1% < 900.00 And [plugin#gpio#pinstate#25] <= 1021
   Let,1,[plugin#gpio#pinstate#25]+2
   PWM,25,[int#1]
 Elseif %eventvalue1% > 1000.00 And [plugin#gpio#pinstate#25] >= 2 
   Let,1,[plugin#gpio#pinstate#25]-2
   PWM,25,[int#1]
 Endif
Endon

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

Re: Rules in ESPeasy

#76 Post by TD-er » 21 Mar 2023, 09:29

For inline calculations, you may want to prepend an "=".

Code: Select all

   PWM,25,=[plugin#gpio#pinstate#25]+2
However this may not be used everywhere, thus storing it in a variable is a safe way to make sure the values are always calculated.

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

Re: Rules in ESPeasy

#77 Post by dr.zorg82 » 21 Mar 2023, 16:45

chromo23 wrote: 21 Mar 2023, 09:13
Give it a try. :)
]
Thanks a lot. works. :)
chromo23 wrote: 20 Mar 2023, 19:22 At first you need an interval for "garag#analog" ..like 1s,
but one second is long :( Can you please tell me if it is possible to reduce the polling time of an analog sensor? it is impossible to take a big step to increase the PWM . now i increased from 2 to 20

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#78 Post by chromo23 » 21 Mar 2023, 17:49

dr.zorg82 wrote: 21 Mar 2023, 16:45 but one second is long
That was part of my hunch... :D
dr.zorg82 wrote: 21 Mar 2023, 16:45 Can you please tell me if it is possible to reduce the polling time of an analog sensor?
Sorry, but you can’t. At least not that i know of. Maybe you should do the controlling with a dedicated microcontroller like an atmega328 or something similar.
Or somebody writes a plugin for ESPeasy with exactly this purpose :)

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

Re: Rules in ESPeasy

#79 Post by dr.zorg82 » 21 Mar 2023, 18:07

chromo23 wrote: 21 Mar 2023, 17:49Sorry, but
I see. Thanks!! it's a pity. although needed to make an experience and maybe that's enough :roll:

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

Re: Rules in ESPeasy

#80 Post by dr.zorg82 » 22 Mar 2023, 13:12

and hello again. :) I have part of the code

Code: Select all

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

On Rules#Timer=1 do 
   GPIO,4,1
   PWM,25,500
   TimerSet,2,50
Endon

On Rules#Timer=2 Do
  [garag#analog]
Endon 

On garag#analog Do
 If %eventvalue1% < 999.00 And [plugin#gpio#pinstate#25] <= 1010
   Let,1,[plugin#gpio#pinstate#25]+20
   PWM,25,[int#1]
 Elseif %eventvalue1% > 1000.00 And [plugin#gpio#pinstate#25] >= 500 
   Let,1,[plugin#gpio#pinstate#25]-20
   PWM,25,[int#1]
 Endif
Endon
after timer 2 should start executing garag#analog. i.e. part of the code

Code: Select all

On Rules#Timer=2 Do
  [garag#analog]
Endon 
is it correct?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#81 Post by chromo23 » 22 Mar 2023, 13:22

It seems to be correct. If you want to see what is going on, you can always head over to the log-viewer in the /tools tab.

Edit: And you can also always put a "LogEntry" in your code for your own messages. This will then be displayed in the Logviewer.

Example:
(adding all the hyphen gives a better readability, especially when a lot of entries are scrolling through the log-viewer)

Code: Select all

LogEntry,'----------------------------initial value: [var#1]' 
log.png
log.png (97.86 KiB) Viewed 5547 times
Last edited by chromo23 on 22 Mar 2023, 13:32, edited 1 time in total.

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

Re: Rules in ESPeasy

#82 Post by dr.zorg82 » 22 Mar 2023, 13:30

chromo23 wrote: 22 Mar 2023, 13:22 you can always head over to the log-viewer in the /tools tab
I always forget about it :oops: . Thanks a lot.

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#83 Post by Ath » 22 Mar 2023, 13:46

dr.zorg82 wrote: 22 Mar 2023, 13:12 after timer 2 should start executing garag#analog. i.e. part of the code

Code: Select all

On Rules#Timer=2 Do
  [garag#analog]
Endon 
is it correct?
That will only try to execute the value of [garag#analog] as a command, (I) don't expect that to do anything useful.

If you want to 'run' the garag task, use this command:

Code: Select all

  TaskRun,garag
That will trigger the matching event, after retrieving the latest value.
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#84 Post by chromo23 » 22 Mar 2023, 13:58

Ath wrote: 22 Mar 2023, 13:46 That will only try to execute the value of [garag#analog] as a command
I think it was used as a placeholder for the code.
If not, then @Ath is right. But then it is probably anyway better to activate and deactivate the whole task with:

Code: Select all

TaskDisable,[number of the analog device]
TaskEnable,[number of the analog device]
Like this:

Code: Select all

On System#Boot Do
  TaskDisable,1
Endon

On Rules#Timer=2 Do
  TaskEnable,1
Endon

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

Re: Rules in ESPeasy

#85 Post by dr.zorg82 » 22 Mar 2023, 14:09

thank you for your patience and help. but i have a new problem :mrgreen:

Code: Select all

On garag#analog Do
 If %eventvalue1% < 999.00 And [plugin#gpio#pinstate#25] <= 1010
   Let,1,[plugin#gpio#pinstate#25]+20
   PWM,25,[int#1]
 Elseif %eventvalue1% > 1000.00 And [plugin#gpio#pinstate#25] >= 500 
   Let,1,[plugin#gpio#pinstate#25]-20
   PWM,25,[int#1]
 Endif
 If %eventvalue1% < 100.00
 TimerSet,3,60
 Endif
Endon

On Rules#Timer=3 do 
   GPIO,23,1
Endon
the analog sensor polling time is 1 second, and timer 3 sets the delay to 60 seconds. and in the log I see that the timer is reset every second and pin 23 will not turn on in any way
Безымянный.png
Безымянный.png (26.24 KiB) Viewed 5530 times
please tell me what am i doing wrong?

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules in ESPeasy

#86 Post by Ath » 22 Mar 2023, 14:16

Check this code in your rule:

Code: Select all

 If %eventvalue1% < 100.00
 TimerSet,3,60
 Endif
The event is called with %eventvalue1% = 0, so that is true every second (the Interval for the garag task), so the timer will be reset...
Not sure why that value is 0 though.
/Ton (PayPal.me)

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

Re: Rules in ESPeasy

#87 Post by dr.zorg82 » 22 Mar 2023, 14:23

Ath wrote: 22 Mar 2023, 14:16 so the timer will be reset
my task is this: if garag#analog<100 within a minute, then pin 23 should turn on.
but garag#analog is polled every second. What do i do?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#88 Post by chromo23 » 22 Mar 2023, 15:25

dr.zorg82 wrote: 22 Mar 2023, 14:23 What do i do?
Set a variable to run TimerSet only once and set i back when %eventvalue% is not <100

Code: Select all

On garag#analog Do
 If %eventvalue1% < 999.00 And [plugin#gpio#pinstate#25] <= 1010
   Let,1,[plugin#gpio#pinstate#25]+20
   PWM,25,[int#1]
 Elseif %eventvalue1% > 1000.00 And [plugin#gpio#pinstate#25] >= 500 
   Let,1,[plugin#gpio#pinstate#25]-20
   PWM,25,[int#1]
 Endif
 If %eventvalue1% < 100.00 And [var#2] = 0
  TimerSet,3,60
  Let,2,1
 Elseif %eventvalue1% >= 100.00
  TimerSet,3,0
  Let,2,0
 Endif
Endon

On Rules#Timer=3 do 
   GPIO,23,1
Endon
Last edited by chromo23 on 22 Mar 2023, 17:38, edited 1 time in total.

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

Re: Rules in ESPeasy

#89 Post by dr.zorg82 » 22 Mar 2023, 15:55

chromo23 wrote: 22 Mar 2023, 15:25
Set a variable to run TimerSet only once
oh how stupid I am. Thank you :D I still can't figure out the variables. need to read more

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#90 Post by chromo23 » 22 Mar 2023, 17:38

chromo23 wrote: 22 Mar 2023, 15:25 Set a variable to run TimerSet
I just saw, that i used the same variable than that which was already in code... i corrected it now

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

Re: Rules in ESPeasy

#91 Post by dr.zorg82 » 23 Mar 2023, 05:37

chromo23 wrote: 22 Mar 2023, 17:38 that i used the same variable
Yes. Thank you. I noticed this yesterday, but didn't have time to try it

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

Re: Rules in ESPeasy

#92 Post by dr.zorg82 » 25 Apr 2023, 18:09

Good afternoon. I have a problem again but this time with a long button press. I have a simple rule

Code: Select all

On qq#qq Do
  If %eventvalue1%=1
  GPIO 16,1
  Elseif %eventvalue1%=11
  GPIO 17,1
  Endif
Endon
but with a long press, it works first GPIO16 and only then GPIO17. please tell me how to fix it
somewhere I found such a solution (did not try it), but maybe there is a more convenient one?

Code: Select all

on Switch1#switch1=1 do
 timerSet,1,1
EndOn

On Rules#Timer=1 do
 Publish sometopic/switch1,single
 timerSet,1,0
endon

on Switch1#switch1=3 do
 Publish sometopic/switch1,double
 timerSet,1,0
EndOn

on Switch1#switch1=11 do
 Publish sometopic/switch1,long
 timerSet,1,0
endon

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#93 Post by chromo23 » 26 Apr 2023, 08:53

dr.zorg82 wrote: 25 Apr 2023, 18:09 I have a problem again but this time with a long button press. I have a simple rule
Yes, it´s a problem. The short press event (1) is always fired fist.
To get around this , there are different valid approaches.
I can show you mine:

Code: Select all

On Button#State Do
  If %eventvalue%=1
   LoopTimerSet_ms,1,100,50
  Elseif %eventvalue%=0
    If [var#4] >= 25 and [var#4] < 35
      AsyncEvent,wifiap
    Elseif [var#4] >= 10
      AsyncEvent,longpress
    Elseif [var#4] < 6
      AsyncEvent,shortpress
    Endif
    TimerSet,4,0
    Let,4,0
  Endif
Endon

On Rules#Timer=4 Do
  Let,4,%eventvalue2%
    If %eventvalue2% >= 35
      NeoPixelAll,255,0,255
      AsyncEvent,Resetevent
    Elseif %eventvalue2% >= 25
      NeoPixelAll,255,255,0   
    Elseif %eventvalue2% >= 10
      NeoPixelAll,0,255,0   
    Elseif %eventvalue2% < 6
      NeoPixelAll,0,255,255
    Endif
Endon
Short explanation:
-when the button is pressed a loop timer is started and stores its number of loops in a variable
-when the button is released an event is called depending on the number of loops
- if you want the longpress event to be fired without releasing the button put it in the rules#timer block (see: AsyncEvent,Resetevent)
- for visual feedback i use a neopixel where you can see when it is time to release the button...

to shorten it for you:

Code: Select all

On Button#State Do
  If %eventvalue%=1
    LoopTimerSet_ms,1,100,50
  Elseif %eventvalue%=0
    If [var#4] < 6
      GPIO 16,1             //shortpress
    Endif
    TimerSet,4,0
    Let,4,0
  Endif
Endon

On Rules#Timer=4 Do
  Let,4,%eventvalue2%
  If %eventvalue2% >=10
    GPIO 17,1             //longpress
  Endif
Endon

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#94 Post by chromo23 » 26 Apr 2023, 09:10

Or simpler since you probably won´t need multiple long press with different length:

Code: Select all

On Button#State Do
  If %eventvalue%=1
   TimerSet,1,1
  Elseif %eventvalue%=0
    If [var#1] = 0
      GPIO 16,1             //shortpress
    Endif
    TimerSet,1,0
    Let,1,0
  Endif
Endon

On Rules#Timer=1 Do
  Let,1,1
  GPIO 17,1             //longpress
Endon
dr.zorg82 wrote: 25 Apr 2023, 18:09 but maybe there is a more convenient one?
I guess not.

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

Re: Rules in ESPeasy

#95 Post by dr.zorg82 » 26 Apr 2023, 10:08

chromo23 wrote: 26 Apr 2023, 09:10 I guess not.
Yeah. not so simple :D thank you.
i have three options :
how i did

Code: Select all

on qq#qq=1 do
 TimerSet,1,1
Endon

On Rules#Timer=1 do
 GPIO,16,1
 TimerSet,1,0
endon

on qq#qq=11 do
 GPIO,17,1
 TimerSet,1,0
endon
as suggested to me

Code: Select all

On qq#qq Do
  If %eventvalue1%=1
    let,1,0
  Elseif %eventvalue1%=11
    GPIO,17,1
    let,1,1
  Elseif %eventvalue1%=0 and %v1%=0
    GPIO,16,1
  Endif
Endon
and your choice.
Is there any difference between them in the operation of the device?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rules in ESPeasy

#96 Post by chromo23 » 26 Apr 2023, 10:26

dr.zorg82 wrote: 26 Apr 2023, 10:08 Is there any difference between them in the operation of the device?
Yes.
This one is the least responsive example since it only fires a shortpress after one second....

Code: Select all

on qq#qq=1 do
 TimerSet,1,1
Endon

On Rules#Timer=1 do
 GPIO,16,1
 TimerSet,1,0
endon

on qq#qq=11 do
 GPIO,17,1
 TimerSet,1,0
endon

Mine ist actually the same as the latter one. The only difference it, that my suggestion is independent of the settings of the switch plugin.
So for you the latter one in your last post makes the most sense...

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

Re: Rules in ESPeasy

#97 Post by TD-er » 26 Apr 2023, 11:24

The reason the "short press" event is fired first is to make it more responsive.

You can also act on the specific values as you do in your latest code, but keep in mind the rules parsing stops when a matching event block is found.
So have the most restrictive version first.

on qq#qq=1 do // << more restrictive
on qq#qq do // << less restrictive

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

Re: Rules in ESPeasy

#98 Post by dr.zorg82 » 26 Apr 2023, 11:59

chromo23 wrote: 26 Apr 2023, 10:26
TD-er wrote: 26 Apr 2023, 11:24
thanks for the explanation.

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

Re: Rules in ESPeasy

#99 Post by dr.zorg82 » 26 Apr 2023, 12:07

and yet I don’t understand why this option is bad, except that a short press will work after one second

Code: Select all

on qq#qq=1 do
 TimerSet,1,1
Endon

On Rules#Timer=1 do
 GPIO,16,1
 TimerSet,1,0
endon

on qq#qq=11 do
 GPIO,17,1
 TimerSet,1,0
endon 
:?:

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

Re: Rules in ESPeasy

#100 Post by TD-er » 26 Apr 2023, 12:12

For your use case this isn't bad.

It is still possible the timer will be handled before the long press event is fired.
It depends on how critical the timer is compared to the set delay to consider it a longpulse.

So if GPIO 16 should not be set when 17 is set, you may want to tweak those timings or even set the GPIO 16 to 0 when dealing with the longpulse.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests