Don't turn off if already on in RM

Some background - In my bathroom, I have a Hue motion sensor, three Hue GU10's, and a Sonoff switch controlling the extractor fan.

What I'm trying to achieve is for the fan to trigger every time someone enters the bathroom and for the lights to turn on if the lux is below 30 and with a different dimmer level for modes Day, Evening, and Night. The exception handling being don't turn the lights off if already on.

I've created a Motion and Mode App to control the lights and a Simple Automation Rule to control the fan, both triggered by the motion sensor. Both of these work exactly as I want them but I have been looking into creating a single RM app to do both.

My questions are:

1/ The logic for merging is to improve efficiency. My question is: Should I bother?
2/ My approach for the exception handling was to create a variable and capture the state of the bathroom lights when motion was detected, then depending upon this boolean variable it would either just turn the fan off and both the fan and lights. The problem I have is that if motion triggers the rule twice, it assumes the lights were on initially and so doesn't turn them off.

I've now deleted the RM rule and reverted back to the two separate and much simpler rules but it's bugging me that I couldn't work out a single rule. :nerd_face:

As I say: Is this possible and should I bother? :thinking:

As a general rule, the best practice is to K.I.S.S. (keep it simple stupid :wink:). Using two rules to achieve what you want is sometimes the best option especially when they operate different types of devices. Although in your case it would seem a rule that is based on a single trigger (motion) wouldn't be that complex in RM either.

That being said, RM is a much "heavier" app, it's designed to allow much more complex rules, If you can achieve what you want with one of the simpler apps then that's fine too.

EDIT: I just realized you specified not turning on the light if it's already ON, in that case you would need a slightly different RM rule for the 2nd action using a "Conditional IF-Then-End" based on the current switch state and room illumination.

Thanks for the reply. As you'll see from my profile, I'm well used to the concepts. Albeit I've grown a bit distanced from the coding over the last 22 yrs. :slight_smile:

I have to admit I am unsure of the command 'Wait for Event'. Does this stop the rule from being triggered again by any additional motion? (or whatever the trigger definition is for a specific rule)

My issue was if the rule gets triggered every time the trigger condition is met, then having an If statement that checks the state of the switch becomes irrelevant on the second trigger if the lights are still on from the first trigger...

"Wait for event" stops the action execution until the next event occurs, but does not stop the rule from being triggered again. If it's triggered again the "wait" is canceled.

While I understand your desire not to turn on the light if it's already on, in practice I haven't observed a real-world improvement from trying to eliminate the redundant command.

The hue motion sensors have an adjustable motion reset that could help prevent the rule from being triggered so often, or you could use the "zone motion controller" application to create a "virtual" motion sensor that has a much longer reset.

1 Like

That was my understanding, I'll leave it with the two apps...

1 Like