Dummy TaskValueSet from examples not working

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
thalesmaoa
Normal user
Posts: 31
Joined: 07 Dec 2020, 15:33

Dummy TaskValueSet from examples not working

#1 Post by thalesmaoa » 28 Apr 2023, 04:36

Hello, I've read a lot of posts with related topics. Also checked from docs. However, I can't understand why I'm not able to check dummy var.

Code: Select all

on Rules#Timer=3 do
 if [dummy#var1]=0
   TaskValueSet dummy,var1,1
 else
   TaskValueSet dummy,var1,0
 endif
timerSet,3,2
endon
It always set zero.

Code: Select all

590457: EVENT: Rules#Timer=3,1
590472: TIMER: disable timer
590504: ACT : TaskValueSet dummy,var1,0
590512: ACT : timerSet,3,2
592514: EVENT: Rules#Timer=3,1
592529: TIMER: disable timer
592561: ACT : TaskValueSet dummy,var1,0
594670: ACT : timerSet,3,2

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

Re: Dummy TaskValueSet from examples not working

#2 Post by dr.zorg82 » 28 Apr 2023, 08:27

your third timer starts the third timer? i.e. itself?
Do you also have the setting enabled : tools>Advanced Settings>Allow TaskValueSet on all plugins ?

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

Re: Dummy TaskValueSet from examples not working

#3 Post by Ath » 28 Apr 2023, 08:52

dr.zorg82 wrote: 28 Apr 2023, 08:27 your third timer starts the third timer? i.e. itself?
That's the 'old' way of having a LoopTimerSet command
dr.zorg82 wrote: 28 Apr 2023, 08:27 Do you also have the setting enabled : tools>Advanced Settings>Allow TaskValueSet on all plugins ?
That's not needed for changing a Dummy Device ;)

The Devices page is only updated every Interval seconds, taking into account the lowest Interval, of enabled tasks, that is > 0. By default the Dummy Device has an Interval of 0... and if there are no other tasks, there will be no refresh of the page, or only after 1 minute, if a default Interval of 60 seconds is active.
It might be helpful to add a SysInfo task with an Interval of 1 second to get quick updates.
/Ton (PayPal.me)

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

Re: Dummy TaskValueSet from examples not working

#4 Post by dr.zorg82 » 28 Apr 2023, 09:22

Ath wrote: 28 Apr 2023, 08:52 That's not needed for changing a Dummy Dev
I will know thanks :oops:

thalesmaoa
Normal user
Posts: 31
Joined: 07 Dec 2020, 15:33

Re: Dummy TaskValueSet from examples not working

#5 Post by thalesmaoa » 28 Apr 2023, 12:36

Ath wrote: 28 Apr 2023, 08:52 That's the 'old' way of having a LoopTimerSet command
Thanks, I will look into it.
Ath wrote: 28 Apr 2023, 08:52 It might be helpful to add a SysInfo task with an Interval of 1 second to get quick updates.
Let me see if I get it right. You mean that I need to add a device like this one:
https://www.letscontrolit.com/wiki/index.php/SysInfo

After your tips and some more reading, I found:

Code: Select all

TaskValueSetAndRun
ScheduleTaskRun
TaskRun
TaskRunAt
I suppose that they are all related.

If I replace my code by:

Code: Select all

on Rules#Timer=3 do
 if [dummy#var1]=0
   TaskValueSetAndRun dummy,var1,1
 else
   TaskValueSetAndRun dummy,var1,0
 endif
timerSet,3,2
endon
Will it work?

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

Re: Dummy TaskValueSet from examples not working

#6 Post by TD-er » 28 Apr 2023, 13:03

Please refer to the ReadTheDocs for up-to-date documentation: https://espeasy.readthedocs.io/en/latest/index.html

TaskValueSetAndRun is a combination of TaskValueSet and TaskRun.

A TaskRun will trigger a task to "take a sample", which is a nul-operation on a Dummy task.
But it will also send out the collected data to any connected controller of that task and generate event(s) with the task values.

By default there will be an event per task value, unless you checked the checkbox to send out a single event with all task values at once. (the event will then be named "taskname#All=123.4,567.8,...")

You should also set the initial rules timer. (e.g. at boot)
See for some examples:
https://espeasy.readthedocs.io/en/lates ... rset#timer

The old way was to set a timer and set it again when handling the timer event.
But now we also have the "looptimer" which will be much more consistent and not showing any drift.

For example when you would set the timer again when handling the timer event, it would take some time to parse the commands and also the timer event might be slightly longer in the event queue before it is being handled.
This would then cause a drift in when the next timer would be set.

The loop timer would set the next timer based on the current set time and thus show no drift.

thalesmaoa
Normal user
Posts: 31
Joined: 07 Dec 2020, 15:33

Re: Dummy TaskValueSet from examples not working

#7 Post by thalesmaoa » 28 Apr 2023, 16:46

:o

I see great improvement from the last time I've built a ESPEasy device. I can get a small glimpse of the usage. However, it is better to share my application. From those new features, perhaps there is a better way of performing it.

I have a pump which I remotely turn on. But I want to turn it off after some time using rules.

My problem is that I use

Code: Select all

On Relay#Switch do
  If (timer_not_set)
    Timer set, 3, 180
  Endif
Endon
My problem is that I send one event every 5 seconds. On relay#switch is called every 5s. Thus I'm using Dummy to check (timer_not_set) to not reset timer again.

Is there a better approach?

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

Re: Dummy TaskValueSet from examples not working

#8 Post by Ath » 28 Apr 2023, 19:23

I don't see why there is a problem in resetting the 3-minute timer, if you enable the pump every 5 seconds?
Maybe you can explain why the Relay#Switch event is fired every 5 seconds, and what effect it should have on the timer or the pump?
/Ton (PayPal.me)

thalesmaoa
Normal user
Posts: 31
Joined: 07 Dec 2020, 15:33

Re: Dummy TaskValueSet from examples not working

#9 Post by thalesmaoa » 28 Apr 2023, 21:49

Right! Sorry.

I have a extremely poor wifi connection. I've looked for OpenHab (MQTT plugin), but I couldn't find a way to enable QoS = 1. In order to guarantee a message delivery, I keep sending the value every 5s. Dumb workaround. :roll:
Sometimes I get, others, don't. This is why I need ESPEasy self powerdown the pump.

The problem is that every publish generates an event. This event, in turn, call my routine. I should only start timer when it latches from zero to one. To work-workaround, I was planning to use the dummy#var1.

Thinking louder, I perhaps should publish only inside rules and stop generating events. Any ideas?

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

Re: Dummy TaskValueSet from examples not working

#10 Post by TD-er » 29 Apr 2023, 10:18

You don't need to use a Dummy, you can also store a state in a variable.

Code: Select all

On Relay#Switch do
  If [int#1]=0
    let,1,1
    Timerset,3,180
    // Maybe also set some state/pin???
  Endif
Endon

on Rules#Timer=3 do
  if [int#1]=1
    let,1,0
    // Do whatever else is needed here
  endif
endon

thalesmaoa
Normal user
Posts: 31
Joined: 07 Dec 2020, 15:33

Re: Dummy TaskValueSet from examples not working

#11 Post by thalesmaoa » 29 Apr 2023, 13:59

Perfect! Thank you.

Post Reply

Who is online

Users browsing this forum: No registered users and 94 guests