Rule Machine and Google Drive API

I had to take a step back at another topic I'm looking into, to figure out how to do a particular activity.

I see examples out there on how to write various data to, for example, a spreadsheet on Google drive, using Rule Machine and the Google Drive API. The examples I see are very complex and specific.

Can anyone explain to me how to create a simple, let's call it a "hello world" type, rule in Rule Machine to write a file to Google drive? The rule's action would be "Send, Speak or Log a Message, Send HTTP Request", and I assume "Send HTTP Post". From there, I'm not sure what content type would be used, the URL to use, or the body for the POST. To make the example specific, it would:

  1. Create a text file, "Hello.txt", in the directory of "Hello" in Google Drive.
  2. The text file would contain the text "Hello World".

I can tell it will likely involve creating a project in my google account, getting API keys/tokens, etc. I'm sorry to ask for something so basic. Any help is greatly appreciated. Googling for a simple example bore no fruit for me.

1 Like

Very likely, you would have to craft the necessary code in Google Apps Script -- running behind something like a Spreadsheet -- for the purpose of "pulling" the file(s) into a folder in Google Drive. I don't think it would be worth the effort to try building an app on HE to "push" files onto GD, because of the complexities of OAuth, folder permissions, etc. (I know I don't have the chops, esp. with regard to writing Groovy scripts on HE, and I quickly get lost in Google's API documentation).

Using RM's HTTP Request feature, you could "trigger" your GAS application to run and pull the file to wherever you want it.

What's your ultimate goal with the file(s)? Just keeping them for archival purposes?

Sorry to be long-winded, but my end goal is to have Hubitat act as a backend for Assistant Computer Control ("ACC").

ACC is an application for Windows that listens to configurable folder for a text file. Based on the contents of the file, it executes certain actions on the PC, such as mute the sound, unmute, reboot, lock, etc.

The typical way ACC is used involves using a voice assistant (Alexa or Google Assistant), IFTTT, and a cloud storage app (Google Drive, OneDrive, or Dropbox). Users set up an applet in IFTTT, which is triggered by Alexa. The applet writes the text file to the folder on cloud storage, then ACC reads it and performs the actions, deleting the file when done.

The way ACC works, it occurred to me you could cut out IFTTT and even possibly cloud storage entirely. All ACC requires is the file in a specific location. If IFTTT could create the file in a folder ACC can monitor, that's all that's needed. I was looking into using the local file option in Hubitat, but it doesn't appear to write a file to a folder that can be monitored by ACC. I did see it appears Hubitat can use Rule Machine to make API requests, so it seems that would be an option too.

I know that's a lot of detail, but it sums up what I'm trying to do.

In that case, I might recommend looking into the freeware EventGhost as an alternative application to accomplish the same things. No need for files, just URLs.

PowerAutomate may also be an option, I posted on the similar thread around saving a text file to a network location. Was able to do this quite easily. I imagine you could save the file locally into the Google Drive folder if you wanted / needed to do this, but it sounds like that was more of a way to get the files locally transferred in this case.

Just updating this thread for anyone that has a similar need and comes looking.

I investigated event ghost, and ultimately decided it was a FAR better solution for my needs than Assistant Computer Control could ever be. As a result, I abandoned looking down this rabbit hole. I suggest anyone looking for a similar solution do the same. :slight_smile:

1 Like