Timer adds additional 1 second delay

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Timer adds additional 1 second delay

#1 Post by buzzger0815 » 05 Aug 2020, 18:03

Hi there!

I'm really new to the espeasy thing, but i directly got trapped into an unlogical aspect i think.

Why does this rule toogle a (on a pcf8574 i2c ic attached) led NOT in 1 second pulse but in a 2 seconds pulse?

Code: Select all

On System#Boot do
  timerSet,2,1
  pcfgpio,1,1
endon

On Rules#Timer=1 do
  timerSet,2,1
  pcfgpio,1,1
endon

On Rules#Timer=2 do
  timerSet,1,1
  pcfgpio,1,0
endon
It toogles the led in a 2 second pulse. It seems, that the execution of the Rules Timer adds an additional 1 second delay or anything like this.

Is it possible to set a timer with milliseconds?

By the way, i use build 120 because of a blue esp8266 module. If i got everthing right, the blue esp module couldnt get more than build 120.

Another by the way, its not about toogling a led with 1 second pulse, its about getting used to the system and understanding it.

Thank you for your answer!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Timer adds additional 1 second delay

#2 Post by grovkillen » 05 Aug 2020, 19:00

R120 is super old. Use the latest version instead.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: Timer adds additional 1 second delay

#3 Post by Ath » 05 Aug 2020, 20:26

After installing the latest release from https://github.com/letscontrolit/ESPEasy/releases on your device, you might also read this thread about the 'accuracy' of the timers: https://www.letscontrolit.com/forum/vie ... f=2&t=7849
/Ton (PayPal.me)

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

Re: Timer adds additional 1 second delay

#4 Post by Ath » 05 Aug 2020, 20:32

If you could connect the LED on a standard GPIO port, then you could use the

Code: Select all

longpulse_ms,<GPIO>,<state>,<duration>
command to turn it on for a number of milliseconds, using a higher resolution timer.
/Ton (PayPal.me)

buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Re: Timer adds additional 1 second delay

#5 Post by buzzger0815 » 05 Aug 2020, 23:52

@Ath
Thank you, but its not about connecting an led, but about getting use to the rules and the syntax. The led blink thing is just a test.

I updated to build 147, nothing changed, same behavior.

@grovkilen

I updated to build 147, nothing changed, same behavior.



I played a bit and i found out, that starting a timer on boot with timerset 1,1 and a timerset 1,0 (which reading the manual should disable the timer) in every occurency of the timer results in a timer coming up precise every second. Is this the planed behavior?

