How do connectors work?

I have a variable setup and have created a connector. How do I access the connector in my app?

I’ve been searching for an example but haven’t found one.

Connect Global Variables to Dashboards

in RM4, you can set a variable and define what you want to do with it:

  • in a trigger event, choose a global variable and select the action
  • in a action to run, choose a global variable and select the action to run
  • in a dashboard tile, select the connector as a device, template: attribute and attribute:variable to display the value of the global variable you created

I’m still missing something. I’ve used variables with the rule machine, I see the connector’s virtual device. I have no clue how to access it from a custom app.

I’m sure it is something simple but these Groovy apps are eluding me.

I mean say I want to print the value to the log. It doesn’t get any more simple than that. :wink:

I created a test Boolean with a connector and can select it from the list when I use;

input "testBool", "capability.switch", required: false

So I guess the question is how do I select the string virtual device.

I tried each variable type and for a couple of them I was able to access the virtual devices in the app selection box. I can't see all of the types (ex. string). What am I doing wrong?

Try "capability.sensor". That will bring up a String Connector.

When in doubt, looking for an oddball device, try "actuator" or "sensor".

1 Like

Thanks, I’ll give that a try next time I get the chance. I was starting to do an enumeration since I couldn’t figure out the string.

I’m a software engineer and this stuff is eluding me. :man_shrugging:t2:

I gave sensor a quick try before I left for work this morning and I was able to see the GV in the list. Thanks for the head's up. Hopefully I now have enough information to be dangerous. :wink:

OK, the connector in my brain is still misfiring. I can see the connector with this:

input "holidayName", "capability.sensor", required: false

But I can’t read the value. I’ve tried the following (and more):

def motionDetectedHandler(evt) {
    log.debug "motionDetectedHandler called: $evt"
    log.debug "global: $holidayName.displayName"
    log.debug "global: $holidayName.status"
    log.debug "global: $evt.device.displayName"
    holidayName.each { chld ->
        log.debug "--> $chld"
        chld.each { xxx ->
            log.debug "x $xxx"
            xxx.each { yyy ->
                log.debug "y $yyy"
    log.debug "==> $connector_gHolidayName"
    log.debug "==> $holidayName.variable"

The motion handler is from a different device. The above logic results in the following:

app:1972019-11-07 07:12:53.199 am debug==> null
app:1972019-11-07 07:12:53.198 am debug==> null
app:1972019-11-07 07:12:53.196 am debugy gHolidayName
app:1972019-11-07 07:12:53.186 am debugx gHolidayName
app:1972019-11-07 07:12:53.176 am debug--> gHolidayName
app:1972019-11-07 07:12:53.163 am debugglobal: Motion - guest bath
app:1972019-11-07 07:12:53.161 am debugglobal: ACTIVE
app:1972019-11-07 07:12:53.160 am debugglobal: gHolidayName
app:1972019-11-07 07:12:53.158 am debugmotionDetectedHandler called: com.hubitat.hub.domain.Event@4250d2f5

I can see bits and pieces of data but I haven’t been able too ferret out the value. What bit of knowledge am I missing?


That would be the value of the motion event. So are you saying I need to subscribe to some event on the GV? I just want to read the value not use it as a trigger.

OK, device.currentVariable. That's for variable connectors, and it is a string.

OMG! There’s the secret handshake. I’ve been searching the Hubitat and SmartThings forums and docs with no luck. I’ve triggered countless null pointer exceptions.

Thank you for all of the assistance.

That reads the current value of an attribute. To set the value of a variable connector there is a method for the device called setVariable.

device.setVariable("this is the new value")

Doing that to a connector also sets the value of the corresponding Global Variable.

I saw that and tried it early on. I was just missing "current" in all my attempts to read the var. For some reason I’ve been finding the fundamentals of Hubitat elusive. I was able to do a first pass at this in Rule Machine but the edit and insert before mechanic quickly became a hinderance for a larger project.

Most of it makes sense but I’m missing a few key bits of understanding. The answers in this thread may seem obvious but they really helped.

Guys... trying to subscribe ( in a custom app ) to a global variable set up as variable and can’t figure out what to subscribe to ...

Eg subscribe ( listOfGlobals, “variable”, methodh)


I have this in the preferences section of my custom app:

   section("var") {
        input "holidayName", "capability.sensor", required: true, title: "Select holiday global variable connector."
        input "isNight", "capability.switch", required: true, title: "Night toggle"
        input "overrideMotion", "capability.switch", required: true, title: "Motion Override"

And access them in the app like this:

  if (isNight.currentSwitch == "on") {
        if (overrideMotion.currentSwitch == "off") {
            if (new Date() > location.sunset) {
                switch (holidayName.currentVariable.toString()) {

Hope this helps give some insight.

Edit: In Rule Machine I have the variables configured like this:

Edit 2: Here’s what it looks like in the app:

1 Like

Thanks that .. and how are you capturing in your code the events coming from the globals ?

Subscribe ( xxx,yyyy,zzzz)