Rules - Retrieve info if task is active or not

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Rules - Retrieve info if task is active or not

#1 Post by chromo23 » 17 Dec 2022, 16:30

Is there any way to get the status (enabled/disabled) of a task in rules ?

What I use at the moment is a bit cumbersome.
These are the current events that are generated when enabling or disabling a task:

Code: Select all

ACT : TaskDisable,4
EVENT: TaskExit#Device=4,0

ACT : TaskEnable,4
EVENT: TaskInit#Device=4,1
I can use these to save the state somewhere.
(btw: the last numbers of each event are a redundancy since "Exit" and "Init" are unique events that already tell the state.)

This could imho be improved to

Code: Select all

TaskState#Device=1or0
or

Code: Select all

Task#State=4,1or0
Last edited by chromo23 on 17 Dec 2022, 17:41, edited 1 time in total.

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

Re: Rules - Retrieve info if task is active or not

#2 Post by Ath » 17 Dec 2022, 17:37

We have been brainstorming about this for a bit, some time ago, but didn't make any decisions yet. This is a trigger to get the priority up a bit :D
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#3 Post by TD-er » 17 Dec 2022, 19:26

(btw: the last numbers of each event are a redundancy since "Exit" and "Init" are unique events that already tell the state.)

Nope it isn't.
PLUGIN_TASK_INIT may fail.

But the enabled state should also be available in the JSON, isn't it?

