Pass variable from HomeKit to Hubitat

Hi - is it possible to set a variable in HomeKit and pass it to Habitat?

What I want to do is read an NFC tag with my phone, allow me to choose an 'alarm' time and pass it in to a Hubitat variable.

Thanks
Chris

I was impressed by some methods suggested by Gemini AI (which I've been playing with lately):

To pass a variable from HomeKit to Hubitat—specifically for an NFC-triggered "alarm time" workflow—the most effective method is using the Maker API combined with an Apple Shortcut.

Since HomeKit's native bridge only shares device states (on/off, temperature), it doesn't allow you to push arbitrary text or numbers (like a specific time) back to Hubitat easily. A Shortcut can bridge this gap by sending a direct web request to Hubitat.

Recommended Implementation

1. Setup on Hubitat

  • Create a Hub Variable: Go to Settings > Hub Variables and create a variable (e.g., alarmTime ) of type String or DateTime .
  • Install Maker API: If you haven't already, add the Maker API built-in app.
  • Enable Variable Access: In the Maker API settings, scroll down to "Allow endpoint to control these hub variables" and select your alarmTime variable.
  • Get the Cloud/Local URL: Note the "Send Device Command" URL format provided in the app. For variables, it follows this structure:http://[YourHubIP]/apps/api/[AppID]/hubvariables/[VariableName]/[Value]?access_token=[Token]

2. Create the Apple Shortcut

  1. Trigger: Create a new Shortcut. (You can later link this to an NFC Automation in the Shortcuts app).
  2. Action - Ask for Input: Use the "Ask for Input" action. Set it to Time.
  3. Action - URL: Add a "URL" action.
  • Paste your Maker API URL.
  • Replace the [Value] part of the URL with the Provided Input variable from the previous step.
  1. Action - Get Contents of URL: Add this action and set the method to GET. This "hits" the Hubitat endpoint and updates your variable immediately.

Alternative: Virtual Device "Connectors"

If you prefer not to use web URLs, you can create a Hub Variable Connector (a virtual device tied to your variable).

  • Virtual Dimmer/Volume: If you only need to pass a number (0–100), you can share a Virtual Dimmer to HomeKit via the HomeKit Bridge.
  • How it works: Moving the "Brightness" slider in HomeKit to 70% would set your Hubitat variable to 70.
  • Note: This is less precise for specific times (e.g., 7:30 AM) than the Shortcut method.

Summary Comparison

Method Best For Complexity Reliability
Shortcut + Maker API Specific values (Time/Text) Medium High (requires LAN/Cloud)
Virtual Connector Simple numbers/percentages Low High (native HomeKit)
Rule Machine Endpoint Triggering specific logic Medium High
2 Likes

You could use two virtual dimmers. One is for hours, the other is for minutes, in 24 hour time. Have Hubitat not respond to the the hour dimmer changing, but get its set value when the minute dimmer value is changed. Set the hour dimmer, then set the minute dimmer to get Hubitat to trigger off of it, and then on Hubitat side combine the two values into a time.

1 Like

How do you format the time sent via MakerAPI so it is recognized as a DateTime variable by Hubitat? Nothing I've tried seems to work.

If you're trying to set an alarm time via Apple Home / Homekit, one way I have used for the last couple of years is to:

  1. Share a virtual switch from Hubitat to Apple Home. At the Hubitat end, use the status of that switch to control an automation.
  2. Just use Siri to turn on the switch at the specified time (eg. Siri, turn on WakeMeUp at 5:45").

It should also be possible to use a prompt from a Shortcut to turn on the switch at the time obtained from input, but I haven't tried this.

While I couldn't get a DateTime variable to be passed from Homekit to Hubitat, I did get this to work using a combination of String and DateTime variables.

  1. Create two variables. One of them is a String variable (timeString below) and exposed to MakerAPI. The second is a DateTime variable (testTime below)

  2. Pass time from the Shortcut to the string variable via MakerAPI. Select a custom format of "hh:mm" for the time input.

  3. Create a Rule (or other Hubitat automation) that sets the DateTime variable to the value of the String variable

(the 99.999 should be replaced with 00.000 )

The shortcut itself looks like this:

Would be nice if someone could post a way to do this directly with a DateTime variable, instead of using a String variable as an intermediate.

I found this:

Hub variables can also use a DateTime variable to represent only a date or only a time. In such cases, the "missing" components should be substituted with the digit 9 (as many times as needed to ensure the format is still correct). For example, a time-only variable with a blank date could look like: 9999-99-99T14:25:09.009-0700 . If the variable contains only a date with blank time, the string is like 2022-10-13T99:99:99:999-9999 . Built-in app UIs would display these as only times or only dates, respectively. Your apps should also gracefully handle all three possibilities: date, time, or date and time and display appropriate presentation (and provide appropriate values back to the hub). Generally you can test for the two special cases above with startsWith("9999") or endsWith("9999") .

I was unable to pass an input string like that from the Shortcuts app directly to MakerAPI and have it set a DateTime variable, while the same format clearly works from Rule Machine (in my example above).

Be interested in knowing if you can get that to work directly from the Shortcuts app.

I've managed to get it to work as a URL - struggling to get the shortcuts app to work with any URL at the moment. Will let you know!

This part is easy. Can you create a shortcut like the one I've shown above?

THIS solves a problem I've been facing - conveniently scheduling a virtual switch through Siri. I wish I knew this earlier! THANK YOU!

Any ideas on how to get Siri to look at my calendar and schedule "Prepare the Car" (pre-warm the car) for all the times I will need to go somewhere and return? Or is that asking for too much? :laughing:

1 Like

Got it:

I've not done much with Shortcuts, so it took be a bit of head scratching.

I hadn't realised that URL simply creates a URL.

The shortcut then is

Ask for Time

Format date (ask for input). Another thing that confused me is you can't have a custom format of a time, so even though I just want the time, I had to choose date, custom format and HH:MM

That result is then pasted into the following URL

http://192.168.0.XX/apps/api/20/hubvariables/AlarmTime/9999-99-99T[Formatted Time]:00.000-0600?access_token=[TOKEN]

And finally it's opened.

Just need to find out now if it's possible to open the URL without opening the browser!

1 Like

Yes, make the final part of the shortcut “Get contents from URL”