[Deprecated] Alarm Clock Rule

By the way.
My issue is gone :smiley:
Thanks again!

1 Like

Where in this code can I add an if condition?

I want a script to run at Civil Dawn time, but only if my SceneSelection item == NIGHT

In the “but only if…” section of the rule. Or you can edit the code of the Script Action.

It looked to me like the rule triggering happened at the start of the timer, not just before the script ran.
I want it to check the condition just before it triggers the script.

I think I just answered my own question by saying it out loud. I’ll put the condition in the script I’m running. Duh!

I wasn’t specific in my previous reply. You would add the condition to the “but only if…” section of the rule that is called by this rule. The call from this rule will not bypass the condition.

Although there may be other situations I may not want it in the script. If the rule is being used another time for another purpose and doesn’t need the condition for example

not quite sure my brain is parsing this. You say I should use the ‘Only If’ section of the UI rule and it will be relevant just as the rule is running the script?

There are two scripts.

  1. The rule that is generated by this template.
  2. The rule that is called by the rule generated by this tempalte.

You would add the condition to rule 2. When rule 1 calls rule 2, rule 2 won’t run unless the condition is met.

Ok, that is clear now.
It would be more useful to do this in Rule 1 so I don’t have to make a duplicate rule just to include the ‘If’ because I use the rule else where

Then modify the code to add the test to Rule 1. But if you ever update Rule 1 to pick up changes from the template you’ll have to make that change again.

Note, if you use the rule elsewhere, the second argument to the function to call another rule is a flag to consider the conditions or not. So if you pass false as the second argument it won’t look at the conditions.

How can I do this? Sorry, I’ve been learning DSL and I can’t figure out this Javascript

I will save my rule to a text file when it’s set.

Or you can update the Marketplace template to include this as an optional setup field :wink:

If you can’t figure out how to add an if statement to this code it’s probably best not to modify it. You should either have two rules like you mentioned before or write your own version of the Alarm Clock Rule in Rules DSL that you do understand and can customize as you see fit.

Rules created from a rule template cannot be saved to a text file. You’d have to rewrite it, in which case you may as well write it as a text file in the first place.

This is a really niche requirement and implementing it well would be very complicated. I’m not included to do that since using the condition on the called rule handles 99% of all use cases.