Rule Machine with AND condition

I need a simple rule but can not find a way with the rule machine.
Let X be a light(device)
Let Y be a dimming value.

If time == sunset-15 and X is OFF
set X to Y

Under some conditions when the time is sunset-15, the light X is at a dimming value other than Y. Under those circumstances I don't want the light level to change, but in general at sunset-15 I want the light to come on at the dimming value Y.

2 Likes

This is actually pretty simple, as shown in the example below:

Here's a brief explanation. Hubitat automation is event driven. A particular time is a unique event (for that date) and can serve as a trigger.

Device state is not an event, whereas a change in device state would be an event. By this I mean that the state of "being off" is not an event, whereas the act of "turning off" is an event.

States can be used in conditions. Conditions can either be incorporated into a Rule, as indicated by @kahn-hubitat's example above. Alternatively, they can used in a Required Expression, which is slightly more efficient.

You can incorporate these conditions into the Required Expression.

3 Likes

I find the Rule Machine interface obtuse, unfortunately. I actually need the following:
IF (mode in (Guest,Home) AND Light OFF AND
(time == sunset -15 OR time = 5:45 PM)
THEN
set light dimmer = 40%

The image shows that I can't set a specific time, but must choose 'Between two times". I need to get to the example above. No matter what I have tried I eventually get to the place where I can't select specific times in the OR condition.

The triggers should be the time. 2 triggers one for each time case. It should not.be a required expression. That can be for other stuff or you can have an.if inside the rule.

2 Likes

You don't want all that logic in Required Expression. Instead, that should be a conditional action.

2 Likes

Thanks. The time as triggers works. The two images show the progression of the example.

Image-1 shows the triggers and the action that results but not the conditions for the action. Image-2 shows the data for the Conditions. I don't see anywhere to view the entire Rule.


You need to put the conditions inside and if/endif

What you have there just pre-defines the conditions, but they are not used yet. Or you can put them in a required expresion

1 Like

That is very reasonable but where do I get the the if/then/else/endif syntax?

In action add conditional action.

Also.some lights don't come on with only a dim. You may need to add an switch on action if needed.

Does this look correct?

Yep but see comment above.

Like this?

You can test it . You may not need it. But if needed i would put it after the dim so that level is set before it turns on and you don't see flashing as it changes. Although what you have would work fine in either case.

I will test it later today by changing the 5:45 pm to so value close to the current time. That will also all me to test the switching requirements.

Thanks very much.

1 Like

For my switch, a GE Enbrighten wall switch, the dim command works perfectly without the other actions.

I still find it confusing that the Trigger events are added first but the required expression show up above them when complete.

Thanks again.

Well as mentioned you can put an.end.if in the rule.actions instead of the required expressions then the triggers are u.top and the.rule.is.all together.
.

There is some history to Required Expression. Initially it wasn't part of Rule Machine. You only had Triggers and Actions. It was added much later on as a request to limit when a rule could run.

  • Required expression is to prevent triggers from occurring. It filters events from getting to the Triggers. These are not part of the rule exactly. It is not meant to be used as a catch-all, or for IF-THEN logic or anything like that.

  • Triggers are events that sets the rule into motion.

  • Actions are what you want to happen, and how they should happen.

Not sure if you have read the documentation Rule 5.1 | Hubitat Documentation, or watched any of the RM videos on Youtube https://www.youtube.com/@Hubitat/videos, but they can be quite helpful.

3 Likes

I am beginning to get the concept, but looking at the Required Expression and the Trigger Events a number of interpretations are possible.

If 'Required Expression' is TRUE AND one of the Trigger Events occurs, THEN execute the Action.
Or...
If 'one of the trigger events occurs' AND the Required Expression is TRUE, execute the Action.

I fully grasp the Event Driven Nature of the code, another automation system I used some time ago worked similarly(HAI purchased and ruined by Leviton).

I also spent may years writing Fortran, C, C++, Java etc. code so my mindset originates from the program flow of those languages. I just need some time to adjust to Hubitat.

I think I need to read the full documentation!