timer remaining time

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Ouzo2020
New user
Posts: 4
Joined: 14 Dec 2020, 16:33

timer remaining time

#1 Post by Ouzo2020 » 14 Dec 2020, 16:40

Hi,

I have some long time (20 min or more) running timers started with rules via http.
Is it possible to ask via http the remaining time of each?

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

Re: timer remaining time

#2 Post by TD-er » 14 Dec 2020, 17:21

Not directly, but you could store the number of seconds of the current day in a variable when setting the timer.
Then you can subtract the stored value from the current value of %syssec_d% in an event handler block.
By triggering such an event you can output the difference (or store it somewhere like in a dummy)

Ouzo2020
New user
Posts: 4
Joined: 14 Dec 2020, 16:33

Re: timer remaining time

#3 Post by Ouzo2020 » 15 Dec 2020, 08:41

Thanks for your answer. But its not clear for me:
I have in Rules (from the examples):

On startwatering do
gpio,12,1 //start watering (open valve)
timerSet,1,600 //timer 1 set for 10 minutes
Let,1,%syssec_d%
endon

1) %syssec_d% is not listed in https://www.letscontrolit.com/wiki/inde ... _Variables , is this usable ?

2) How can I ask via a http call the Variable ? I didnt find anything ...

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

Re: timer remaining time

#4 Post by TD-er » 15 Dec 2020, 09:01

See on the web interface the list of System Variables.
There all variables are shown and their current values. (at the moment the page is loaded)

It depends a bit on how you would like to retrieve the value.

For example if you want to send it to a logentry:

Code: Select all

on timerleft do
  let,2,%syssec_d%-[int#1]
  LogEntry,'Timer seconds left: [int#2]'
endon
After calling: event,timerleft

Code: Select all

137038 : Info   : HTTP: event,timerleft
137128 : Info   : EVENT: timerleft
137165 : Info   : ACT  : let,2,32299-32249
137172 : Info   : ACT  : LogEntry,'Timer seconds left: 50'
137178 : Info   : Timer seconds left: 50
But you can use the computed value in just about anything.
For example publish it to a MQTT broker, use it in an URL for a HTTP GET call, show it on a display, etc.

Ouzo2020
New user
Posts: 4
Joined: 14 Dec 2020, 16:33

Re: timer remaining time

#5 Post by Ouzo2020 » 15 Dec 2020, 11:01

Sorry, I don't underdstand.

I call from the Browser http://easy_ip/control?cmd=event,timerleft and the whole respond is OK. How I get the Var content ?

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

Re: timer remaining time

#6 Post by TD-er » 15 Dec 2020, 11:41

That is not (yet) implemented, to query a variable via a HTTP GET command.
You can trigger an event to collect a value, which then can be used to send it somewhere, but for now it is not possible to return it to the originator.

It is however a nice idea, so I'm thinking of how to do this.

Problem is the events will be scheduled, so you can't give a reply immediately back to the sender of the event.

So I guess the only way to achieve this is to create a new command which supports some basic computation and returns the result of it immediately.
It really isn't as simple as it sounds as we have a very good reason to schedule the events and not execute them immediately.
This reason has to do with stack usage.
If you handle an event, you may use quite a bit of stack, so you must make sure it is always called from the same point or else handling the event from different sources may work fine when called from source A and no longer when called from source B.

When we allow for parsing values and compations, you essentially are executing a single line of a rule.

To summarize; I like the idea (a lot) but I'm not entirely sure yet how to implement it.

Ouzo2020
New user
Posts: 4
Joined: 14 Dec 2020, 16:33

Re: timer remaining time

#7 Post by Ouzo2020 » 15 Dec 2020, 11:55

maybe its easier to implement the var-values in the json respond ?

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

Re: timer remaining time

#8 Post by TD-er » 15 Dec 2020, 13:18

That's a good suggestion.
We already have something similar for accessing specific plugin data, so if you store it in a dummy via rules, then you can already access it like that.
See: https://espeasy.readthedocs.io/en/lates ... ht=csv#csv
And to set the value in a Dummy task, see the command "taskvalueset"

Post Reply

Who is online

Users browsing this forum: No registered users and 135 guests