Action Only Running Once

Hello All,

How can you ensure that an action only executes once even if the conditions are still True?

Thank You

Please provide more information to allow the community to provide appropriate advice. Since you posted this in the Rule Machine section, I am assuming you're using RM 4.0? If so, I find it easiest to simply use the Private Boolean feature of each rule.

Here is an example of a RM 4.0 rule that I use to receive one notification for each laundry complete cycle. It demonstrates the use of Private Boolean (PB).

1 Like

Here is a very arbitrary way of doing it:

TRIGGER: SOMETHING **CHANGED**

ACTIONS:

IF (SOMETHING is WHATEVER AND Private Boolean is TRUE)
	NOTIFY: SOMETHING is WHATEVER
	SET Private Boolean FALSE
ELSE-IF (SOMETHING is DIFFERENT)
	SET Private Boolean TRUE
END-IF

However, as @ogiewon correctly said, it is very hard to give you the right advice not knowing what you are trying to accomplish. E.g. my example above only works if there are not fluctuations for the device SOMETHING like with a power level. You would need a different approach then.

It is always advised to be as specific and descriptive as possible. It makes it much easier for everyone to come to closure quickly. Last thing we want is you to get frustrated by getting a million different ways of doing things but all of them don't address your actual need

3 Likes

This question is in reference to RM4, I have attached an example below, it will sometimes speak the command multiple times within the 2 minute window:

I think you can make this rule much simpler and you have a thought problem there.
Right now, in your actions you are only checking for time. So it will always speak, no matter what the status is of the mower. Also, I always try not to mix time triggers and status triggers as it can complicate things. In your case, I would do something like this:

TRIGGER:
When time is 4.30 PM CDT
OR 
When time is 6.00 PM CDT

ACTIONS:
IF (Mower is open)
  NOTIFY: 'The mower is not docked, please check it. Thank you'
END-IF

As you can see, I removed the "Mower open" from the triggers and moved into the actions as a condition as you only want to get notified if the mower is open. I also removed the delay on the notify as it really does nothing in this scenario, it really just delays for 15 seconds. I can see that there is slight difference in the device selection for the notify between the two times. Do you really need that? The one for the 6pm run has the Pixel 3 in there but I wasn't sure if that was intended that way. If so, I might have to adjust my example above a bit

Actually, I missed the first mower open when changing a time yesterday, you found another issue not related to my duplicate spoken messages and thank you. I am migrating 205 devices while running a home business and missed a few details initially :slight_smile:

The RM4 rule that had this issue a few hours ago is below:

Here is what I would do: make two rules out of that.

  1. Rule trigger just on time handles the IF and the first ELSE-IF
  2. Rule triggers on motion and thanks Tristen

I think you are getting yourself in trouble trying to cramp to much into one rule and mixing state triggers and time triggers. Bruce from Hubitat always preaches to follow the KISS principle. It makes it so much easier. Rules are free and don't cost anything. You can have as many as you want

Here is what I would do:

Rule 1:

    TRIGGER: Time is 6:55 AM or 7:35 AM
    ACTIONS:
    IF (DAY IN M,T,W,T,F AND TIME BETWEEN (6:55 and 6:56) THEN
      DIM: Kitchen Lights
    ELSE IF (DAY IN M,T,W,T,F AND TIME BETWEEN (6:35 and 6:37) THEN
      OFF: Kitchen Lights
      Speak: Tristen brush your teeth
    END IF
  1. RULE

     TRIGGER: Motion Sensor active
     ACTIONS:
     IF (DAY IN M,T,W,T,F AND TIME BETWEEN (7:35 and 7:45) THEN
          NOTIFY: Thank You Tristen
     END-IF

I don't disagree with the KISS principle, although I like to keep everything regarding an event in one rule if I can.

However, how can I ensure the action will only run once if the triggers are True?

TRIGGER: Motion Sensor active
ACTIONS:
IF (DAY IN M,T,W,T,F AND TIME BETWEEN (7:35 and 7:45) THEN
NOTIFY: Thank You Tristen
END-IF

Here is what you can do about that:

TRIGGER: Motion Sensor active
ACTIONS:
IF (DAY IN M,T,W,T,F AND TIME BETWEEN (7:35 and 7:45) AND Private Boolean is TRUE) THEN
  SET Private Boolean False
  NOTIFY: Thank You Tristen
  SET Private Boolean True -> delay 10 minues
END-IF

What that basically does is to remember that the rule ran once by setting the PB to false and setting it back to TRUE after 10 minutes. I chose 10 minutes because you are checking for a 10 minute period in the IF clause

Oh very nice, I love RM4, it opens so many previously closed doors for us :slight_smile:

Thanks Again
Matt