Q about Timerset

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Q about Timerset

#1 Post by BartSr » 16 Oct 2023, 20:18

Hi,
Hereunder a simplified piece of code in rules.
I want to Publish domoticz to be executed every 10 seconds.
I had expected this code works but no, it does not.
What is wrong?

-Bart

Code: Select all

On System#Boot do 
   timerSet,1,10
endon

On Rules#Timer=1
   Publish domoticz/in, '{ "idx":985, "svalue":"0;0;0;[Energy#Wh];[Power#W];0"}'
endon

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

Re: Q about Timerset

#2 Post by TD-er » 16 Oct 2023, 20:47

You should either set the timer again when dealing with it, but this will eventually drift as the new timer is set when the event is being processed.
So the better option is to use looptimer :)

See: https://espeasy.readthedocs.io/en/lates ... l-commands
And: https://espeasy.readthedocs.io/en/lates ... oop-timers
The latter one is probably the most usable as it includes examples.

N.B. there are 2 variants, one of them ending with _ms indicating the time unit is in msec.

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Q about Timerset

#3 Post by BartSr » 16 Oct 2023, 22:06

TD-er I tried , following example but without good result.
What is wrong?

Code: Select all



 On System#Boot do    //When the ESP boots, do
       looptimerset_ms,2,2500
 endon

   On Rules#Timer=2 do 

   Publish domoticz/in, '{ "idx":1009, "svalue":"[Energy#Wh];0;0;0;[Power#W];0"}'


endon

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

Re: Q about Timerset

#4 Post by TD-er » 16 Oct 2023, 22:16

Did you reboot?
Or give the command via the tools page?

Code: Select all

looptimerset_ms,2,2500
By the way, this will call the loop timer every 2.5 sec, not the 10 sec you mentioned before.

Just did some cleanup on your rules and added a logentry call so you can check whether it is working and what it is sending:

Code: Select all

On System#Boot do    //When the ESP boots, do
  looptimerset,2,10  // start timer #2 every 10 seconds
endon

On Rules#Timer=2 do 
  LogEntry,'Publishing: { "idx":1009, "svalue":"[Energy#Wh];0;0;0;[Power#W];0"}'
  Publish,domoticz/in,'{ "idx":1009, "svalue":"[Energy#Wh];0;0;0;[Power#W];0"}'
endon

BartSr
Normal user
Posts: 122
Joined: 27 Sep 2019, 17:45

Re: Q about Timerset

#5 Post by BartSr » 17 Oct 2023, 18:29

Hi TD-er.

I changed my code to a 2.5 sec interval just for some faster checking. In final version 10 sec will be used.

It seems that I overlooked to reboot. After that the rule worked ok.
Regarding the logentry you added,( I still need to include) but what is the advantage? I use to have a look at the log which shows up after selecting that option. This also shows me if the looptimer works.

Anyway, thanks for your time and help.
Bart

update: I googled on 'logentry' and I think to understand. so going to play with it for my understanding

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

Re: Q about Timerset

#6 Post by TD-er » 17 Oct 2023, 20:16

The logentry was for you to help diagnose the issue.
It will also replace all variables in the string before adding it to the log, so you can see what is actually being sent.

Logentry is very useful for debugging rules.

Post Reply

Who is online

Users browsing this forum: No registered users and 45 guests