Rule 4.0 Without Trigger

I am just wondering why Rule 4.0 has to have the Trigger at the start. The IF is a trigger in itself, along with AND IF so why can't the Rules simply start with IF?

IF there is motion THEN turn on a light. You can use IF, AND IF, OR IF and THEN and maybe ELSE.

If there is motion
AND IF the door is closed
AND IF the time is 4 PM
THEN turn off a light

IF the time is 4 PM
AND IF the date is 7-28-19
OR IF the time is 9 PM
AND IF the date is 7-28-19
THEN turn off the light

The rules are endless but you really don't need the beginning Trigger IMO.

The trigger is the thing that initiates the action. There has to be some event to set off the series of actions. Some of the confusion may be that you can duplicate the trigger in your actions. That said, there's nothing to cause the action to run. The IF statement isn't a trigger but sets up a series of conditions to test the triggering event against.

In your example, the trigger would be motion = "changed". From there you could write a set of actions that use both the active and inactive.

Trigger
Motion = "changed"
Action
IF door closed AND 4 PM
THEN turn on a light.

Substitute the word Trigger with IF and you have the same thing. Homeseer uses the IF as a start and has forever and it works great.

IF the door is open
Then speak

IF the door is open
AND IF there is motion
THEN speak

Trigger just adds the word 'changed' which isn't necessary if you have open or closed. It has to be one or the other.

I'm sorry I'm not able explain things better. Hopefully others will chime in and guide this along. This isn't Homeseer and operates differently. In HE, Trigger can't be substituted for IF or a set of conditions.

There's no reason it has to work this way, but it does work this way because Rule Machine differentiates between conditions and triggers. A trigger is a way for you to specify when you actually want the rule actions to execute. You can test for things in the rule actions (using conditionals) that you don't actually want to trigger the rule--for example, say you want to turn a light to 100% with motion and down to 10% after it stops, but only at night. You don't need time of day as a trigger, but you'll need it as a condition. (I confess: that example isn't very imaginative, but there are times when this distinction is much more useful and powerful than I just made it sound like.)

What you're asking for is not impossible--webCoRE does this and does a fine job if you build the piston correctly--but it's just a slightly different paradigm. In webCoRE, you can build if statements with triggers, often the first thing you do in a piston. If you don't have any triggers, it will guess what your "triggers" should be from plain conditionals (triggers would be things like "motion becomes active," whereas conditionals are things like "temperature is 50 °F"). This is a distinction RM instead makes by separating out these sections. It could certainly do the same, but it's just, again, a paradigm difference.

Oh, and Rules don't need triggers or conditionals in the actions at all. You can use a trigger with actions (and no conditionals--so it's really necessary to specify the trigger) to just run something every time the trigger fires. You can also have no trigger and run the actions via another mechanism, e.g., a different rule.

If it helps, there's no reason that you can't start by setting up the actions for your rule -- the "what" you want to have happen: If there's motion AND the door is closed AND it's 4 PM, etc.

Once you have your rule set up, then think about "when" you want this rule to run: Every day at 3 AM, or every time the door is opened, or if it's Christmas, or if motion starts or stops, etc.

The "when" becomes the trigger.

The trigger does not have to be a part of the actions in the rule. It can be, but that's not required. So, for example, you can have a trigger of 4 PM, and then a list of actions that you want to have happen every day at that time. Some of those actions can be conditional, but they don't have to be, and time never needs to be reflected in an action at all. For example:

Trigger: 
   Time is 4 PM

Actions:
   Turn on the kitchen lights
   Turn off the bedroom lights
   Turn on the bathroom fan
   Turn on the air conditioner
   If the outside temperature is > 90 F
      Set the a/c temp to 80 F
   else
      set the a/c temp to 72 F
   end-if

Personally, I think that having the trigger separated from the actions, and being able to have actions that don't require a condition, make RM 4 very powerful.

You can create RM 4 rules with no trigger. I use no trigger rules but trigger that rule from several different other rules. If you have the same needs within other rules it makes them far simpler by just adding the untriggered rule as a step.

I wasn't aware that the trigger was not always required. Do anyone have a sample of a rule that doesn't use the trigger? thanks

I use a rule to only lock the garage entry door if the door is closed and tell me if the door is open. I call this from multiple rules.

IF (garage_entry_sensor open(T) [TRUE]) THEN
	Speak on Echo - downstairs_dot, upstairs_dot: 'The garage entry door is open and cannot be locked'
ELSE
	Lock: garage_lock
	Speak on Echo - downstairs_dot, upstairs_dot: 'All is well.'
END-IF
3 Likes

So with this type of rule you went directly to the actions? If so, I didn't know it would allow that.

Kind of looks like the trigger isn't needed. :grin:

1 Like

I discovered this by accident. I had the logic worked out in my head and started creating the actions. When I was done with the actions, I hit done one too many times. Since it was created, I just tried triggering from another rule. I really hope this wasn't a mistake that gets corrected in a future update. The reusability aspect is worthwhile.

Interesting, I will have to try it. Another reason it is thought that the trigger is necessary is the "changed". This can be accomplished by adding "was and becomes".

If the motion sensor was inactive and becomes active
Then turn on a light

I recall Bruce pointing out that a rule without a trigger is an action. I consider them named macros.

Obviously, no trigger won't satisfy many situations. When you can reuse, it makes so much sense, especially when you have more complex situations. As @2ac16mo says "named macros" is appropriate.

True, but the rule will never be executed unless it's triggered in some way; either via its own trigger, or by being called from another rule. Rather say that it's not required to enter a trigger when creating a rule. But without a trigger/call of some kind, your actions will just sit there doing nothing.

For example:

Trigger:

Actions:
   IF door is open
      do some stuff
   ELSE IF door is closed
      do some other stuff
   END-IF

You can open and close the door all you want, and the stuff will never happen.

Agreed, but...
IF the time is 4 PM,
that will work.

Also as I said above...
IF the motion was inactive and becomes active
Then do something
Will also work

So if the door was open and became closed
Then do something
Will work as well

No not unless you tell it when you want to test these conditions. If there is nothing to trigger the event nothing will happen. IF in RM is only a condition not a trigger.

2 Likes

I am beginning to see what terminology is being used. So, (IF time is 4 PM) is a trigger then a rule will run, but (IF time is 4 PM) is a condition only then the rule will not run.
So you have 2 identical things but only one of them will work. Now I see the confusion everyone is having.

Trigger:

Actions:
   IF time is 4 PM
      do some stuff
   END-IF

The "stuff" will never happen because there's nothing telling the rule to check to see if it's 4 PM. Every day at 4 PM this rule will be ignored.

Contrast this:

Trigger;
   Time is 4 PM

Action:
   Do some stuff

This "stuff" will happen every day at 4 PM because the rule has been told to check at 4 PM to see if there's stuff to do.

That's how RM works.

Maybe trigger needs to be changed to IF and IF to ANDIF.