Rule Machine is eating my lunch

I am getting frustrated quickly with the Rule Machine. I am trying to make a simple rule to turn a light on if the front door sensor is opened or the motion sensor is active after dark. Something is not making sense to me. My front page looks like this:


and my Actions page looks like this:
Shouldn't the Condition "Time between Sunset -30 minutes and Sunset " be listed on the front page with the Actions.
I am very confused.

"Manage or Create Conditions" is just a bank where you can create conditions to use later (and where ones you create on the fly in a rule will also appear, and also creating most triggers will automatically generate a condition under the assumption you might want to use it later, saving you time). They don't do anything on their own unless you use them.

For how to use them, what you want are conditional actions. There are two kinds, a simple conditional (one condition only and one action/line only--will just say IF...) or a "regular" conditional (will show a complete IF...THEN and require an END-IF to close with arbitrarily many actions in between). These two videos from Hubitat's YouTube channel may help:

There are also several examples of conditionals in the Rule 4.0 docs, which I'd recommend reading (they won't help you if you can't figure out the UI-- a bit awkward at first--to make them, which the videos will show).

That being said, what I'd probably do in your case instead is use this example app by Hubitat to convert a contact sensor into a motion sensor: HubitatPublic/contactMotion.groovy at master · hubitat/HubitatPublic · GitHub. Then, use both of these "motion" sensors with Simple Automation Rules, Motion Lighting (probably your best option here), or another motion-lighting app that meets your needs without the hassle of creating a rule. That being said, RM would obviously give you the most power, and there's nothing wrong with learning.

Good luck either way, and feel free to ask more if this doesn't make sense!

2 Likes

Thanks, I have watched quite a few videos and they looked pretty straight forward when the guy is doing them. It seems like I don't get the same results. You have cleared up one thing about simple and if-then conditions. I was unclear on making them up and then using them. I will watch the videos again and give it another shot.

Why aren't you using the much easier Motion Lighting app?

Because if I am going to make complex rules someday, I need to learn how. I thought I would start with something simple. You can see how that turned out.

1 Like

Keep your triggers and conditions. Except you have a weird thing in the sunset condition where you have sunset -30 and sunset. I don't think that is what you really want. You can delete and recreate, or edit that.

In actions, use a conditional action.

IF time is between sunset -30 and sunrise
THEN on living room outlet
ENDIF

I will give that a try. I can achieve this by using Motion lighting app and Simple Automation app by making a rule in each app for each trigger.

A few YouTubers that I find helpful with Hubitat are.
TechBytes with Ron Nutter..... YouTube
KMM Tech...... YouTube

There are more, but those are the two that I always found very helpful.

1 Like

Yea, I have been watching a bit of everything. I understand about triggers, actions and conditions but have problems getting the conditions into the rule.

1 Like

The simplest way I think starting out is to not make the conditions you want in the conditions options first.
When you insert conditional actions there is the option to create new conditions and this way you can be sure they are being used.

I will keep that in mind.

I, like you, wanted to learn Rule Machine because I had a desire to make more complex rules and I wanted to start with a simple one. It took a while, but I feel I am at the reasonably competent level now; Rule Machine doesn't eat my lunch anymore, but sometimes I see it following me home from school with a nasty look in its eye.

Seriously, let's start by looking at what you've done so far, what you expect it to do, and fix the gap between those things. You said you want the rule to work after dark and that it should be based on two different sensors and either one can set off the rule. Good so far. The rule you wrote in the OP should be turning on your Living Room Outlet whenever either the Front Door Sensor is "open", the Living Room Motion Sensor is "Active" or both. If that's not happening, you have a problem that has nothing to do with the rule.

Okay, assuming that trigger is working correctly, before you make your conditional rule for the Living Room Outlet only turning on "after dark" you have to decide how you are going to define "after dark". You could do as you've done, and set a time on it (although note that in the posted example, this rule would only work in the 30 minutes before sunset until sunset; as @neonturbo mentioned, this probably should be until sunrise. However, if you are using modes, and one of them fits your scenario appropriately, you could use that as your conditional trigger. You could also use a light level sensor to decide what "dark" is. But, you used sunset, so let's stay with that.

You want to encapsulate your action within a conditional IF-THEN statement. This way, the rule will process based on the triggering event (the motion sensor or the door sensor being activated) but the ACTION will only fire if it meets the conditions you've set. So you need to add an action in Rule Machine, but you want to choose "Conditional Action". This will give you the option of an "IF (conditions) THEN" action or a "Simple Conditional Action". What's the difference? Well, as far as I can tell (and please someone correctly), an "IF (conditions) THEN" action can be complicated, with multiple conditional levels (nested, if you so choose) and multiple actions; a "Simple Conditional Action" has one condition and one action. In your case, an "IF (conditions) THEN" might look like this:

IF (Time between Sunset-30 minutes and Sunrise(F) [FALSE]) THEN
	On: Living Room Outlet
END-IF

Note that you don't need the "END-IF", but getting into the habit of it will help you when you start making more complicated rules.

The same rule, using a "Simple Condition Action" might look like this:

IF (Time between Sunset-30 minutes and Sunrise FALSE) On: Living Room Outlet

Obviously, this second version is simpler, and it is helpful to know both ways, but when you start getting into more complicated conditional triggers and multiple follow actions, allow with "ELSE" statements and the like, being adept with the "IF (conditions) THEN" action will probably aid you more.

One thing that helps immensely with using Rule Machine is that it does give you immediate feedback on whether conditional statement's conditions are met, both individually and as a whole condition. One thing that will drive you crazy is the lack of ability to cut, copy, and paste within Rule Machine.

Finally, consider turning on Logging for Events, Triggers, and Actions when trying to Debug. It will save you some headaches. One thing I do is take the log entries for when the rule did what I expected it to and the ones from where it didn't, and I compare them side by side in a text editor. That way I can find the differences and figure out what I've done wrong.

I hope this both helps and makes sense. :slight_smile:

Thank You very much for your input. I have since completed this rule using a “simple conditional” as you mention. I have not used the IF-THEN condition as of yet but I am sure that I will soon. I have only been at thIs a week now. My main issue with the rule machine is the syntax. I had to get it straight in my head, what do do next. I am getting a lot better. I was doing a lot of removing and starting over. I am looking forward to using the END-IF statement.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.