VS Code openHAB Extension!

Hi @kubawolanin
I’m now on openHAB 2.2.0 Build #1077 and Visual Studio Code 1.18.0 with openHAB Extension 0.2.0.
I still get the following error:

[Error - 09:55:17] Connection to server is erroring. Shutting down server.
[Error - 09:55:17] Connection to server is erroring. Shutting down server.

I assume this error should have been eliminated by this PR. Since this PR is already merged, could you have a new look at this issue?
Thanks!

Hi,
I installed VS Code 1.18.1 together with version 0.3.0 of the OH extension on my Windows computer. The conf-folders are available trough samba-shared. I also did the user-config (specifying the IP of my OH).

My items are loaded fine:
image

However, if I do “Insert into Sitemap”:
image

I get this:
image
I swear my .sitemap file is open.

So what am I doing wrong?

Hey @Dries
Strange :thinking: Maybe the editor has no focus in your sitemap file?
Works fine for me - just tested it on my local environment (same VSCode version along with 0.3.0 extension)

I checked the focus. I placed my cursor where I wanted to do an insert. Then I rightclick the item I would like to insert and choose “Insert into Sitemap”. And then I get the error.

Same for rules btw:
image

I’m still new to VS Code, so I’m not sure what to except from autocomplete. But so far, I see it only completes item-names, and not syntax related stuff.

This is indeed strange. Could you please raise an issue with as much info as possible for me to trace the root cause of the problem?
Please refer to your posts here too.
Thank you.

I will do! However, I just upgraded from #1082 to #1084. Now I’m again confronted with that other issue. So I’ll wait for that to be clarified. If I still have that issue mentioned in my earlier post, I’ll raise an issue.

[EDIT]
Issue logged:

Can I change the expected share location in Visual Studio Code / Plugin?

I think it is not that reasonable to have this location static.
I assume therefore the plugin can’t load the config.

My Ophenhab config is shared as //raspberrypi/Openhab

Thanks.

While this is really great and don’t get me wrong or opposed to this, but reading through all of this I have the feeling that OpenHAB is going to lean towards Windows users then, as ESHD might get even less development and enhancement attention and leave Linux users like me then either to ESHD (which is indeed far from ideal) and editing with vim.

I would have been happier to see the development forces put into one platform-independent tool that into platform-dependent ones.

Nevertheless, great job guys and as far as I can see from the screenshots it seems indeed to be a great tool. I hope it’s going to be an inspiration for the ESHD crew.

Visual Studio Code runs on Linux too, and there are packages available for most architectures.

1 Like

@antares2001 You’ve judged it too soon :wink:

VSCode is a open source tool (that happened to be developed by Microsoft employees, but not only!) that’s written in TypeScript and packaged as an Electron app. That basically means that it’s a webapp within embedded web browser :wink:

Advantage of it is that it runs everywhere - Windows, Mac, Linux - you name it.

People seem to mistake VSCode with standard Visual Studio. It’s a common misconception and I emphasize it every time - Code is a open-source text editor (very powerful and extendable). Visual Studio is a full blown IDE.

That openHAB extension is for Code. Not Visual Studio.

Cheers!
Kuba

2 Likes

Hi @kubawolanin

I haven’t judged it too early I simply lack that knowledge. Indeed, I read this as “Visual Studio” and was not aware of “Visual Studio Code” as something separate. Perhaps they should have thought of picking a different name. Sorry for that - I learned something new.

Well - in this case I have to revise my words and can only leave those that say that it’s a great job you’ve been doing and I think I’ll have to try it out in this case :slight_smile:

2 Likes

Sure, just open your shared folder.

The only thing you have to edit is your network name (or ip adress):

1 Like

Hi! I have 4 openHAB2 servers, geographically far from each other. Between them is configured VPN. In VSCode to open the configuration of any of these servers is not a problem, but things and items will be those whose address is registered in the settings. Can I make sure that when opening the desired configuration folder, open things and items of the open configuration?
I found the folder “.vscode” in the directory “/etc/openhab2”, tried to save the settings in it, it did not work. Should this work? Maybe I did not have enough rights settings or something else?

What did you do:
I deleted all my settings, deleted the catalogs “/etc/openhab2/.vscode”, rebooted the VSC, opened the remote folder, opened the rules file, got the error: “Error while connecting to openHAB REST API.”. I pressed the “Set openHAB host” button. Entered:

{
    "openhab.host": "192.168.1.14",
    "openhab.port": 8080
}

Saved changes (Ctrl+S).
There was a catalog “/etc/openhab2/.vscode” with the file settings “settings.json”.
opened the rules file, got the error: “Error while connecting to openHAB REST API.”.
http://192.168.1.14:8080/rest/things - opens
Что я еще не сделал?
the same at two settings:
openHAB 2.2.0 Build #1084 and openHAB 2.2.0 Build #1099
nor any records in the log file.

Read about difference between User and Workspace Settings in VS Code.

Yes, I learned and tried to reconfigure everything, as I wrote a post above, but now I get an error:
Error while connecting to openHAB REST API.
I do not understand why, the settings were saved in /etc/openhab2/.vscode/settings.json
then there are enough rights, and what I do not have is not understood. I read all the branches about VSC, but I did not find the answer, maybe I missed something, because my english is google translator, very bad :frowning: You can edit the configuration this way, but I would like to use all the power of your work!

I do get the same error when creating new files using VS, so whenever I need to do that I open up putty and then cd to right directory and do sudo new.items then sudo chmod 777 new.items

I am not a linux fan, but I guess it has to do that the VS is run as another user then the samba share and hence can not create new files, just alter files in the samba share… However for me I dont often make new files so I never bothered to investigate it further…

You have to use force user for samba share:
in smb.conf:

[openhab_conf]
        valid users = openhab,@openhab
        write list = openhab,@openhab
        force user = openhab
        force group = openhab
        path = /etc/openhab2

should be self explaining…

Hi,

no chance:

Neither Hostname nor the path. My understanding is, that when I access the share from my MAC or WIN machine I’ve to use the share \OPENHABIANPI\openHAB-conf.

I’ve tried to open the folder of my existing share. When I open a rules file I get the known REST error.

Error while connecting to openHAB REST API.

Samba share (e.g. \OPENHABIANPI\openHAB-conf) Local folder (e.g. c:\openhab\configuration)

What is the best practice opening the config files when OH2 server has a different hostname?

Thanks.

Don’t open the rules folder directly, open the conf folder of your openHAB.
And don’t forget to change the settings:

{
    "openhab.host": "192.168.x.xxx",
    "openhab.port": 8080
}
1 Like