Centralizing Notification Logic?

Not sure this idea makes any sense, but here goes ....

Now that I have 30-40 rules, I've begun to notice that nearly every time I write a rule, there is some notification logic that I am writing. And so I retype the same stuff into RM4 over and over again with each rule....sending messages to various mobile devices and/or speaking those messages. What I wonder is why I have to reconstruct this logic into every rule. Couldn't I instead use global variables to set the parameters for a notification and then "call" on some other rule to execute the notification?

If doable, I picture the parameters for a generic Notifier would be something like this:

  1. Recipients: who receives the messages
  2. Message Channel: Text-based (SMS, HE App, Pushover) or Speech (Sonos, Echo)
  3. Priority (esp.for Pushover)
  4. Repetition
  5. (If Spoken) Time of Day restrictions to prevent making noise when people are sleeping

So, I'd picture each rule would set these 5 parameters appropriate to the use-case and pass them along to some kind of shared notification engine to execute the messaging. Except the code for that messaging is defined once and only once. Easier to maintain, easier to change.

I was thinking about using Global Variables, but what happens when multiple rules are setting different values for the same 5 GVs, not sure how HE would thread the activity. Is this possible? How would I approach it? Appreciate any feedback. Be gentle, I'm still a newbie. :grimacing:

If the recipients and message, among other things, are different for every notification, what does centralizing it accomplish? I'm not trying to question your motivation, just wondering what you would actually get out of this.

I created a notification "proxy" device that is one device I can use to send notifications to multiple "real" devices (making my apps and rules easier to manage if I ever add or remove devices of change my mind--only one place to worry about this), but I don't think that's quite what you're after. If Cobra re-releases Message Central or Speaker Central, the latter is basically a more powerful version of this that can handle restrictions on your virtual/proxy device (e.g., don't send to this speaker when sleeping).

If you're just tired of writing rules, the built-in Notifications app can handle a lot of things I see people using Rule Machine for with a lot less effort.

I had been trying to do something similar to do "notify if present". In WebCore I had a function to do this since you could specify inputs. In Hubitat I found it easier to just write a custom app: [RELEASE] Presence Aware Notification Wrapper

Depending on what you need to do you might be able to follow that pattern to have an App + Notification wrapper device.

One place to maintain the logic!

To use a historical example.... when I started using spoken messages for a bunch of my notifications, I thought I was all clever by adding a simple condition like so:
IF (it's between hours of waking up and bedtime)
THEN Speak
ELSE Don't Speak

Of course later I realized that was not very extensible. I should just replace "between waking up and bedtime" with a global variable that determines whether it's wake time. The value for the GV can then be managed separately through some rules, be overriden manually, etc. But making that change meant going back into 30 rules to execute the change. Ick.

Now I'm picturing all the other similar changes I'd like to make and I'm asking myself the meta-question about whether there's a way to codify once (continuing to maintain the logic in one place) and then have all rules reference it somehow.

Eric, yeah I saw that. Cool idea, but since it's only based on Presence, it doesn't quite have the parms that I'm looking for. And I don't have the skills to write a custom app. Maybe that's my dead end.

Makes sense! Speaker Central isn't available right now, but will likely be re-released soon. Still, the description in that thread may give you a good idea of whether it will meet your needs. (It handles both speakers and, per a request apparently made just by me that the author was gracious enough to include in an update, notification devices.)

You might be able to re-create something like that using your own logic in a Rule and a virtual notification device (not sure if one exists as a stock driver but it would be easy to create), then sending custom commands to that device, but I haven't tried this so there might be something you can't do that I'm not thinking of...

1 Like

Follow Me with What Did I say, controls where and how all my notifications are handled.

2 Likes

Thanks Bryan, I had the impression that What Did I Say was focused on Speak and that Follow Me was Speak and Pushover. I'm going to check it out, thanks!