How to set a variable in the trigger?

I've configured geofencing and I'm trying to pause/resume a rule depending on the presence of my Pixel 8 phone. Can someone explain to me how set a variable in the trigger? If the phone reports "departs", set the variable "present = false". And if arrives set "present = true". After this I believe the actions will run as desired.

I wound up with the "ONLY IF" logic in the trigger which assumes the variable is already set.

-Thanks

I don’t believe you can set a variable value in a trigger.

Setting a variable value is an action.

If I could back up for a second, what is the purpose of pausing and resuming the rule?

When I'm home I want to pause the Front Door Lock Notification rule. When I'm away, I want the rule to resume.

-Thanks

Yes that’s clear enough, my question is why?

1 Like

Because I don't want numerous notifications from my family and I locking and unlocking the door when I'm home. I'm always locking/unlocking the front door.

Most people would handle that by adding restrictions to the triggers, or conditional logic in the actions.

The method you’re describing could be made to work, but with unnecessary effort and complexity.

3 Likes

If you look at my screenshot that is essentially what I'm trying to do. Need help with that.

Why are you using a variable here at all? Why not just check the state of the device directly?

IF (Pixel 8 is present) THEN
   Pause Rules: ...
ELSE
  Resume Rules: ...
END-IF

As others have mentioned, you cannot set the value of a variable in your triggers. You can't really do anything in triggers in general. I'd take seriously my suggestion yesterday to read the Rule 5.1 docs -- and also look at some examples you can find here and elsewhere. People are happy to help if you get stuck, of course.

(So if you do need that variable elsewhere, you'll need another approach. But with just this rule, there's no indication of that.)

3 Likes

The "Use Required Expression" restriction will be added to your "Front Door Lock Notification" rule not the one you showed us. You won't need that rule at all.

1 Like

Thanks! My first if-then-else conditional statement in Rule Machine. You never forget your first! :slight_smile:

Even simpler solution, yes yours is fine, would be to add a restriction to your notification rule that restricts it from running if your phone is present.

If interested, post that rule an I, or someone, will show you that approach.

2 Likes

Yes, I would be interested in seeing that approach. I'm curious how it compares with the if-then-else statement I created with the help of bertabcd1234.

Thanks!

Go to your notification rule and turn on this.

Then add a conditional expression like this one.

In my case no triggers will be looked for unless my iPhone is NOT present.

You won’t need the if/then rule at all.

1 Like

If a rule has a “required expression”, its triggers will not be “enabled, checked, used” unless the expression is true.

Thanks again, I'll give it a try.

Let me know how it goes. Rule machine has lots of features that can be used to simplify how we can implement our ideas.

I followed your suggestion and setup a rule to pause the rules and it did not work. I think the rule looks just fine. So, I created a similar rule to send me a notification based on present and not present and that did not work either. But I confirmed in my Pixel 8 events as you can see there is a present and not present entry. I double checked my location in the Hubitat settings and also the Hubitat app which are correct. I'm getting close!

Without seeing the entire rule (you only showed the actions), it is not possible to troubleshoot. See: How to Troubleshoot Apps or Devices | Hubitat Documentation

Along those lines, it may also be helpful to enable logging on the other rules and check Logs for that output too, but if you think your problem starts with this rule, I'd start troubleshooting here first -- and seeing the whole thing would be the best place to start (for us), Logs for it being next.

It just occurred to me after you mentioned seeing the entire rule. I need a trigger right? I was thinking I didn't and that the IF THEN ELSE logic was sufficient.

Yes. Please read the docs I linked to above. I again think this will help with a lot of the problems you are running into. While many of us are happy to answer questions, it would make things easier for you if you had at least the fundamentals to start.

Rules will not do anything unless they are triggered (or run manually or from another rule).

3 Likes