Experimental: Preconfigured Eclipse Theia remote IDE for openHAB

Hi all,

I have played a little bit with Eclipse Theia today and ended up having it working on my PINE A64 alongside my OH instance. Theia is very similar to VS Code and can run VS Code extensions (including the openHAB extension!). I see potential in this to provide a preconfigured, ready-to-go, predictable environment, and perhaps even advanced editing features like extensions to provide e.g. ways to edit JSON DB-based entities on the local instance. Because all settings and preferences and workspaces reside on your server, you can access the IDE from any device and resume editing.

Also, the “open console” command works out of the box - since the terminal runs on localhost no need to allow SSH access for other hosts.

image

Maybe Docker images could be uploaded to Docker Hub in the future for different architectures, but for now you’ll have to build it yourself. I have successfully built it on my PINE A64 where my production instance is, and on my AMD64 workstation.

Instructions with screenshots below (copied from GitHub - ghys/openhab-ide: A pre-configured Eclipse Theia (https://theia-ide.org) tailored for openHAB development & configuration, to install on your appliance.). Let me know if it works for you if you try it!


Prerequisites

  • Docker 19.03+

  • 4 GB+ of free disk space for the image

  • 2 GB+ RAM preferred (might work with 1 GB but no guarantees)

It’s also possible to run outside Docker. Check the Theia prerequisites (node, yarn, build tools…): Theia - Cloud and Desktop IDE Platform and adapt the commands from those in the Dockerfile.

Build the image

(TODO: docker-compose file)

1. Clone the repository

git clone https://github.com/ghys/openhab-ide
cd openhab-ide

2. Build the image

docker build -t openhab-ide .

The build process can take a while (~30 minutes on a PINE A64 with 2 GB RAM), be patient.
It should end with:

Successfully built 72a1c4ec78cd
Successfully tagged openhab-ide:latest

3. Run

Start a container with the newly built image (define $OPENHAB_CONF or replace it below with the location of your openHAB configuration folder e.g. /etc/openhab or /opt/openhab/conf):

docker run --rm -v $OPENHAB_CONF:/srv/openhab --net=host --name openhab-ide openhab-ide:latest /srv/openhab

(--net=host ensures your local openHAB instance on localhost:8080 (by default) will be accessible.)

4. Retrieve the token to access the IDE

Run:

docker logs openhab-ide

and look in the logs for:

...
access url: https://0.0.0.0:10443?token=9b2a11b5da6ff262b7a73d9676f63bc5
token: 9b2a11b5da6ff262b7a73d9676f63bc5
...

Copy the token.

NOTE: The token is generated randomly by default and will change every time you run the container. You can add e.g. -e token=mysecrettoken in the docker run command above to define it yourself.

5. Open the IDE in a browser

You will get a HTTPS error (“your connection isn’t private” or similar) because the TLS certificate is self-signed and invalid. Ignore it the warning for now - click Advanced then Continue (or similar).

Open https://<host>:10443 and paste the token in the login page.

image

(You can also open directly https://<host>:10443?token=<token> and/or bookmark the address with the token once you’re in).

Verify that your configuration appears in the file explorer on the left, and that the list of items from your local openHAB instance appear.

There will be an error for the list of things, however, because you have to configure the authorization to the API by setting an API token.

Follow openHAB API tokens | openHAB to generate one, then in the IDE, open the File > Settings > Open Preferences menu, and in the openHAB section, click Edit in settings.json below Username and specify the token there.

The settings should resemble the following:

{
    "openhab.host": "localhost",
    "openhab.username": "oh.ide.CFWsJZ799oi3GcLSLd1C..."
}

Save the settings.json file, and go to the openHAB panel and click the Refresh buttons in the Things pane header. The list of Things should now appear.

TODO: improve this - allow setting the API token from Docker.


Roadmap

  • Activate Python support
  • Reactivate Git plugin
  • Allow editing managed objects (using the JSON DB) in YAML with a virtual filesystem?
2 Likes

@ysc Ever checked out coder, alias Code Server ?
I wrote about it last year under the headline accessing VSC in a browser…

It seems similar indeed!
Although it looks easier to provide customizations in Theia, like removing unnecessary features to strip it down to only those required for openHAB development, add local extension points (extensions or plugins) that aren’t feasible with a vsx… and it’s also an Eclipse project so licensed under the EPL-2.0, same as openHAB, so it might be better if we adopt it as an official editor and perhaps include it in openhabian as an optional feature.

Haven‘t checked Theia for quite some time, but if I remember right, it did not support vsx extensions at the time I found coder.
If you think it could be easier to integrate, why not. I have no favour :wink:

Now it does, but I liked the fact that you can simply brand it “openHAB IDE” and pre-install the openHAB extension to make it built-in:

So we can have a customized openHAB-branded IDE ready out-of-the-box, or the full VS Code with code-server, I don’t have a strong preference either but it’s nice to have both approches available.

2 Likes