Variables vs. Conditions

My two little Yorkies often need to get up in the middle of the night to potty. One is 1/2 blind and the other scared of the dark and barks his head off if there is not sufficient light.

I put in two motion detectors pointed at the doggie door, and wrote the following rule:

It worked perfectly except that the lights in the back yard and the one lamp was coming on in broad daylight. I added a condition that the rule should only run between 11:01 PM and 5 Minutes after Sunrise. The issue is, it has not been running the rule at 11:01 PM. I have to go to the rule and manually resume it. Is this a case where I need a variable?

I have not a clue on where to write these and store them? Is there an app that will create them? Is this something that is written in Groovey and do I need to learn it in order to write them. I am confused because the documentation shows these examples:

If you see the issue with my rule or you have some insight into these variables please let me know.

Drat. I accidentally deleted my own comment!

A couple of questions...

You mentioned adding a conditional to prevent the rule from running except from 11:01-sunrise+5, but I don't see a conditional in the screen shot. The easiest way to do this is with a "required expression" but wondering if maybe you added the conditional but never incorporated it into the rule?

There's a "capture" statement with no corresponding "restore." This won't affect the rule per se but might cause unexpected behavior down the line.

And last the rule shows paused. If that's just for troubleshooting it makes sense but is it possible the rule was accidentally paused and never unpaused?

1 Like

I inadvertently left this screen grab off:

As for the capture restore I must have accidently deleted that, here is the screen grab with that corrected:

They are just lines in your actions and are added like every other action, via the menus. (You do not need to write an app; Rule Machine is an app that lets you write custom automations without actually writing an app yourself--though that is certainly an alternative.)

To add IF THENs (and associated "actions" like END-IF, ELSE, etc., though some will show as shortcut "buttons" too when you're in the middle of writing one of these), use the menus: Conditional Actions > IF (expression) THEN to get started. In other words, these are added the same way as you add other actions, even though these are a bit special.

I don't see one of these in your screenshot,but if you mean the "Create Conditions" or "Manage Conditions" box (same thing; the name changes after you have one or more added), they don't do anything on their own. They have to be used somewhere, such as in one of the actions above. Think of this as a bank of conditions you can use. You don't need to pre-create anything, as the editor for things like IF THEN will let you create conditions on the fly, and they'll show up here when done. This lets you edit them separately and also share a reference to the same condition among multiple expressions if you want.

That being said, as mentioned above, for your particular rule, perhaps a required expression would work. This prevents your rule from triggering. You could achieve the same results (in this case) with conditional actions, but sometimes it's less clicking for the other approach. Other times, it helps you do things that are difficult or impossible in the actions alone. Other times, people seem inclined to turn the option on just because it's there and then use one where they don't actually want or need one at all, but you probably have a good case. :slight_smile:

1 Like

Yeah here's the issue... adding the condition here:

doesn't actually add it to the rule. It just puts it in a bucket that you can use later in your rule. Easy mistake to make - it can be a bit confusing when you're not used to it.

What I would suggest is adding a required expression and then putting that condition in the required expression.

7 Likes

This was the missing link for me, it seems strange that you would have create conditions after the action and then go up to the top of the page and add define required expression. I was not even thinking in that direction. I have been writing process mapping diagrams for many years and this (to me) is counter-intuitive but, I still enjoyed learning something new and I appreciate the help I received and the convivial nature of this group. I will respond in kind... thanks again.

The conditions box you are talking about is only for actions. Expressions used in required expressions have their own "bank" that is separate from this one, so I think it makes more sense.

But really, I think it makes the most sense to just ignore these boxes and only come back to them if you need to edit a condition; anything you need to create can be done on the fly while you're creating the action/expression. It might be less confusing if then boxes just weren't there in the first place, but then we'd lose the ability to edit or possibly re-use existing conditions this way.

3 Likes

Download the Hubitat app