VSCode Guide

Great, that there is a VSCode specific thread, so I want to refer to another post of me showing an VS-Code specific problem: Beginners Guide to create an Addon without the Eclipse IDE for openHAB 2.4 and place it in your running openHAB runtime

Hate to say - that only works because the openHAB installer created that environment variable for you (I ran into that same thing when I was doing the windows side). The others (openhab_runtime, openhab_addons, openhab_logs) probably wonā€™t work unless your environment defines those as well.

Thatā€™s why I tried the ā€œoptions.envā€ approach (makes it independent of openhab installer and options youā€™ve chosen) - which works on windows but doesnā€™t on linux/osx based on this thread.

Iā€™m going to spin up my linux environment and will see if I can find a solution for thisā€¦

EDIT: after reading through that thread - you may be right that it would work on linux/osx. Again - Iā€™ll be testing shortly to find out

It works. :grin:
I run all my OH stuff in containers, except a manually installed instance, without any environment variables set, that I will use for debugging.
But Iā€™m not sure about the behavior in other shells.

Yep - I can confirm that the $openhab... definitely work on linux environments. Iā€™ll be making a change to the tasks.json shortly (I need to update the docs anyway for a markdown error). Hopefully the next version will run correctly for you all.

Hereā€™s the PR if people want to try the new tasks.json (and I also included the code formatter setup)

1 Like

Hi

Can you explain how you get VS Code to access an openhab instance on a remote linux machine? This would be my preferred setup as I have a spare Raspberry Pi to run as a dev instance and will avoid having to have maven etc on my mac laptop.

Thanks

1 Like

Unfortunately it only works on x86 Linux with the current preview version, so youā€™ll have to be patient I guess. :slightly_smiling_face:

UPDATE: The new Insider version of July now includes support for Raspberry Pi.

Thanks - is that already part of the official set up Guide for VS Code?

Not yet - still waiting on the merge

Note: this was merged sometime over the weekendā€¦

1 Like

Dear Community,

I try to fire up the VS Code debug task. Unfortuntely it is not possible find the corresponding task. I followed the VS Code guide here https://www.openhab.org/docs/developer/ide/vscode.html

Anyway I prepared the tasks- and launch-file in my binding .vscode folder. After hitting ctrl+shift+p and selecting Run task ā€¦ I cannot pick any openHAB related task to choose from.

Thanks in advance for your replies.

Best regards,
Jochen

It is solved! The problem where the slashes - I wasnā€™t expecting, that on a windows box unix related paths are necessary.

Dear Community,

these days I am starting to use VS Code more intensely. Maven is able to build my addon but lots of classes and includes are not visible, see

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.binding.BaseThingHandler;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

What is the most preferred way to add these modules to VS Code.

Best regards,
Jochen

UPDATE: It is solved. After a new start of VS Code the imports were recognized.

The Steps for each Bundle donā€™t work for me.

Steps to reproduce:

  • git clone https://github.com/openhab/openhab2-addons.git
  • cd bundles/org.openhab.binding.astro
  • mvn clean install -DskipTests -DskipChecks

I get loads of compile errors like QuantityType cannot be resolved to a type.
It seems that the imports cannot be resolved.

At the beginning there are warnings like:

The POM for org.openhab.core.bom:org.openhab.core.bom.compile:pom:2.5.0-20190717.100901-102 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

Iā€™m not an expert in maven (in the least bit) but Iā€™d clear out the .m2/.p2 directories (usually in your home directory) and try again.

I have the same problem. I followed
https://www.openhab.org/docs/developer/ide/vscode.html
but got stuck on step 10. part 2.

Press CTRL-SHIFT-P ā†’ Tasks: Run Task ā†’ Start openHAB (Debug) to start an openHAB instance in debug mode. You should see openHAB startup in a new VSCode terminal.

I get an error message:

In Zeile:1 Zeichen:3
+ & $env:openhab_home/start.bat debug
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (F://Openhabian/...-main/start.bat:String) [], Command NotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

There is no start.bat file in myopenhab_home in Windows. I guess this should start a debug instance of openhab on my remote raspi dedicated to running openhab.

Where can I find the contents of the missing start.bat?

or can I use an alternative to start openhab in debug mode on my raspi (via putty)
Will VS connect to this debug session as stated in 10.3. of the above document?