Else statement not firing after condition ends

Working on some new logic that turns on some holiday lights between November 5th and November 30th starting at sunset. This also changes a system level variable (Holiday Lights) to either true or false which is used in another rule machine automation.

Tonight 10:30pm came around and my else statement didn't fire changing the variable and turning off two lights.

I'm sure this is an easy fix for an experiences rule machine writer.

That's not at all how if/then/else works, or more precisely, that's not how triggers work.

Your rule triggers only once at Sunset -5 minutes. It then runs all the actions, skipping those that don't meet the "if" condition.

Is there something you didn't show in the screenshot that would retrigger it again later? If not, this can't work.

It looks like you can dump the whole if/then statement. Have you first action turn on the lights. Then have an action to wait for the time to be 10:30, then have the next action be to turn off the lights.

The logic flow is one trigger to start the rule, an initial action, a delay until a later time, then finally another action after the delay/wait is over.

1 Like

Hmm interesting, so here is another example of a rule I wrote as well this evening. Which from what your saying isn't going to do what I want either?

Correct - what Alan wrote above is true for that second rule too.

The documentation for RM is pretty darn thorough -- for a better understanding of what triggers, conditionals, and actions are and how they all relate to one another, it's a good reference to have handy (it has a useful index on the right side)...

1 Like

Okay thank you both. I have rewritten the rule with what I think Alan was referring to, if you wouldn't mind confirming this now looks functional?

You can keep it simple with no conditionals.

Obviously you need to fill in the on and off actions. It won't turn off exactly at midnight but you get the idea. It isn't elegant but it is simple.

That latest rule you posted looks like it will work.

Thank you Alan for confirming. I will let it run this evening and if it works I'll update the solution.

So 10:30pm came around tonight and only part of my actions ran at that time. It set the HolidayLights variable to false, but didn't run my off commands?



From reading the logs, it looks like it never even sent the variable change, but I can see it did in my other rule that looks at that variable.

I also confirmed it didn't try issuing any commands to the 3 devices that were supposed to go off as there is nothing in the logs.

The logs for rule 55 show the actions ran at 4:47 and then again at 4:53. Did you open the rule and 'run actions' at 4:53? That's what it looks like, and then it looks like you clicked either "update rule" or "done", which re-initialized the rule at 4:54:43. When the rule re-initialized that reset the wait, so the 10:30 actions never ran. You do have to be careful about updating rules while they have pending waits and delays.

That, however, doesn't explain why your other rule shows HolidayLights going to false at 1030. Is there a third rule that could have set that to false? If not, I'm not sure what's going on.

2 Likes

No there isn't any other rules running that would set that variable to false, that is what has my stumped. I'll see what happens tonight and report back.

After sunset today, click the settings gear icon at the top or rule #55, scroll all the way to the bottom, and look at the scheduled jobs. It should show the scheduled actions for 10:30. Do NOT click update or done afterwards, as that will re-initialize the rule.

(If you do click one of those by accident, you should be able to go into the rule, click "run actions" and then navigate away without clicking update or done. That will re-run the "on" actions and re-schedule the 10:30 off actions

If you go to Settings -> Hub variables and click on the name "HolidayLights" it will show you what apps are using the variable at the bottom of the list. If you haven't looked there already, can you check that and confirm no other rule is using it that might have switched it at 1030?

1 Like