Hey all. I am needing to know a variable value during certain times of day. I would like for Hubitat to notify me at certain times of the day with the value of a certain variable. I am unable to do this through the Notify App, since it does not seem possible to notify of that particular variable. So I then tried to create an app that would run at certain times of day and notify me of the variable value, but I don't know how to get the variable value into the notification that sends. I could set up a Rule that runs every time the variable changes, but it changes every few seconds and I don't want a notification that often.
Assuming you have a hub variable (or local variable) named myVariable
, you can just create a Rule Machine rule that:
-
Triggers at a specific time; and
-
Uses uses the Send/Speak a Message action (under Send, Speak, or Log a Message, Send HTTP Request) to send a message to your selected device in this format:
"Hi, the variable value is %myVariable%."
'
The key here is that you can use the variable name, enclosed in %
symbols, to get the value for use. This works here and in many parts of the Rule Machine UI that accept string inputs.
So, the rule would look something like:
Trigger events: Time is 8:00 AM
Actions to Run:
Notify My Phone: 'Variable value is %myVariable%'
The method for groovy if you want to use your app instead is:
varValue = this.getGlobalVar(variableName).value
Awesome. Thanks! By the way, I am actually trying to notify of a device attribute, not a variable. I am currently getting this to work by setting the variable "Test" to the device attribute I want to be notified of, then sending a notification of the "Test" variable value. Is there a way to notify the device attribute directly?
No, you'd need to store that in a variable since you can directly query a device attribute in this text. But you could use a local variable for that rather than a hub variable if you want, assuming you have no use for it outside this rule.