Anyway, we do have some recently extended feature for tasks to get some values other than the taskvalues.
Original inspiration was the getLevel from the Level plugin.
[taskname#getlevel] would then return the set level, even though that isn't a taskvalue name.

We can do the same for [taskname#enabled] and [taskname#disabled]

So in short:
[taskname#taskvaluename] = current value of the task value.
[taskname#taskvaluename.foo] (added for task stats, like .avg, .max, etc.) is a derived value of a taskvalue
[taskname#bar] = some task specific value which isn't present as a taskvalue. (e.g. getlevel for the Level plugin, and the GPS plugin has all parameters made available via such calls)

Does this introduce some ambiguity or does it make sense?

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

Re: Rules - Retrieve info if task is active or not

#4 Post by Ath » 17 Dec 2022, 19:57

We could use a somewhat fine-tuned approach, using a . prefix:

[taskname#.enabled] = 0/1 for disabled/enabled
[taskname#.interval] = current value for interval
[taskname#.valuecount] = the number of values available in the task

This has the advantage of these special value name being unique from the usual value names, where a period prefix would be, well, strange, and also recognizable as special values.

Rule:

Code: Select all

 LogEntry,'ST7796: [st7796#.enabled#O#C]/[st7796#.interval] SysInfo: [SysInfo#.enabled#O#C]/[SysInfo#.interval]/[SysInfo#.valuecount]'
Output:

Code: Select all

344936 : Info   : ACT  : LogEntry,'ST7796: On/0 SysInfo: Off/60/3'
344939 : Info   : ST7796: On/0 SysInfo: Off/60/3
Last edited by Ath on 17 Dec 2022, 20:01, edited 1 time in total.
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#5 Post by chromo23 » 17 Dec 2022, 20:01

TD-er wrote: 17 Dec 2022, 19:26 But the enabled state should also be available in the JSON, isn't it?
It is and i am using it in easyfetch.
But i also would need an option for rules based on the state.
TD-er wrote: 17 Dec 2022, 19:26 Does this introduce some ambiguity or does it make sense?
It makes almost totally sense...
TD-er wrote: 17 Dec 2022, 19:26 We can do the same for [taskname#enabled] and [taskname#disabled]
Here only one event is needed right? Like [taskname#enabled]=1 for enabled and =0 for disabled.
Why the [taskname#disabled]?

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

Re: Rules - Retrieve info if task is active or not

#6 Post by chromo23 » 17 Dec 2022, 20:06

Ath wrote: 17 Dec 2022, 19:57 This has the advantage of these special value name being unique from the usual value names,
i agree...
Ath wrote: 17 Dec 2022, 19:57 We could use a somewhat fine-tuned approach, using a . prefix:
since a point represents hidden files in unix/linux environments i would at least make sense for me.. so like the hidden values

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

Re: Rules - Retrieve info if task is active or not

#7 Post by Ath » 17 Dec 2022, 20:14

In AdafruitGFX_Helper and the PRs for P137 and P138 (and others) I have also used the 'GetLevel' approach to make all usable values available, mostly because of the limit of 4 taskvalues, making it easier to use any available value from plugins.
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#8 Post by Ath » 17 Dec 2022, 20:15

chromo23 wrote: 17 Dec 2022, 20:06 since a point represents hidden files in unix/linux environments i would at least make sense for me.. so like the hidden values
I can relate to that :)
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#9 Post by TD-er » 17 Dec 2022, 21:29

But then the argument for "derived" values for taskvalues no longer makes sense.

It is after all a property or value of the task, thus [taskname#enabled] then makes more sense.
You could use an _ to indicate it is like a state of the task, but I think this will be confusing as we also don't do it for the "getValue" kind of requests.

I do agree that #disabled isn't needed.
After all, the checkbox is also labelled "Enabled".

Maybe we should check and see what other "get" types we have.
Perhaps we can then opt for [taskname#setting.enabled] ?
This way we have only a single keyword which may not be used as a taskvalue name (or else this functionality cannot be used)

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

Re: Rules - Retrieve info if task is active or not

#10 Post by Ath » 17 Dec 2022, 21:58

TD-er wrote: 17 Dec 2022, 21:29 But then the argument for "derived" values for taskvalues no longer makes sense.
It's just the derived value of the task, without the taskvalue (name) ;)
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#11 Post by TD-er » 17 Dec 2022, 22:04

But it isn't a derived value, it is a setting.

A derived value is something which is... derived from other values.

For example if you have temperature and humidity, then you can derive a dew point temperature.
Average value is also a derived value as it is derived from the previous values.

But a setting like "enabled" or "interval" isn't a derived value.

When using a '.' in [taskname#settings.enabled], we can also describe it as a property or a member, like in programming languages.
But [taskname#.enabled] is rather confusing.

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

Re: Rules - Retrieve info if task is active or not

#12 Post by Ath » 17 Dec 2022, 22:07

That makes sense to me, I'll adjust my code :)
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#13 Post by chromo23 » 17 Dec 2022, 22:21

TD-er wrote: 17 Dec 2022, 22:04 [taskname#settings.enabled],
That’s even better since it is more logical despite the fact, that it has a bit more text!

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

Re: Rules - Retrieve info if task is active or not

#14 Post by chromo23 » 17 Dec 2022, 22:24

Ath wrote: 17 Dec 2022, 19:57 [st7796#.enabled#O#C]
What does the "#O#C" do?

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

Re: Rules - Retrieve info if task is active or not

#15 Post by TD-er » 17 Dec 2022, 22:25

And we can use it globally on all tasks, so no need to have it implemented in specific tasks.

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

Re: Rules - Retrieve info if task is active or not

#16 Post by TD-er » 17 Dec 2022, 22:26

chromo23 wrote: 17 Dec 2022, 22:24
Ath wrote: 17 Dec 2022, 19:57 [st7796#.enabled#O#C]
What does the "#O#C" do?
Probably related to this: https://espeasy.readthedocs.io/en/lates ... sformation

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

Re: Rules - Retrieve info if task is active or not

#17 Post by Ath » 17 Dec 2022, 22:28

I also added
[taskname#settings.controllerN] where N can be 1..3 (CONTROLLER_MAX actually) to get the enabled/disabled state per task per controller

Formatting code O = ON/OFF, Justification option C is First Capital, so the result will be On or Off
/Ton (PayPal.me)


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

Re: Rules - Retrieve info if task is active or not

#19 Post by chromo23 » 17 Dec 2022, 23:09

Just testet it...great!
So this specific problem here is solved for me. Thanks a lot.

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

Re: Rules - Retrieve info if task is active or not

#20 Post by Ath » 18 Dec 2022, 15:08

Would there be a need for having the [taskname#settings.controlleridxN] values available, for the controllers that support that (only for the Domoticz controllers, I think)?
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#21 Post by TD-er » 18 Dec 2022, 15:56

Yep, add them.
But perhaps the more clean way to have these is something like
[taskname#settings.controllerN.enabled]
[taskname#settings.controllerN.idx]

etc.

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

Re: Rules - Retrieve info if task is active or not

#22 Post by Ath » 18 Dec 2022, 16:18

Yes, that's a great suggestion :)
/Ton (PayPal.me)

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

Re: Rules - Retrieve info if task is active or not

#23 Post by chromo23 » 18 Dec 2022, 18:21

And now the only (of course not) thing missing is a command to get the pinstate/value of a pwm pin. (and a json entry for that too)
:D

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 59 guests