Motion rule

So I have a motion rule that sends commands to my devices using the [CC] command on the google home relay to turn my devices on and off based on motion. I'm not that good with RM4 so how do I delay the motion sensor from sending this command each time it senses motion? In the rule I have it setup to turn them on and wait 5 minutes without motion before turning them back off. It appears each time it sees motion though it is sending the commands each time. Anyway the issue is I have been redoing my network and spent a lot of time out there this weekend which has caused me to go over the limit of my API calls the last 2 days. So how can I have this rule see motion turn on the devices and wait 4 minutes before re sending the command if motion is still active?

You can use Rule Machine's Private Boolean feature (or even a Local Boolean Variable) to help with coordinating logic flow.

For example, take a look at the logic flow in the following rule I have for washing machine notifications to prevent multiple announcements. This is not the logic you'd want for your specific use-case, but it does demonstrate the use of RM's Private Boolean to help with logic flow.

1 Like

Thank you @ogiewon Does this look right? I still have a lot of learning to do with RM4 and honestly maybe it is just me but I felt like the if/then etc actions should be in the the trigger events section. Could just be me though and my lack of experience.

The rule you showed above only turns them off four minutes after motion stops. It does not care when motion starts again, so that will happen every time motion stops (and never be cancelled even if it does). Rule actions run only when some event matches your trigger. I assume you have another rule somewhere that turns them on, but I'd suggest combining them into one rule using a "changed" trigger for your motion sensor--then you can use an IF/ELSE to "fork" the actions in your rule depending on the state of the sensor, and you can make new motion cancel the delay on your inactivity.

The Rule 4.0 docs contain a basic motion lighting example. I'd highly recommend reading these or at least looking at that. All you'd need to add is your additional devices to turn off and the private boolean suggestion from above (or some other way to restrict this), since apparently repeated "on" commands for devices that are already "on" (generally harmless with real switches but perhaps not here) doesn't work in your case. In fact, the docs contain an example of that, too. :slight_smile: Here it is:

image

(you'll want a full-blown IF THEN... for the private boolean check, not a simple conditional "if" since you have a series of actions to do and not just one, but the idea is the same)

2 Likes

Thank you @bertabcd1234 I will try and accomplish this as soon as I have time to wrap my head around it.

I had a few minutes to look into this and I'm even more confused now I finally found out how to do the if/then and private bolean but I'm afraid I do not have a clear enough understanding of how this should be setup or what it even means. See below for what I ended up with after trying to accomplish this.

I don't think that is right is it?

Select Actions for Turn on/off lights and monitor in garage with motion
IF (WeMo Motion active(F) OR
WeMo Motion inactive(T) XOR
( NOT Private Boolean is false(F) OR
WeMo Motion inactive(T) XOR
WeMo Motion active(F) [FALSE]) THEN
Notify Google Home Relay: '[CC] Turn on monitor'
Notify Google Home Relay: '[CC] Turn on network rack and set color to blue'
Notify Google Home Relay: '[CC] Turn on server rack'
Notify Google Home Relay: '[CC] Turn on console light and set to color blue'
IF ( FALSE)
Conditional Expression:
WeMo Motion active(F) OR
WeMo Motion inactive(T) XOR
( NOT Private Boolean is false(F) OR
WeMo Motion inactive(T) XOR
WeMo Motion active(F) [FALSE]

Way over complicated. :slight_smile:

Trigger: WeMo Motion changes

Actions:

IF (WeMo Motion active) THEN
    IF(Private Boolean IS TRUE) THEN
        Cancel Delayed Actions
        Set Private Boolean False
        Notify Google Home Relay: '[CC] Turn on monitor'
        Notify Google Home Relay: '[CC] Turn on network rack and set color to blue'
        Notify Google Home Relay: '[CC] Turn on server rack'
        Notify Google Home Relay: '[CC] Turn on console light and set to color blue'
    END-IF
ELSE
    Delay 0:04:00 (cancel);
    Notify Google Home Relay: '[CC] Turn off monitor'
    Notify Google Home Relay: '[CC] Turn off network rack and set color to blue'
    Notify Google Home Relay: '[CC] Turn off server rack'
    Notify Google Home Relay: '[CC] Turn off console light and set to color blue'
    Set Private Boolean True
END IF

I also have another question, aren't all these devices connected directly to your HE? If so, why are you going out to Google Home Relay to issue commands? If they aren't connected directly to HE, why not? (Sorry, just curious). :slight_smile:

2 Likes

They are not currently connected to the Hub. I have them on two separate power strips one is Tuya and the other is TP-Link the Tuya I know seemed really complicated to connect to Hub the TP-Link I can't remember if it was overly complicated or not or I simply thought since these devices reside in the same setting it would be easier to keep them under the same rules for simplicity.

1 Like

Ahhhh, ok. Yeah, Tuya and TP-Link are not "officially" supported (but there are community integrations that I have seen).

Try out the rule logic and see if that works for what you want. :slight_smile:

1 Like

I'm trying to set this up just not sure how to get the "THEN
Cancel Delayed Actions" in the rule? Am I simply choosing the wrong option I have and or, xor. I'm no programmer and don't understand RM4 all that good. Thanks for everyone's help by the way.

Conditional Expression:
WeMo Motion active(F) XOR
Private Boolean is true(T) AND
[FALSE]

You're creating a RM4 rule, correct?

To setup the trigger, follow this:

Then, in your actions section:

Select Conditional actions:
image

Then select IF (conditions) THEN

Then, in Define Condition, select WeMo Motion active as the condition. Don't put ANY And, Or, or XOr.

Click Done and it will populate the first IF statement. Then, add another IF statement:
image

For this one, you'll want a new condition:

In Select capability for Action Condition, you want to select Private Boolean:

At this point, your rule should look similar to this:

Now, add your On commands (Notify Google stuff), Cancel delayed actions and set Private Boolean to False. Your rule should look like this now:

Then, add (from Conditional Actions), an END-IF and an ELSE:

Now, add in your delay:

Then, your actions and set the private boolean to TRUE:

Finally, add the final END-IF and you should look like this:
image

Click Done and your rule should now look like this:

From there, profit.

3 Likes

I think I got it. It was a challenge no doubt I really appreciate the detailed instructions with the screen shots etc.

I would of been here a month trying to recreate that without the screen shots for sure.

Let me know if you see any issues. Now just understand what I just did and the why and I will have it whipped for my next rule....:slight_smile:

2 Likes

Perfection! Glad to be of help!

Yeah, RM is a BEAST... But, once you have the basics down (and the little intricacies of it), you'll be whipping up rules in no time.

Thanks again for all the help. I hope this solves my API quota issue! I guess the old rule was firing off each time it sensed motion.

2 Likes

This worked perfectly thanks again for everyone's help.

2 Likes

Awesome! Glad to be of assistance. :slight_smile:

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