But now, playing again with my led toogle thing, i would like to use a variable to store the actual value and to toogle. Reading the forum i came out with a for example let 1,1 to store the value in the variable and a %v1% or a [VAR#1] to get the value out of the variable. But this doesnt work (again :( ). Please see my rule and find my fault, PLEASE!

Code: Select all

On System#Boot do
  timerSet,1,1  // start timer 1 with 1 second 
  pcfgpio,1,0  // set initial state of the led to off
  let 1,1	// store 1 into variable 1 for the state "led_off" (1)
endon

On Rules#Timer=1 do
  if [VAR#1]=1  // is current state "led_off" (1)
    pcfgpio,1,1  // set led on
    let 1,2  // set new state to "led_on" (2)
  endif

  if [VAR#1]=2  // is current state "led_on" (2)
    pcfgpio,1,0  // set led off
    let 1,1  // set new state to "led_off" (1)
  endif

  timerSet 1,0  // "disable timer 1", which results in firing the event of timer 1 in 1 second
endon

Thank you for looking at my thread. As i said, i'm trying to get use to espeasy and the rules for the decission to use it or not.

Thanks!

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

Re: Timer adds additional 1 second delay

#6 Post by TD-er » 06 Aug 2020, 02:25

Well that build is also "ancient".

Can you pick a build from here: https://github.com/letscontrolit/ESPEasy/releases

buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Re: Timer adds additional 1 second delay

#7 Post by buzzger0815 » 06 Aug 2020, 08:34

@TD-er

Thanks mate, that was a good advice. I picked my firmware from the "how to flash" page, which leads me to build 120 or 147. But now i'm on build 20109 - Mega. Thanx!

Now this code

Code: Select all

On System#Boot do
  pcfgpio,1,0
  let 1,0
  timerSet,1,1
endon

On Rules#Timer=1 do
  if [VAR#1]=1
    pcfgpio,1,0
    let 1,0
  else
    pcfgpio,1,1
    let 1,1
  endif
  timerSet,1,1
endon
works and i'm ended up in a very precise toogle at 2 seconds. So i'm back again to the thread topic, it adds an additional 1 second delay. Why is that?

By the way, now timerSet,1,0 really kills the timer and its not gonna get fired again.

Thank you!

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

Re: Timer adds additional 1 second delay

#8 Post by TD-er » 06 Aug 2020, 10:02

What you can try is to set the timer right at the start of execution of the rules block.

Code: Select all

On Rules#Timer=1 do
  timerSet,1,1
  if [VAR#1]=1
    let 1,0
  else
    let 1,1
  endif
  pcfgpio,1,[VAR#1]
endon
And I'm not entirely sure, but maybe this will also work:

Code: Select all

On Rules#Timer=1 do
  timerSet,1,1
  let 1,![VAR#1]
  pcfgpio,1,[VAR#1]
endon

buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Re: Timer adds additional 1 second delay

#9 Post by buzzger0815 » 06 Aug 2020, 10:25

No, the "toogle impuls width" :) stays at 2 seconds. But is this a bug or is this wanted behavior?

By the way, the "maybe this will also work" part of your code works pretty well!

By the second way, this code

Code: Select all

On Rules#Timer=1 do
  timerSet,1,5
  let 1,![VAR#1]
  pcfgpio,1,[VAR#1]
endon
creates at 6 second toogle. So its seems to be always a 1 second addition.

But should interpreting this code

Code: Select all

On Rules#Timer=1 do
  timerSet,1,5
  let 1,![VAR#1]
  pcfgpio,1,[VAR#1]
endon
really take precise 1 second? I guess not.

Thank you!

buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Re: Timer adds additional 1 second delay

#10 Post by buzzger0815 » 06 Aug 2020, 10:40

Maybe this is, because in the interpreting code there will be the 1 second timer time added to the current time (including milliseconds) and there will be a comparision with milliseconds.

For example:

1.0000 timer 1 rise
1.0020 create timer 1 adding 1 second = 2.0020 (timerSet 1,1)
2.0000 compare actual time (2.000) with timer raise time (2.0020), nothing to do, because timer raise time is greater than actual time
3.0000 compare actual time (3.000) with timer raise time (2.0020), raise timer

Ends up in always 1 second addtion.

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

Re: Timer adds additional 1 second delay

#11 Post by TD-er » 06 Aug 2020, 11:17

Could be...
The timing of rules execution is not really exact, but it could be the test for the rules timer only runs once a second.
The best way for these would be to have a standard interval timer... which we don't have yet.

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

Re: Timer adds additional 1 second delay

#12 Post by Ath » 09 Aug 2020, 17:15

TD-er added a pull-request implementing a timer with milliseconds resolution, and 2 repeating (loop) timers (no need to restart after the timer fired, with seconds and milliseconds resolutions).
It can be found here: https://github.com/letscontrolit/ESPEasy/pull/3204
There are downloads available from that link for testing, and some examples as well.
/Ton (PayPal.me)

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

Re: Timer adds additional 1 second delay

#13 Post by TD-er » 09 Aug 2020, 20:54

Ah thanks, I wasn't sure where I read about this reported issue (either forum or GitHub).

Indeed, this issue should also be solved by that pull request.

buzzger0815
Normal user
Posts: 21
Joined: 05 Aug 2020, 17:54

Re: Timer adds additional 1 second delay

#14 Post by buzzger0815 » 10 Aug 2020, 11:16

@TD-er

Thank you mate, i'll try the test built! Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests