Demo of Keyboard Maestro to control Apple HomeKit


This is a simple demo of how to use KM to control a Homekit device. It's a very simple demo so don't expect too much here. Currently Homekit has no way to control devices (like fans) based on temperature values, even though HomeKit itself can display the temperature reported by HomeKit devices. Even worse, although you can read the temperature on the Apple Home screen, it's not selectable text so it's tricky to get KM to interpret the temperature. But I like challenges, and I love the Find Image action in KM!

Let's get started. Here's what I see at the top of my Apple Home window, which shows the temperature in my house:

One of the challenges is that you can see the temperature above but you can't select it so it's tricky, but not impossible, to deal with this. Someday KM may have hooks into HomeKit, and someday KM might have OCR built in, but currently it does not so we're going to use a trick using the Find Image action to get this to work.

In my case, if I owned a fan that HomeKit could turn on, I would solve the problem this way: I would create a KM macro to periodically search for the graphic image containing the letters "Living Room 7" (ie, the first digit of "70 degrees") and when that image appeared I would click on the Home icon to turn the fan on. Also in the same macro I would check if the image containing the letters "Living Room 6" appeared and when that image appears I would click on the Home icon to turn the fan off. It would look very similar to this: (this is just a sample to show the idea)

I'll be the first to admit there are downsides here, like your computer has to be running, along with KM, and you need to have Apple Home on the display. And it will take a little more work if you want to trigger on a different temperature than 70 degrees. Here's how I would tackle that. I would create one statement like the following for each number from 60 to 80, which is a cheap form of OCR. This essentially gets the temperature into a KM variable as a value.

Apple's Home product is pretty half-baked because you can't use Option +/- to zoom in and you can't get it to work with the Accessibility feature in macOS. And if you click on Edit / Speech / Start Speaking it doesn't speak anything useful. But with some ingenuity in KM you can make it work. And even if you don't like this solution, it may give you ideas for other problems.


Thanks for sharing. I'm sure it will be useful to many.

I moved your topic to the "Macro Library" section.
Could you please edit your post and upload the Macro file?


Thanks for moving it to a better location. There are 2 reasons why a macro upload won't help users in this case. 1) My screen resolution is different from everyone else's so my captured images will not help users. 2) When anyone resizes the Home App the bitmap actually changes colour around the buttons so the images become void/different. As a bonus excuse, I'm a noob who doesn't know how to upload a macro. I tried "Copy as XML" and "Copy as Text" and neither of those ideas worked. Aha! I found File / Share / KM Forum. But it's completely unclear to me how to add it. There are six possible buttons I can't decide what to click on: Get, Check, Upload, Upload, Both, and New Topic.


There might be a way in apple script to get the value.

We use apple script to toggle the volume on a device.

set muted to output muted of (get volume settings)
if not muted then
	set volume with output muted
	set volume without output muted
end if


Even so, just having your Macro as a starting point would be a big help to a lot of people.

It's actually very easy:

  1. Select the Macro in the Macro panel
  2. From the KM Editor menu: Export Macros
  3. Upload that file (.kmmacros) to the forum (drag/drop, or via the upload button.

You can also see: How to post/upload your script/macro


Okay I attempted to follow your instructions. It's not as easy as you claim (those instructions are about 300 lines long and I wasn't sure which set of instructions to follow). I think I uploaded it, but my first problem is that I can't find it now. Shouldn't it appear either on this page or on the index page? Can you find it? I want to be the first person to ridicule myself for not understanding... there I feel better.


I gave you the simple version:

But maybe you need Step 3.1:

  • Edit your Original Post (OP)
  • Click where you would like to upload the macro file
  • Now drag/drop .kmmacros file from Finder to Forum post; or use the upload button

Is any of that unclear?


Just to be clear, the link I gave you to the KM Wiki, How to post/upload your script/macro, is NOT 300 lines. It is only 12 lines. Perhaps you went to the wrong page.

1. Upload Using Share Button

(Available for Keyboard Maestro version 7+ only)
This will create a new topic in the forum category you select.

  1. Click on the Macro name in the Editor
  2. Click on the Share button
  3. Change the “Category” to “Macro” if you are sharing a working macro for others to use
  4. Leave the “Category” on “General” if you are asking a question related to the macro
  5. Click on the “Both” button
  6. :!: Note: If you just click on the “New Topic” button, it will NOT upload your macro.

To move the uploads to an existing topic , see instructions below these screenshots.


Well, as I said, "I think I uploaded it" and I did that using the exact instructions you posted above (steps 1--5). But I couldn't find it. I'm not even sure where I'm supposed to find it. That's why I asked "Can you find it?" Maybe I just don't know where to look. Perhaps I was overstimating the number of lines when I said "300" so I actually copied all the text from the page "" into a macOS Terminal window and got only 142 lines. So I apologize for saying "about 300". no doubt you will respond by saying that only half that page is about actually uploading macros. So that brings it down to about 75 lines. Which is much less than 300.


If you followed my simple instructions, it would appear in your original post at the location where you clicked and then did the upload. I looked and it is not there.

Please quit exaggerating the number of instructions and the difficulty in upload, as it may cause confusion with other readers.

Forget about the Wiki article. Maybe you would prefer video instructions:
See this video: How To Upload Macro to Existing Post in Keyboard Maestro Forum

If that does not work for you, then I don't have much else to offer.

Good luck.


Feel free to delete my posts if you think I'm confusing other people. I don't mind. It would be helpful if you don't delete until after my problem is resolved.

That video was extremely helpful. I did everything exactly as you did up to the 2 minute mark. But I did not see anything shown after that point in the video. I didn't know I was supposed to see anything after that as it's not mentioned in the documentation after step 5 in this page: (All of the steps in the video after that point are not found on this page.) If that documentation had explained what I was supposed to see and do next then I probably would have realized I wasn't getting that window. My guess is that maybe Chrome, which I used, isn't compatible with this website. I see in your video you were using Safari. I can try using Safari later if that's a requirement.

I profusely apologize for not being able to understand how to do this. I can see that you think my claim of the number of lines of instructions was overstated, which is why I carefully justified it with the "wc -l" command. That made my estimate a precise value, in fact it was an underestimate because it didn't include any of the lines of text in the images. If I had included that it would have been 10% higher.

And I agree fully with your statement in the video that "this part can be a little bit confusing." But after watching it three times I think I understand it now.

I will reiterate my theme that Keyboard Maestro is a fabulous product that has changed my life. Don't let this little problem with this website change that impression of me. I love KM.


Hi Sleepy,

FYI, I just posted a "Type To Siri" macro that allows you to use KM to control HomeKit devices, without using on screen images. You simply run a query from a KM Macro with Text. You could use this to poll the temperature every x amount of time and do some other action based on the response you get from Siri - i.e. Query = What is the Temperature in the Living Room? Siri's Response: The Temperature is 75 degrees etc. - and you can capture the response to then use a KM If Then etc., to run other macros, based on the temp number in the response.

Good Luck


Nok, your new thread on this subject is beyond brilliant. By comparison my approach is below boneheaded. People should avoid my approach here and switch to yours instead.

However the Find Image action, which I use (overuse?) is still a spectacular action. This thread might still help inspire others to use Find Image. I use Find Image to deal with apps that have no programmable interface. A new app that came out yesterday from Apple is News+. I doubt there's any API for News+ so it's possible I may be using Find Image to deal with it.