List of variables and syntax to use

Hey guys, I am new to Hubitat, and I am trying to learn how variables work and how to use them in certain situations like with Alexa TTS for example.

Is there any documentation that lists all the native variables that can be passed to a device like Alexa TTS? Or in Puhover notifications? Sorry if the question is stupid but I've been looking for this answer for a while and I can't find anything on the syntax to use or variable names to pass over.

2 Likes

You can start with these threads.

https://docs.hubitat.com/index.php?title=Rule-4.0

2 Likes

Thank you so much. So you can basically use variable only within Rule Machine? If a global variable is set, you can't use it within an app for example or to manually test it against a device or notification....

JNS, thank you for all the explanations. Is there a way to set a global variable value from within an app? If so, what is the syntax? I can't seem to figure out a way to do so.

I haven't written any apps for the platform and currently have no interest in doing so. You will need to wait for one of the developers to respond back to you. Sorry, I have no idea.

1 Like

Global Variable are only part of Rule Machine. You can set a global variable from another app if you have a Global Variable Connector created. You can then manipulate that device from your other app and that in turn would change the Variable in Rule Machine. However if you are writing another app, why would you need to change a variable in Rule Machine? If you have an example of what you are trying to do, that would be a lot easier than talking in the abstract.

Ryan, I am trying as an example to grab the title of a movie playing on Plex and send it to a Pushover notification. I can grab the title string JSON like plexJSON.Metadata.title, I can even print the movie title to debug but I don't know how to assign it to a variable to send to Pushover.

You can do all that from within Rule Machine. You don't have to use another App. Do you have a pushover device created?

@Ryan780 Yes, I do. Push alerts work great but the value of the variable always shows as null.

How are you trying to capture it in Rule Machine? Can you show a copy of your rule?

@Ryan780 I've tried it in several ways. I have a driver where I set a Movie attribute title like this:

def playbackTitle(PlexTitle) {
sendEvent(name: "trackDescription", value: PlexTitle);
log.debug "Title set to $PlexTitle"
}

Then when I call %trackDescription% anywhere in a rule it's null.

I also created a global string variable that I have tried to assign a value to with the same null result. I am confused about how to pass that string value across apps/drivers/rules to actually make it useful.

I do have a music player device that actually gets that attribute value correctly but Idon't know how to use it anywhere else. See the screenshot below where I circled the attribute in red. How do I grab that value and make it useful?

You still haven't shown me your rule. So, I'll just assume you don't have anything to start with. You want to create a new rule and then create a local variable named "title". Then do the following action.

Select Mode or Variables then Set Variable. Next select the track variable. Then select Device Attribute, then Track Description. Then your variable is available to send to Pushover. You can also set it to global variable if you need to use it in another rule.

1 Like

@Ryan780 I am definitely not doing this, but I will try it as soon as I get back home. Thank you for patiently explaining this. I think the terminology is confusing. "Global variable" makes me think that it's global across the entire Hubitat device. I was trying to assign the value to a global variable I made in Rule Machine using the app code, not this method.

Thanks again! I will update you with the results.

1 Like

You are most welcome.

Remember its called a Rule Machine Global Variable...which means it is global to Rule Machine. There are ways you can set a RM GV from other apps but that entails creating what's called a Global Variable Connector...basically a virtual device that allows other apps to interact with Rule Machine's variables. But since you can do everything you need for this right inside RM, there's no need for that.

1 Like

@Ryan780 I got it working, thanks to you. I am using a global variable and it works fine. Thank you so much for your help and for pointing me in the right direction. I have a much better understanding of the Rule Machine right now!! I wish I could buy you a beer.

2 Likes

You're too kind. Glad I could help. :smiley: