RM 5.0 Global variables and Hub variables

So for a number of my global variables I pass them from various other devices with an http request

https://cloud.hubitat.com/api/blah/apps/appid/trigger/setGlobalVariable=Var:value?access_token=token

I would like to transition my global variables to Hub variables, as I will likely use 5.0 for new rules, can the new hub variables bet set by http, if so how?

Also is there any way for legacy rule manager to see or interact with the new hub variables?
They don't appear in the variable list, I also don't see a way to interact with the connectors, under custom actions.

There is no direct way at present to set a Hub Variable by http. (see post below) You could set a connector for one by http with Maker API.

Rule-4.1 can set devices, and connectors are just devices. Each connector type has capabilities that can be used to select them in Custom Actions, such as Dimmer, Switch, Motion Sensor, etc. Sensor type connectors also have capability Sensor, and actuator type connectors also have capability Actuator.

There is a way to do this with a Local or Cloud endpoint trigger of a rule. It works the same in Rule 5.0 as it did in Rule 4.1.

See Rule Machine API.

/setGlobalVariable=varName:varString

varName could be the name of a Hub Variable.

Thanks so much, this makes things much easier!

Ah I see, didn't check actuator which can set dateTime, should be able to get all variables in sync with this.

It looks like the field sizes changed between RM4 and RM5 for a "string" variable. In RM5 it is limited to 255 characters. When trying to move a rule from RM4 to RM5, I created a new hub variable but when I added the current text, with a length of 292 characters, it took the data, but then generated this error:

app:6272021-07-21 09:26:48.783 errorjava.lang.RuntimeException: java.sql.SQLException: Value too long for column "VALUE VARCHAR(255)": "'Good morning. , Today is Wednesday, July 21st and it is currently 72 degrees outside. , The pollen count is 2. , Todays forecas... (291)"; SQL statement:
merge into global_variable key(name) values(?, ?, ?, null, null) [22001-197] Query: merge into global_variable key(name) values(?, ?, ?, null, null) Parameters: [goodMorningText, Good morning. , Today is Wednesday, July 21st and it is currently 72 degrees outside. , The pollen count is 2. , Todays forecast is, Considerable cloudiness. A stray shower or thunderstorm is possible. High 84F. Winds light and variable.. , , take the trash to the curb and have a great day!, string] on line 726 (hubVar)

Now when I try to go into Hub Variables I get the same error so I cannot even change the variable to something smaller that the system will accept. I tried to create a temp app to change the variable, but it's not showing up in the variable list. I rebooted the hub, and I'm still stuck. I don't know how much effort it would be to add an error message or something to catch someone trying to push too much data into a field, but it may be worth looking in to. Is there a way to either force-update the variable, or delete the variable? Or, is it possible to expand the field length to whatever it was in RM4? I can use two smaller variables, but I need to get this one fixed first to restore functionality. Thanks!

@JayTee I've seen similar issues, but with dateTime, however I was able to fix them with a RM 5.0 rule, try using an http request to set the variable

Just create a 5.0 rule with a local or cloud request trigger
https://cloud.hubitat.com/api/blah/apps/appid/trigger/setGlobalVariable=Var:value?access_token=token

So it seems you can't actually set dateTime with RM 4.x using custom action or with an http request, at least trying to just set the time, at best nothing happens at worst you'll end up in a state where you can no longer open the hub variables window

happening on version 2.2.8.138

An unexpected error has occurred trying to load the app. Check [Logs] for more information.

Error: String index out of range: 10

2021-07-21 09:36:01.723 am errorjava.lang.StringIndexOutOfBoundsException: String index out of range: 10 on line 335 (method hubVar)

example time used 10:30 PM

/setGlobalVariable=varTime:10%3A30%20PM

That said even if you did include a date you'll get *bad time* for the time

/setGlobalVariable=varTime:07%2F21%2F2021%2010%3A30%20PM

Please show the rule.

If you are trying to set a Hub Variable DateTime connector, it has to have a full date string formatted like this:

2021-07-21T11:08:22.123-0700

If you want to omit the date, use 9999-99-99. If you want to omit the time use 99:99:99.999-9999.

I will look into the issue with Hub Variables blowing up with a bad DateTime string; obviously, it should not.

Ah I see I just needed to use a rm 4.X connector to get time into the correct format, thanks

I've run into this same issue, but am unable to solve the problem.

I have overrun the 255 character limit of a global variable as set by a RM5.0 rule. When attempting to view the global variables page I'm presented with the error message referencing "Error: java.sql.SQLException: Value too long for column" and the variable in question. I've performed a backup and soft reset, as well as attempted to create a rule with a local end point trigger and changing the variable via an http-get, but nothing is working.

The rule I created originally had a single action: set the global variable to "reset". I created the local endpoint trigger, updated the rule, and then tried to perform an http-get with the following sanitized URL:

http://A.B.C.D/apps/api/#APPID#/trigger/setGlobalVariable=MSA_Lock-Array-Pending:reset?access_token=#token#

Is there something obvious I'm missing?
Thanks in advance!

Please show the rule in question. "same issue" doesn't convey much information, given that prior discussion was about DateTime variables.

I'm sorry, I meant I had the same issue as JayTee did above: he overran the character limit of a global string variable resulting in the SQL exception "value too long for column "VALUE VARCHAR(255)"".

There are multiple rules that access/change the variable, but the gist is that one of them attempted to change a string variable to a value that is longer than 255 characters. My attempts have failed to recover the hubitat enough to be able to view the global variables page.

See pm I sent you.

Is it possible for the hub to send itself an http GET? I have tried to get this to work several different ways and can't seem to figure it out. So I assume it is not possible? What I was trying to do was to link the hub and global variables together by sending the hub an http GET to itself, but the hub never receives the GET.

@claywhitenack if you want to set your RM 4.x global variables in RM 5.x you'll want to create variable connectors and then use the actuator custom action in RM 5.x and vise versa. To set your Hub variables from another device create a rule with a local or cloud trigger (there don't have to be any actions in the rule) and use the following http request on the device setting the variable:
https://cloud.hubitat.com/api/blah/apps/appid/trigger/setGlobalVariable=Var:value?access_token=token

Thank you. I think I understand. I have an RM5.x created successfully to set a Global Variable through the actuator option. However, when I try to do the same thing from RM4, it looks like I still only have the option to set the Global Variable, not the hub variable.

So in RM 4.x you have to do the same, create a connecter for the hub variables (I label my 4.x connectors, but do whatever you want to differentiate them) the in RM 4.x use the actuator of the hub variables connector.

In RM 4.X:
image
In RM 5.X:
image