Virtual Switch vs Global Variable

Should I use a global variable or a virtual switch to indicate when a notification should be sent?

So I have a rule that sends a notification when my garage is open. But there are times when I donā€™t want to be notified, so I would manually set the global variable to false, or the virtual switch to off, and then check that variable or virtual switch in my rule to determine if a notification should be sent.

In the use case that you are describing, I would say that a virtual switch is a good approach. The virtual switch has the added benefit of being shareable and updatable with voice command devices like Google Home and Alexa.

With global variable connectors, you can now also create devices for variables (and for boolean variables--true/false--one of the options you get is a switch device--on/off). So, the difference nowadays is minimized. In the past, you had to use devices to "track" things like this since variables didn't exist, and in the early days of variables neither did connectors, so you'd still need a device if you wanted to expose or manipulate a value elsewhere. Nowadays, the functional difference is minimal, so I'd say use whichever you prefer or feel most comfortable with. :slight_smile:

2 Likes

I guess if I want to use the Notifications app, I would have use a virtual switch, because I donā€™t think a global variable can be accessed in a Notifications rule. To access a global value I would have to use Rule Maker.

Is that correct?

No, if you make a global variable connector (and choose "switch" as the type in this case--you have options when you create the connector--or any capability that your desired app is looking for in general), then you should be able to choose that device in the app. But either way works, so I'd say whatever you're most comfortable with is fine!

2 Likes