I am trying to turn on a light if a contact sensor is trigger AND it is night. Every time I try to create a rule it only seems to allow OR options. How do I do an AND option?
I am trying to do this with Rule Machine 5.0.
I am trying to turn on a light if a contact sensor is trigger AND it is night. Every time I try to create a rule it only seems to allow OR options. How do I do an AND option?
I am trying to do this with Rule Machine 5.0.
I suggest using Predicate conditions, with Mode being Night.
Then use the contact sensor as trigger.
It will respond as you expect.
To expand on @BiGs solution, and your original question about AND and OR options within Triggers....
You should see triggers in a rule as events, things that happen at a moment in time, e.g. a sensor detecting something, time ticking over to 5pm, etc. So with that in mind it does not make sense to have a rule that would trigger on two events happening at exactly the same time.
In your case you are wanting one trigger / event and a condition applied as to whether the actions should run. Prior to the introduction of predicates, this was commonly achieved by still using, in your case, one trigger for the rule, then including conditional actions inside the rule to handle the mode being night, or potentially using restrictions, but I can't remember if they still exist...
My understanding is that when you create a rule, the HE system then starts to watch out for the various triggers that are used in your rule, when you introduce a predicate this controls when the HE system watches for these trigger events occurring.
There was also a lengthy discussion about this last year, I can track down the thread if you want.
In the trigger section all triggers defined will be an OR as they may not happen at the same time. Also you may want 1 of 3 triggers to cause a rule to be evaluated.
You then define what actions you want in the main rule.
So in the triggers you would have
MODE CHANGED
OR
MOTION CHANGED
In actions you would have.
MODE IS NIGHT
AND
MOTION ACTIVE
THEN
Do your stuff.
This means that either trigger will cause the rule to be evaluated and if BOTH are true the rule will fire.
This is not an good example of a rule but hopefully a reasonably good explanation.
I'm not sure @silverton38 needs the rule to trigger when the mode changes to night, just that the rule only runs when the mode is night. But the conditional action is certainly one valid option for achieving this.
This may well be true.
I was hopefully showing that any trigger will cause the rule to fire.
So if the motion sensor is active and during this active period the mode changes to night the light will turn on.
I wasn't trying to write a rule but hopefully explain how a rule constructs.
Ah, I get it now, and actually a scenario I hadn't thought of, good pickup...
Typically in the other hubs that I use you have an OR or AND option. The Rule machine 5.0 seems to be locked to OR. Is there any way to have an AND option like other hubs have?
I am used to Homeseer and ISY. I am new to Hubitat
The has to be some way to have an AND option
If Zone 2 is violated
and mode = Night
then turn on Light
Does anyone know how to do this in Hubitat?
But you can with HE in your actions. You cannot in your triggers because it is just that, a trigger to get the rule evaluated. This is then done in the actions where you have a multitude of options.
Here is one of mine.
Above this I have triggers that, as said above, cause the rule to be evaluated. It triggers it. It then moves on to the actions where the rule is actually evaluated.
I think you may be getting stuck in the trigger part and not moving forward. Not sure though.
Knocked this up quickly and no doubt others with chip in with other, and probably better ways of doing this.
If mode changes to night (trigger) OR Motion changes (trigger) then the actions will be evaluated.
If both in the IF are true THEN the rule will cancel any schedules/timers in this rule only that may be active and turn on the light.
If either of the triggers now change again (mode or motion) then the rule will be evaluated again and if evaluated to false the ELSE will run and turn the light off after 30 seconds. (scheduled by the rule).
If another trigger occurs in the 30 second count down then the rule will be evaluated again. If true it will cancel turning off the lights and wait again for another trigger.
Hope this makes sense.
Here's another way using the predicate condition.
As previously mentioned, a trigger occurs in an instance in time regardless of how other hubs treat it. So for a rule to ever trigger based on above, then Zone 2 would have to be violated at the exact same instance in time as the mode changes to Night which is impossible and definitely not the criteria you want. For this example, your trigger is simply "Zone 2 is violated" and your action is "If mode = Night, then turn on Light. It might not be how you want to do it but it is how the RM framework works.
The idea is to turn on a light when the Zone is violated but only do it after sunset and before sunrise. How would I do this in the rule engine?
Thank you so much. That is exactly what I am looking for. I will figure this hub out pretty quickly.
My issue was that I needed to choose conditional actions.
Thank you again.