Rule machine triggering if and else if at the same time

Hello
New to Hubitat. Guessing I'm doing something wrong with rule machine. It seems to be triggering the if and else if at the same time which shouldn't be happening.
What I'm trying to do is to turn on the light then turn it off after a minute. If the button is clicked while the light is on then turn it off.
On every click it triggers the IF then instantly triggers the ELSE IF which should only happen on a second click.

You have the master dimmer turning on as a trigger.
So when the light turns on, the rule re-triggers.
As the light is on, the ELSE-IF will be true and turn off the dimmer.
Remove the light turning on trigger and see if it works OK.

1 Like

I thought that could be the reason and removed the second trigger (I have this as the dimmer is also a switch) but still same issue.

Change the Else If to Else. There’s no point in having the converse of an If as a test on an Else if. But that won’t change the re-triggering issue.

I have it as else if because I will still be adding more options. Let me try if it works then I'll just nest the other parts within the initial IF

Ok, realize that, by de Morgan’s theorem, the negative of the initial if ... and ... acts as an or of the conditions.

As to your original question, realize that if the time is outside your time range, the first if ... and ... is false regardless of the state of the dimmer, so testing the dimmer could cause the else-if to be executed if the dimmer is on.

That is saying my above comment a different way.

I’m not sure what you are trying to do, just pointing out your logic and your question.

I think you made need to use a variable to get it to work with a button.
Define a local number variable.

TRIGGER
Button pressed.
ACTION
IF
Button pressed set var button +1.
IF Time between x and y AND var button=1
THEN
DIM stairs dimmer.
OFF delayed 00:01:00 (cancelable)
Set var button = 0
ELSE-IF
var button = 2
THEN
Off dimmer
Cancel delayed actions
Set var button = 0.
END-IF

I think this may do what you want.

Thanks Bobbles. will give it a go.
Switching to and else statement still didn't work.
Will share a shot of the log as it seems very weird on how it can trigger an IF and an ELSE at the same time. I would assume this means it's triggering the rule twice.

Not sure I understood what you are trying to say. I am aware the if the time is out of range, the first if will be false and not trigger. I will be adding further statements for other times.
In regards to what I'm trying to do I explained it in the initial question.
What will be added further to the rule are other time of day to adjust brightness accordingly.
Will share a more complete rule of what I'm trying to do to clear things up.

Even trimming the condition to a very simple if off then turn on else turn off is not working.
As @bobbles pointed out, I believe this will require a variable.

Yeah. My thinking is a button is a momentary press not a toggle on and off.
Using a variable should do what you want. I think. :crossed_fingers:

What type of button are you using? Some ST Buttons were known to send double events that would cause behavior like you're seeing. Take a look at the EVENTS of the Button device to make sure you're not get multiple events for each button push.

1 Like

No, the issue is with the rule. Even when I trigger it by clicking "Run Actions", same issue happens

Any chance you have another rule that is triggered by the "Master Stairs Dimmer"? Enable Debug logging in the rule and monitor the Live Logs when the rule is run.

Personally I think what is happening, I'm probably wrong, is...........
Button gets pressed.
Rule sees this as a trigger. State of button becomes pressed (true) in the rule.
Light turns on. (State of button is still true).
ELSE now becomes true and light turns off.
Some seconds later button pressed turns to false.
Just my hypothesis (big word for me) which is probably wrong.

There is no True or False to a Button 'pushed' event. It is a one time, instantaneous event. Which is why I asked the user to show the EVENTS from the Button Controller Device page. It will tell us if there are duplicate events being generated, or just a single 'pushed' event.

1 Like

I appreciate this but I'm talking about within the rule. When the button is pressed does it become true within the rule so therefore the rules 'fires'. I now it was mentioned in the early days that triggers are either true or false. I believe they hold that state for a brief time then revert back to false. All within the rule. Nothing to do with the button.
Probably totally wrong but that's how I assumed it worked.

I think you may be recalling the pre-RM4 days, where rules had a TRUE and a FALSE section to them.

In RM4, a trigger is just an event - it has no true or false component. A trigger either has occurred, or it has not, based on the events the Rule is subscribed to. If an event does happen that the rule is subscribed to, the the Actions section is run one time.

1 Like

No. First rule for this dimmer. I have the debug enabled and as @bobbles pointed out below it seems what is happening is the IF is getting triggered then goes on to the ELSE, which should be a big no-no. Once the IF conditions have been met, everything after that should be ignored.

So the rule is getting triggered twice. It seems maybe it is not over writing the initial trigger that was declared. When the dimmer switches on then it's triggering again (even though this was removed from the rule).


I deleted the old rule and created a new rule and wrote the exact same conditions and it worked fine. So it seems the issue was the first rule when I created it with a certain trigger, even after deleting the trigger and updating the rule it was still using the trigger for some reason.


2 Likes