[rules] problems with timer, not working as expected

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

[rules] problems with timer, not working as expected

#1 Post by borre » 20 Jun 2022, 14:10

Hello
I have a machine that give high or low output ([switch#state]) to my esp.
when the machine turns on, a fan must blow.
when the machine turns off the fan most blow for 5 more seconds en than turn off (if the machine is still off).

In the rules I have problems with the timer in the code below it does not turn the fan off after 5 seconds.
if I place "timerSet,1,5" with "GPIO,4,1"
it turns the fan off when the machine is done.
but I need a delay, fan needs to blow 5 sec longer after the machine is done.\

what am i doing wrong

Code: Select all

on System#Boot do
	//fan off
	GPIO,4,1
endon

on switch#state do
	if [switch#state]=1
		//fan on
		GPIO,4,0
	else
		// set timer for fan on 5 sec.
		timerSet,1,5
	endif
endon

On Rules#Timer=1 do  
    if [switch#state]=0
		//fan off
        	GPIO,4,1
    endif
endon


I am using this version of esp easy:
Build:⋄ 20104 - Mega
System Libraries:⋄ ESP82xx Core 2.6.0-dev stage, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support
Git Build:⋄ mega-20191003

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

Re: [rules] problems with timer, not working as expected

#2 Post by chromo23 » 20 Jun 2022, 14:58

does your switch have an intervall set in the device setting?
otherwise it should work..

(a look at the log is also often helpful...)

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#3 Post by borre » 20 Jun 2022, 15:18

chromo23 wrote: 20 Jun 2022, 14:58 does your switch have an intervall set in the device setting?
otherwise it should work..

(a look at the log is also often helpful...)
yes it has a interval set to 60 seconds.
but we I set it to 0 and save it, it goes back to 60
Image

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

Re: [rules] problems with timer, not working as expected

#4 Post by chromo23 » 20 Jun 2022, 15:22

this is not your switch in the screenshot. i´m just asking because if your switch would have set an intervall < 5 sek your rule would not work because your timer would be set every intervall new and it will never finish...

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#5 Post by borre » 20 Jun 2022, 15:32

chromo23 wrote: 20 Jun 2022, 15:22 this is not your switch in the screenshot. i´m just asking because if your switch would have set an intervall < 5 sek your rule would not work because your timer would be set every intervall new and it will never finish...
I am sorry, this is my switch
Image

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

Re: [rules] problems with timer, not working as expected

#6 Post by chromo23 » 20 Jun 2022, 15:43

ok..so what does your log say when using the switch...

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

Re: [rules] problems with timer, not working as expected

#7 Post by Ath » 20 Jun 2022, 15:48

Can you please attach screenshots to the post, see the Attachments tab when editing the post, because:
- External image services will stop sharing your image after some time (from hours to months)
- External image services contain a *lot* of advertising and other unwanted/undesirable references
/Ton

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

Re: [rules] problems with timer, not working as expected

#8 Post by Ath » 20 Jun 2022, 15:51

And, having a settings version of 20104, that implies you are running a very old release of ESPEasy (2 years + ?), please upgrade that first and retest, before we can properly support this. Get the latest from here https://github.com/letscontrolit/ESPEasy/releases
/Ton

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

Re: [rules] problems with timer, not working as expected

#9 Post by TD-er » 20 Jun 2022, 23:05

Build "mega-20191003" which does indeed look a bit dated.

On the other hand, if you're runnning on an 1MB unit, you may not be able to perform OTA updates on recent builds.

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#10 Post by borre » 21 Jun 2022, 13:56

yes I know its a older version, I got 7 of these devices running here and like to have them on the same software/fireware.
bit afraid of breaking stuff with updating.

also found the fault, there is indeed a interval on the status switch (5 sec)
but I kind of need this.
I have 5 laser machines, each machine has a esp device (CLIENTS) reading the on/off status.

a HOST esp reads get the values of the CLIENTS through through "ESPEasy P2P Networking"

on the CLIENT under devices add a amount of seconds under "interval"
I used 5 seconds, now the CLIENT updates the state of that device every 5 clients to the HOST (through "ESPEasy P2P Networking")

Now by the HOST under rules, I have this:

Code: Select all

//5
on MONA#state do
	if [MONA#state]=1
		gpio,14,1
		timerSet,5,10
	else
		gpio,14,0
	endif
endon
On Rules#Timer=5 do  
		gpio,14,0
endon
client 5 (MONA) shares here state, when she does that, and state =1
then I set gpio14 to 1, and set timer5 to 10 seconds.
if timer5 is finish after 10 seconds, then it puts gpio14 to 0
BUT if within those 10 seconds client MONA shares here state again and the state = 1 then gpio14 is set to 1 again and timer5 is reset to 10 seconds again.
ect, ect, ect

This is done because when the laser machine is turned of, the CLIENT esp is also turned off and cannot set the machine stat to the HOST.
If there was some command which the HOST can check if the a CLIENT is still ON and Connect I should not have to use a 5 sec interval.
if I remove the 5 sec interval on the STATE device, the timerset works as expected.


(added the screenshot to the attachment tab, was not aware of this tab)
Attachments
gerdien_state.PNG
gerdien_state.PNG (34.61 KiB) Viewed 1291 times

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#11 Post by borre » 21 Jun 2022, 14:12

hmmm have created some kind of work around but do not know why this works :?
interval of the STATE is still set to 5 sec

Code: Select all

on System#Boot do
	//fan off
    	GPIO,4,0
    	// set variable MachineState to 0
    	TaskValueSet 11,4,0
endon

on switch#state do
	if [switch#state]=1
		//fan on
		GPIO,4,1
		// set variable MachineState to 1
          	  TaskValueSet 11,4,1
                
	else
	    
	   	 if [Dummy#MachineState] = 1
	        	// set timmer to shutdown fan after 5 sec.
	       	 	timerSet,1,5
	        	// set variable MachineState to 0
			TaskValueSet 11,4,0
	    	endif
	endif
endon

On Rules#Timer=1 do  
       if [switch#state]=0
		// if the machine is still off, than put the fan out
       		gpio,4,0
       endif
endon
if I use

Code: Select all

	 
// set timmer to shutdown fan after 5 sec.
timerSet,1,5   	 
if [Dummy#MachineState] = 1
	// set variable MachineState to 0
	TaskValueSet 11,4,0
endif
instead of

Code: Select all

	    
if [Dummy#MachineState] = 1
	// set timmer to shutdown fan after 5 sec.
	timerSet,1,5
	TaskValueSet 11,4,0
endif
Why is this?

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

Re: [rules] problems with timer, not working as expected

#12 Post by chromo23 » 21 Jun 2022, 14:50

since the timer fires independent of

Code: Select all

Dummy#MachineState
in the working example i assume that the condition

Code: Select all

 if [Dummy#MachineState] = 1
is never met....

edit: this is something the log will tell you..

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#13 Post by borre » 21 Jun 2022, 14:58

chromo23 wrote: 21 Jun 2022, 14:50 since the timer fires independent of

Code: Select all

Dummy#MachineState
in the working example i assume that the condition

Code: Select all

 if [Dummy#MachineState] = 1
is never met....
I dont understand, in the working example

Code: Select all

	else
	    
	   	 if [Dummy#MachineState] = 1
	        	// set timmer to shutdown fan after 5 sec.
	       	 	timerSet,1,5
	        	// set variable MachineState to 0
			TaskValueSet 11,4,0
	    	endif
	endif
looks to me that [Dummy#MachineState] must be "1" before timer 1 is set to 5 seconds.

I checked it, and in the working example the [Dummy#MachineState] set to 1

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

Re: [rules] problems with timer, not working as expected

#14 Post by Ath » 21 Jun 2022, 16:32

Having both the timer and the Interval at 5 seconds is making it very hard to debug/test, please try with the Interval set to 7 seconds, so there is at least a chance they don't coincide.
/Ton

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

Re: [rules] problems with timer, not working as expected

#15 Post by chromo23 » 21 Jun 2022, 17:40

sorry..missed the post #10 so probably what i wrote before is nonsense. i´ll have a look at it later....

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

Re: [rules] problems with timer, not working as expected

#16 Post by chromo23 » 22 Jun 2022, 09:26

borre wrote: 21 Jun 2022, 13:56 if I remove the 5 sec interval on the STATE device, the timerset works as expected. [/b]
why not putting the state of the switch in a dummy device, give it a 5sec interval and share it with the other devices....then you can remove the interval of the switch

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

Re: [rules] problems with timer, not working as expected

#17 Post by TD-er » 22 Jun 2022, 09:37

I think this may be a cause for problems (not sure if it is "the" cause)

Code: Select all

on switch#state do
	if [switch#state]=1
You're acting on the event of the switch state and then, when it is handled, you're checking the current state of that value.
What you should do, is check what the state was when the event was generated.
This state is present in the eventvalues.

Code: Select all

on switch#state do
	if %eventvalue1%=1

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#18 Post by borre » 22 Jun 2022, 10:53

Ath wrote: 21 Jun 2022, 16:32 Having both the timer and the Interval at 5 seconds is making it very hard to debug/test, please try with the Interval set to 7 seconds, so there is at least a chance they don't coincide.
Tested it with different intervals and timerSet values
but the result stays the same.

Can anyone explain why timer 1 does NOT get triggered
and why timer 2 gets triggered

Code: Select all



//switch has a interval of 5 seconds
on switch#state do
	if [switch#state]=1
        	if [Dummy#MachineState] = 0
            		//fan on
	    		GPIO,4,1
	    		// set MachineState to 1
            		TaskValueSet 11,4,1
		endif
	else
		//this one does not get triggered
	    	timerSet,1,8
	    	if [Dummy#MachineState] = 1
			// This timmer get triggered
			timerSet,2,8
			// set MachineState to 0
			TaskValueSet 11,4,0
	   	endif

	endif
endon


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

Re: [rules] problems with timer, not working as expected

#19 Post by TD-er » 22 Jun 2022, 10:55

On tools->Advanced, uncheck this parameter (if available in your build)

Optimize Rules Cache Event Order:

Which reminds me, I still need to disable this by default.

Oh and change this part:

Code: Select all

on switch#state do
	if [switch#state]=1
to:

Code: Select all

on switch#state do
	if %eventvalue1%=1

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

Re: [rules] problems with timer, not working as expected

#20 Post by TD-er » 22 Jun 2022, 11:01

Not sure why timer#1 does not get triggered.
Maybe some other event does also set the timer to some value before it gets triggered? Or set to 0 to disable it?
Maybe a typo in your rules in the block to handle the timer?

To be sure, you can add some LogEntry commands to send some values to the log.

Code: Select all

		//this one does not get triggered
	    	timerSet,1,8
	    	LogEntry,"Calling: timerSet,1,8"

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

Re: [rules] problems with timer, not working as expected

#21 Post by chromo23 » 22 Jun 2022, 11:20

borre wrote: 22 Jun 2022, 10:53
Can anyone explain why timer 1 does NOT get triggered
and why timer 2 gets triggered


[/code]
because every 5 second it gets retriggered by the switch intervall and so it never finishes?
the intervall of the switch needs to be at least 9secs if your timer1 is set to 8secs

this is your "run timerSet,2,8 only once" - switch by setting the machinestate back after it happend.. so timer 2 can finish without beeing retriggered

Code: Select all

if [Dummy#MachineState] = 1
			// This timmer get triggered
			timerSet,2,8
			// set MachineState to 0
			TaskValueSet 11,4,0
	   	endif

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#22 Post by borre » 22 Jun 2022, 14:11

chromo23 wrote: 22 Jun 2022, 11:20
borre wrote: 22 Jun 2022, 10:53
Can anyone explain why timer 1 does NOT get triggered
and why timer 2 gets triggered


[/code]
because every 5 second it gets retriggered by the switch intervall and so it never finishes?
the intervall of the switch needs to be at least 9secs if your timer1 is set to 8secs

this is your "run timerSet,2,8 only once" - switch by setting the machinestate back after it happend.. so timer 2 can finish without beeing retriggered

Code: Select all

if [Dummy#MachineState] = 1
			// This timmer get triggered
			timerSet,2,8
			// set MachineState to 0
			TaskValueSet 11,4,0
	   	endif
Ah oke, It TIMER 2 gets restarted over and over again.
Now I understand, a timer cannot be trigger twice and get 2 times the output, it wil only run the output once.
Because the second time you trigger it, it cancel the first trigger and triggers it again, am I right? ??


TD-er wrote: 22 Jun 2022, 11:01 Not sure why timer#1 does not get triggered.
Maybe some other event does also set the timer to some value before it gets triggered? Or set to 0 to disable it?
Maybe a typo in your rules in the block to handle the timer?

To be sure, you can add some LogEntry commands to send some values to the log.

Code: Select all

		//this one does not get triggered
	    	timerSet,1,8
	    	LogEntry,"Calling: timerSet,1,8"
Oooooh LogEntry is new for me, this make life a lot more easy, thanks!!!!!

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

Re: [rules] problems with timer, not working as expected

#23 Post by chromo23 » 22 Jun 2022, 14:39

borre wrote: 22 Jun 2022, 14:11 Ah oke, It TIMER 2 gets restarted over and over again.
Now I understand, a timer cannot be trigger twice and get 2 times the output, it wil only run the output once.
Because the second time you trigger it, it cancel the first trigger and triggers it again, am I right? ??
correct....
but it is in your example timer1 that gests restarted over and over again and timer2 finishes successfully.

borre
Normal user
Posts: 14
Joined: 27 Feb 2020, 14:53

Re: [rules] problems with timer, not working as expected

#24 Post by borre » 23 Jun 2022, 09:30

chromo23 wrote: 22 Jun 2022, 14:39
borre wrote: 22 Jun 2022, 14:11 Ah oke, It TIMER 2 gets restarted over and over again.
Now I understand, a timer cannot be trigger twice and get 2 times the output, it wil only run the output once.
Because the second time you trigger it, it cancel the first trigger and triggers it again, am I right? ??
correct....
but it is in your example timer1 that gests restarted over and over again and timer2 finishes successfully.
Ah great, then now I understand.

One more question:

Is it possible to check if a 'ESPEasy P2P Networking' CLIENT is active/online?
maybe in a more recent version of esp easy?

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

Re: [rules] problems with timer, not working as expected

#25 Post by chromo23 » 23 Jun 2022, 11:40

A similar problem was discussed here: viewtopic.php?p=57854#p57854
you could basically send a "i am alive" message from one device to another with an given interval and write some code what to do if the other device doesn’t receive anymore...

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

Re: [rules] problems with timer, not working as expected

#26 Post by chromo23 » 23 Jun 2022, 12:08

note to developer:
i think commands like sendto or sendtohttp should return if they where successfull sending in a way that can be used in rules.....

:)

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

Re: [rules] problems with timer, not working as expected

#27 Post by TD-er » 23 Jun 2022, 12:23

chromo23 wrote: 23 Jun 2022, 12:08 note to developer:
i think commands like sendto or sendtohttp should return if they where successfull sending in a way that can be used in rules.....

:)
Yep, something like an event containing the error

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests