I came across an opensource app called AssistantComputerControl (ACC) that enables you to send commands to a Windows PC from a voice assistant via IFTTT. There are 28 different actions available.
IFTTT writes files to a cloud drive of your choosing, which are then synchronized to your computer. The ACC app monitors the synchronized folder, and as soon as it sees a new file it acts on the command. I’ve found it to be pretty quick in my brief tests.
At this point in time, you can’t synchronize openHAB with IFTTT via myopenHAB (due to the strain it was putting on the servers). However, you can use webhooks for one-way control from openHAB to IFTTT. With help from the IFTTT webhooks tutorial by @Jens_M, I’ve done just that.
I’m most interested in having openHAB put my PC to sleep when I turn on my Away or Night modes (meaning that I’m leaving the house or going to bed), so that’s the focus of this tutorial. However, this works for any other ACC command and for IFTTT webhooks in general.
Set up services
-
Install ACC on your Windows PC and follow the setup instructions for your particular cloud storage. You can use Dropbox, OneDrive, Google Drive, or your own IFTTT-accessible cloud. ACC just needs to know where the synchronized files will be stored on your PC.
I originally used Google Drive, but switched to OneDrive after the developer told me that Google Drive isn’t reliable.
-
(optional) Go to the ACC actions list and enable one of the commands in IFTTT for your preferred voice assistant. This will enable you to test that ACC is working, but it’s not strictly necessary.
-
Activate the Webhook service in IFTTT.
-
Get your personal IFTTT Maker Key by clicking the “Documentation” button on the IFTTT Webhooks page. You’ll need this when we’re setting up the rule in openHAB.
Create an IFTTT webhook applet
-
Open the ACC Applet Maker, then pick a cloud service, voice assistant, and action. It doesn’t matter which voice assistant you choose (since we’re not using it), but the instructions won’t generate without it. If you choose OneDrive and Sleep, you’ll get this:
Note: There’s a mistake in the Applet Maker. It says to use “computerAction” for the file name, but you actually need to use “computerAction.txt”.
Set this information aside. We’ll use it to create an IFTTT applet with a webhook as the trigger.
-
Create a new IFTTT applet. Again, I’m using OneDrive and the Sleep action, so modify as needed for your purposes.
-
Click “+This” to set up the trigger.
a. Choose a service: Webhooks
b. Choose a trigger: Receive a web request
c. Complete trigger fields: whatever you want it to be (I use openhab_pc_sleep)
d. Click “Create trigger” -
Click “+That” to set up the action
a. Choose action service: OneDrive
b. Choose action: Create text file
c. Complete action fields: enter the File Name (“computerAction.txt”), OneDrive Folder Path (“AssistantComputerControl/”), and Content (“sleep”) from the ACC Applet Maker
d. Click “Create action” -
Name your applet, choose if you want to receive notifications when it runs, and click “Finish” to save your work.
Set up an item, sitemap, and rules in openHAB
-
Create an unbound proxy item to trigger the webhook. I suggest a generic string item that can be used for any IFTTT webhooks you create in the future.
String IFTTT_Webhooks "IFTTT Webhooks" <switch>
-
Add a selection element in your sitemap (I’ve added a shutdown command to show multiple commands).
Selection item=IFTTT_Webhooks label="PC Control" mappings=[ Sleep="Sleep", PowerOff="Shut down" ]
-
Create a rule that triggers when
IFTTT_Webhooks
changes. In the sendHttpGetRequest lines, replaceopenhab_pc_sleep
with the name of your webhook, andYour_Key
with the personal IFTTT maker key we got earlier from the IFTTT website.rule "Send commands to IFTTT via webhooks" when Item IFTTT_Webhooks changed then switch (IFTTT_Webhooks.state) { case "Sleep" : { logInfo("IFTTT_Webhooks", "Sending sleep command to Windows PC") sendHttpGetRequest("https://maker.ifttt.com/trigger/openhab_pc_sleep/with/key/Your_Key") } case "PowerOff" : { logInfo("IFTTT_Webhooks", "Sending shutdown command to Windows PC") sendHttpGetRequest("https://maker.ifttt.com/trigger/openhab_pc_shutdown/with/key/Your_Key") } } IFTTT_Webhooks.postUpdate("") end
-
Use the
IFTTT_Webhooks
item to send commands from other rules.IFTTT_Webhooks.sendCommand("Sleep")
Alternatively, you can just add the sendHttpGetRequest line wherever you need it in rules.
I would say that it takes about 2-3 seconds from when I trigger IFTTT_Webhooks
from my sitemap to when it turns off my PC, but latency is largely going to be dependent on IFTTT and the Internet. IFTTT can lag at times, but it seems to be very quick to respond to webhooks.
There’s at least one other method to control your PC that is handled entirely within your local network, but I found it to be a little beyond my expertise. I like this as a relatively simple approach that can be easily deployed to multiple computers. Also, I’m okay with it being dependent on Internet access, IFTTT, and OneDrive, because it’s no big deal if one of these services is down and I have to press the power button on my computer to turn it off.