Import URL Requirements by Hubitat?

Question (per title):
What are the requirements to be able to have the Import URL work successfully in a driver?

Longer version... None of my drivers are able to be successfully imported. I host them on my own domain, not Github. The URLs are all valid and copy/pasting them into a browser, then copy/pasting the ,groovy file displayed works fine, but it is extra steps and I would like to make it easier for users of my drivers. So... why will they not work? Does Hubitat only allow github sources? Does it require a particular MIME format? In one of my driver threads it was mentioned that maybe they were being served incorrectly and needed to be plain text. I have since added a MIME Type that should always serve files with the "groovy" extension as text/plain, so that does not seem to be the case.

Thoughts from anyone?

1 Like

Just ran into this myself with my install of GitLab EE and it turns out you need a personal-token in the URL to pull the file into HE.

My error was this that @chuck.schwer gave me...

Access to XMLHttpRequest at
'URL' from origin 'https://192.168.xx.xx' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.

@anon61068208: I also see you posted in gitlab about disabling the CORS policy...

So if this is a Server Side CORS issue... I have no idea how to solve it. I tried enabling CORS on my server by making an edit to the .htaccess file but it had no impact. Still does not import. The irritating thing is that the editor gives the warning it is going to override it and everything but absolutely nothing happens. Nothing is in any of the logs I know to access either so how would someone have any idea what is happening or why, or how to solve it.

Anything from anyone at Hubitat with a specific answer? This really does not feel like something that should ONLY work with github, but...

GitLab is suppose to be the Open Source version of GitHub so theoretically it should be allowed.

I think how GitHub does it is via it's own rails that serves the raw content similar to how git pages work.

I have found only 1 work around for private repos and its very clumsy at best.

For public repos I think you could publish them like pages by editing .gitlab-ci.yml -- I'll have to check this first though.

Read this thread... linux - Open a file directly from a GitLab private repository - Stack Overflow

The answer that has the most vote is the url I used to get it to work but its clumsy at best.

Ok so I tested this with GitLab pages...

# This file is a template, and might need editing before it works on your project.
# Full project: https://gitlab.com/pages/plain-html
pages:
  stage: deploy
  script:
    - mkdir .public
    - cp -r Driver/* .public
    - mv .public public
  artifacts:
    paths:
      - public
  only:
    - master

So say your repo contains your groovy files under Driver/
image

This yaml will copy that folder to your pages location.

image

Once your page is created the URL to those groovy files will be in this format....

http://YOUR-GIT-PAGE/project-name/groovy-file.groovy

In my case that would be...

http://sgrayban.borgnet.online:8081/raspberrypi.monitor/Raspberry-Pi-DHT-Sensor.groovy

image

Then you can import the file as normal.

Now every time you make a commit to that repo your pages will auto update and copy the new version to the git-pages.

1 Like

@snell I have a ugly hack but it works

http://sgrayban.borgnet.online:8081/raspberrypi.monitor/index.html

You can look at https://gitlab.borgnet.us:8443/sgrayban/raspberrypi.monitor/tree/master

And see how I did this.

1 Like

This only works using Gitlab though correct?
So another git. I am just serving the drivers from a basic website. It should not be so complicated or even CARE where it imports the code as long as it is basic text (MAYBE, and a valid URL of course).

So this still will not work for me unless I set up a git myself... But I will not bother. So either I discover another workaround, Hubitat answers with an alternative, or my drivers remain unable to be imported.

@anon61068208: Thanks for continuing to dig into this.

This will work at gitlab.com also.

Here is a updated one that creates the index file and tree in one shot.

pages:
  stage: deploy
  script:
  - cd public/
  - tree -T "Public drivers for Hubitat" -P *.groovy --noreport --dirsfirst -H . -o index.html
  artifacts:
    paths:
    - public
  only:
  - master

That produces this...

The files are in a basic folder, not being served by a particular page. There is no underlying php or such, nor even an HTML page. I just have the raw text .groovy files. The only references to them are links from here, an HTML file with links from my domain, and then Import links (in the drivers and in the version.xml file I keep in that same folder).

They are all here: Drivers Folder

In any case, I altered the .htaccess to allow CORS per the Apache settings a long time ago (when I was last trying this):
Enable CORS

At the same time I made "groovy" as a text/plain content type as well... Although I just altered that to be ".groovy". But that does not seem to have changed anything.

Totally open to additional recommendations...

Recommendations for what? All of your URL's imported just fine for me.

1 Like

I agree. I tried
https://www.drdsnell.com/projects/hubitat/drivers/Neurio.groovy
and it imported just fine.

1 Like

WHAT?! I tried to Import again last night (changed one of my drivers to say "hi" at the beginning just to test it, with no success. I just tried this morning after seeing your comments and it worked, for the first time EVER.

I made that one change to make it ".groovy" vs "groovy" last night... maybe the server took a bit to migrate the change?

So it was the "." that mattered... 6 months... and all I needed was a ".".

Thanks for bearing with me and prompting me to check again!

3 Likes

No worries! Glad that you got it working.

I wanted to post notice of this on all four of my driver threads, but the forum did not like how similar the text was. On well. :smiley: