Mount Google Drive On OpenHAB

This how to helps you to learn Mount Google Drive On OpenHAB. I am leveraging on openhabian, rclone and a Google Drive (Google Cloud) service account.

Mount Google Drive On OpenHAB

Mount Google Drive On OpenHAB

Index Of How To Mount Google Drive On OpenHAB

Background of Mount Google Drive On OpenHAB

In this how to i am leveraging on the following components:

  • Raspberry Pi 4
  • openhabian 3.4.2 as the operting system
  • Google Drive (Google Cloud Service Account)
  • Rclone

How To Mount Google Drive On OpenHAB

To mount Google drive we leverage on a four step approach:

  1. Get A Google Client ID which is needed to mount the google drive
  2. Install And Configure Rclone
  3. Testing whether its working
  4. Mount the Google drive permanently, hence you make it headless

1. Get A Google Client ID

First of all, you like to make Google ready. To do so you login into the Google Developer Console. Within Google Google Developer Console you execute the below steps:

  1. Select on top of the Google Developer Console “Project” -> “NEW PROJECT
  2. Give it a name, e.g. “OpenHAB”. As for “organization” i have selected “No organization” and click “CREATE“.
  3. Ensure you have selected the created project on top of the site after the “Google Cloud” logo. In my case its “OpenHAB”
  4. On the left hand site you now click “Enabled APIs and services“.
  5. Below the search bar click on “+ ENABLE APIS AND SERVICES” and search for “Drive“. Select “Google Drive API“. Once selected, click “ENABLE“. The window will now show you statistics (that will appear empty).
  6. On the left hand site click on “Credentials“and you will note on the upper part of the page a blue link called “+CREATE CREDENTIALS“.
  7. Click the blue link called “+CREATE CREDENTIALS” and select “Service account“. This will open a menu starting with step 1.
  8. In step 1, enter “OpenHAB” to the “Service account name“. Following this, it will create automatically a “Service account ID”. You are free to add a description. Click however on  “CREATE AND CONTINUE
  9. In step 2, you give the role of “Owner” and you click “CONTINUE” 
  10. In step 3, I have not changed anything but just clicked clicked “DONE
  11. Now, on the left hand site of the Google Developer Console: Click on “Credentials”
  12. You will find an entry under “Service Accounts“, something like “openhab@openhab-XXXXXX.iam.gserviceaccount.com“. Klick on it and it opens a new page. 
  13. Click on “KEYS” and following this, click on “ADD KEY” whilst saying “Create new key
  14. Select “JSON” and click “CREATE“. This also allows you to safe the private key on your computer. 

This key needs to be copied to your OpenHAB. Leverage on SSH tooling or on SCP. If you like to learn more about SCP, check out this great How To for SCP

Note: To make the next steps work, safe the file under “/home/openhabian/GoogleDriveKey”

2. Install And Configure Rclone

Installing rclone is easy. You simple fire the below command on your OpenHAB console:

sudo apt-get install rclone

Once you have installed rclone, you need to configure it: To do so leverage on the below command:

sudo rclone config

This will open a console based guided menu. You like to select the following options:

  1. New remote (n) and give it a name, e.g. “OpenHAB
  2. Google Drive “drive” (18)
  3. client_id> –> you leave this blank and just hit enter
  4. client_secret> –> You leave this blank and just hit enter
  5. scope> –> you select 1
  6. root_folder_id> –> add the OAuth 2 client ID that you can find under the service account section in the Google Developer Console
  7. service_account_file> /home/openhabian/GoogleDriveKey/openhab-XXXXXXXX-XXXXXXXXXXd.json –> or put which ever path you have saved your .Json file. 
  8. Configure this as a team drive? n
  9. Edit advanced config? n
  10. Configure this as a Shared Drive (Team Drive)? n
  11. Once it says “Configuration complete.” Enter to keep this “OpenHAB” remote. 
  12. Finally say to close the menu

3. Testing

Let’s do some tests now. If you fire the below command, then most likely you do not get any feedback or a simple empty feedback. This is good! If you get an error message however, than you need to reconfigure leveraging on step 2.

sudo rclone ls OpenHAB:

Now let’s create a file and copy it to check whether this works. We create a file called file.file . This we will copy to Google drive. 2 steps:

sudo touch file.file

sudo rclone copy file.file OpenHAB:

Lets now check whether the file was copied by fire

sudo rclone ls OpenHAB:

This should give you something like this as a feedback:

0 file.file

If that’s the case, than you are fine!

4. Make It Permanent

First of all, we will be creating a new service. To do so, we create this file:

sudo nano /etc/systemd/system/rclone@GoogleDrive.service

Into this file you will be copying the following:
# service to mount Google Drive by rclone
# Place the file into /etc/systemd/system/ following how to guidance on https://www.myhowto.blog
# Once the file was placed, reload the systemctl deamon by typing systemctl --user daemon-reload
# To start the service type: systemctl --user start rclone@OpenHAB
# To stop the service type:: systemctl --user stop rclone@OpenHAB
# To restart the service type: systemctl --user restart rclone@OpenHAB
# To check the service status type: systemctl --user status rclone@OpenHAB 
[Unit]
Description=rclone: Remote FUSE filesystem for cloud storage config %i
Documentation=man:rclone(1)
[Service]
Type=notify
ExecStartPre=/bin/mkdir -p %h/mnt/%i
ExecStart= \
  /usr/bin/rclone mount \
    --fast-list \
    --vfs-cache-mode writes \
    --vfs-cache-max-size 100M \
    %i: %h/mnt/%i
[Install]
WantedBy=default.target

Save and exit. To enable the service we fire the below 3 commands on the command line:

openhabian@OpenHAB:~ $ sudo systemctl enable rclone@OpenHAB
openhabian@OpenHAB:~ $ sudo systemctl daemon-reload
openhabian@OpenHAB:~ $ sudo systemctl start rclone@OpenHAB

Once done, lets test whether the drive is permanently mapped to the folder in /root/mnt/OpenHAB:

sudo ls -la /root/mnt/OpenHAB

This command should provide you with the list of files. If you followed this How To, than you most likely will find in a minimum one file that is called “file.file”.

That’s actually it. You maybe like to restart to doublecheck. 

Additional Information

More information about rclone can be found on the official rclone page. There is also a how to that I have written earlier, though this might not work anymore properly since Google changed some items on OAuth. You maybe like to check out this as well. Its more related to Raspberry and less directly to OpenHAB.

If you like to leverage on Google drive to backup your OpenHAB, then you maybe like to check out the “Hardening of OpenHAB Guide“. 

Follow me

It would be amazing if you follow my myhowto.blog. To my blog is actually easy! You can leverage on

  • Click to follow me on Twitter
  • Bookmark this page and comeback from time to time

Help and Comments

I am really looking forward for you to contact me if for example you found a better option or other idea then in this how to. Also, please touch base if you found an error or anything not working or if you have something that you would love to be added to the myhowto.blog. Simply click this link to touch base with me.

Linking Or Recommending The How To Or The myhowto.blog

I would love to see you are recommending this how to or link it to your website. Also, I would love if you link or recommend the whole myhowto.blog. Please feel free to do so! In case you like to touch base regarding this topic with me, then simply click this link. I look forward!