Here's the question:
In an attempt to make my setup as efficient as possible (for me to work with/edit/etc) I like to have everything in one screen/app if possible. So I've got a 'scene' I'm setting up wholly contained in RM rather than bouncing back and forth to scenes, scene activators, etc.
The rule should be triggered by either a switch or 1hr before sunset.
I suppose between the rule being triggered and the conditon test of "time is Sunset-60" it may no longer be Sunset-60 if that check is delayed. One of those maybe/maybe not situations I'd like to make bullet proof. The 'requirement' is to do it all in RM, so I don't want another rule to flip the switch at sunset-60... (I know that's an option, but I'm trying to learn) Is there a more elegant/robust way to handle this than set the action "between trigger time and my randomly chosen sunset"?
First, while I know it may make it "cleaner" to have everything in one rule, there's no reason to stick to that plan. Sometimes, it's easier to split things out. Using a purpose-built app may also be better than doing a rule. I'm not saying this is a bad example of that or a bad idea in this case, just pointing this out in general.
One thing that will make it difficult in this case to keep things all in one rule: what do you want to happen if the switch happens to turn on or off at sunset-60? As-is, say the switch turns off at sunset-30. Right now, that will cause those three lights (or groups) to be dimmed and the shades to be lowered. Then, the same shades will raise. You could solve that specific problem by making your "END-IF" and "IF THEN" in the middle of your rule a single "ELSE-IF" so that either the first or second section but not both will execute. But then you're still left with the problem of what to do if the switch turns on or off between sunset-60 and sunset. You could mitigate the effect of that decision by using a narrower interval here, like just "Time is sunset-60" as a condition, though there will technically be a full minute where this question still remains.
Alternatively, you could get rid of that sunset-60 trigger (and the related condition) entirely--why not just have another automation that turns the "Bedroom - Cozy Sw" switch on or off at sunset-60? I know, I know, it's another automation, but it would be very simple to do with Simple Automation Rules or another Rule Machine rule, and it avoids any of those problems. Otherwise, you might have to live with at least 60 seconds of questionable behavior, but if that's a fine tradeoff for you, there are multiple ways you could address most of the remaining issues, including my suggestion above.
I agree, swimming up stream is a poor choice some/most times... But as I said, I'm trying to learn how-to work with and look at the basic click and shoot rather than hand written code logic and how HE uses that... even though I obviously have a lifetime ticket on the iStupid ride.
That said, are you saying it's the "OR" that's the problem? What I'm looking for is two conditions, "SW-on" OR "sunset-60", either of which would cause the rule to follow that top "IF" logic. Is that not what it would do? I'm confused because I don't see how at sunset-30 and turning the switch off would cause the first "IF" to run.
Maybe this is just an extremely basic operator use question... but I've written a few dozen 200+ line groovy scripts successfully...
Appreciate the help!
I might be missing something too, so I'll explain what I'm thinking and you can see where it doesn't match expectations.
First, as you may know, any event happening on your system that matches anything in your rule's "Trigger Events" will cause the "Actions to Run" to run. So in your case, that's the switch turning on or off (PS - you could save a line and use "changed" here instead of "on" and "off" separately) or the time becoming sunset-60. So let's say that it's sunset-30 (nothing happens at this time on its own) and the switch turns off (this is a trigger, so your actions will run).
Now in your actions, it evaluates the first IF, which is made of two conditions
Switch on? No, so false.
Time between sunset-60 and sunset? Yes (it's sunset-30), so true.
Boolean result of entire IF: False OR True is True, so the actions inside this IF THEN run and dim the lights and lower the shades.
Now we're at the next IF, which also gets evaluated. This has only one condition:
Switch off? Yes, so true.
Boolean result of entire IF: true, so these actions also run, and your shades get raised and (I missed this part before) the lights turned off.
What I suggested above was changing your rule to use this structure:
IF (x) THEN
Do things
ELSE-IF (y) THEN
Do other things
END-IF
...instead of:
IF (x) THEN
Do things
END-IF
IF (y) THEN
Do other things
END-IF
...which would ensure only at most one "section" (the IF itself or any ELSE-IF) will have its contents executed. This at least solves the specific scenario above.
CRAP! Total brain fart! Me-so-sorry! Yes, I get that bit
And that's what the whole question is about... how can I tighten up that time other than guessing as to what time window is appropriate? Ideally I'd like to just say OR SUNSET-60, but it seems possible the system being busy and it being SUNSET-59 before it gets around to the IF so the between is really a place holder for a more certain logic i.e. I'd love to just check a system variable, let's call it - %time_the_damn_trigger_event_happened% against the sunset-60. If they match,... do dat stuff.
And I do get the distinction between END-IF/IF and else-if. In this case, as you point out only one would run with an else-if, but I don't know which since there'd be a true condition in each IF.... so presumably the first and exit.
till I tighten up the time test (which is the question).
You should be able to do "Time is sunset-60" as a condition, which would help with that particular issue (though you'd still have no good way to tell why the actions are running, as the switch could still change state during that minute, too). I say this having not tried it recently--just don't use the "between two times" option--but think it should work. This condition would be true for the duration of that entire minute.
Ah! So its not time to 45th decimal then! Good to know. I started with just the sunset-60 but I've got an older C-4 that really would likely take more than a minute to run... it has issues... but I'm building a new C-7, so my paranoid muscle flexed and I outsmarted myself., but you've convinced me. I'll K.I.S.S.