Where do I put the end-if

I've tried to research this but I keep finding conflicting information. Maybe it's just that there are multiple ways to do it, but that isn't helping me understand.

Can someone explain where the "end-if" goes if there are multiple "IF" conditions? Does it go after each "IF" is done or does it close out the string? It seems to work either way but makes sense to me that it would go after each "IF" condition to close it out specifically.

You should always put one after each if block is finished.
I think this works as all the end-if are together at the end and rule machine seems to not react badly.

I think the only question (for me) is whether there needs to be an extra one at the end of the rule to close off the IF (( Den Can Lights...

Not sure, hopefully Bruce can answer this one for you.

I'm seeing 3 ifs and 3 endifs, and they seem to be in the right place for a normally written program... There does seem to be one closing the Den Can Lights from what I can tell, allowing for the else if in between. Does RM require an Else if there has been an else if? Is that not working for you as it is, @jaredeaves ?

It depends on what you want to happen. :slight_smile: In your case, I'd say you were probably looking to do something like this:

IF (Day in Monday, Tuesday...) THEN
  IF (Den Lights on) THEN
    Off...
  END-IF
ELSE-IF (Day in Saturday, Sunday) THEN
  // ...
  IF (Kitchen Can, Den Can all on) THEN
    Off...
  END-IF
END-IF

The indentation both here and in the RM UI (though with line-wraps, that can sometimes be hard to see) should help as a sort of intuitive guide for this, but an "inner" IF will be evaluated only if an outer IF (one in which it is contained is true)--otherwise, just like any actions inside that IF, it will never be reached to be evaluated in the first place. "Closing" your IF THEN with an END-IF closes that "block," which is what I assume you meant to do with your day-of-week comparison before testing the other days. You can nest these as deep as you need to get the results you want, but if you're going more than a few deep, I'd probably start thinking about if there's a better way or if you did something wrong.

1 Like

What about the IF in the ELSE-IF? WOuldn't that make four IFs and 3 END-IFs?

No, an ELSE-IF is part of an IF THEN block, just like ELSE. It does not "open" a new one or require its own closing (beyond that required by the IF THEN to which it necessarily belongs). My post above shows a correctly formatted example, though the OP is technically also sound from a structural perspective--even if logically that structure probably won't have the desired outcome. :slight_smile:

(This might be particularly confusing in the first post given that the ELSE-IF is highlighted in yellow like the IF ... THEN, so don't let that distract you.)

2 Likes
IF (weekday) THEN
	Fade lights
	On under cabinet
	IF (Den Can Lights on) THEN
		Off Den Can Lights
	END-IF
ELSE
	Fade lights
	On under cabinet
	IF (Kitchen Can Lights, Den Can Lights on) THEN
		Off Kitchen Can Lights, Den Can Lights
	END-IF
END-IF

could try something like this. if your delays were the same time for each day, you could've consolidated the den can lights, but since they're different you'll need a different one for each

the reason i'm using ELSE instead of ELSEIF is because you're either in the weekday or not, so there's no need to specify the other days since they would fall under not being a weekday

This only holds for "normal" conditional actions. A "simple" conditional only allows one condition and one action, does not allow any following ELSE or ELSE-IF conditions/actions, and requires no END-IF.

Yes, a one-line conditional statement doesn't count as a block so doesn't need terminating

2 Likes

That was what I wasn't sure about (ELSE-IF's), thanks @bertabcd1234 and @Inge_Jones.