VS Code openHAB Extension!

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

just tried it - VS Code openHAB Extension - looks great - thx for the good work

Thanks, works now.

1 Like

Works great, thanks!

Is or will it be possible to use VS Code with myopenhab? To change/operate the items/sitepam remotely?

@dimes Never tried that but I don’t think that’s possible, given that you need an access to the file system in order to read and write to the files.

In the next version of the extension you will be technically able to access the Items and Things. Note that LSP (content assist for rules and syntax validation) won’t be exposed, so you’ll need to disable it too.

    "openhab.host": "https://home.myopenhab.org",
    "openhab.port": 80,
    "openhab.lspEnabled": false,
    "openhab.username": "your_myopenhab_email",
    "openhab.password": "your_myopenhab_password",

Here’s the commit that adds that feature.

1 Like

ive noticed following problems since upgrade to oh 2.2.0 rel:

every first statement of each rule-file is marked as a problem with this strange hint of a “type is already defined in…” ive never defined. no matter whether the first statement is a var or an import.
is there something im missing creating a rules-file? some syntax issues or maybe a permission prob?

system:
synology dsm 6.1.4-15217-3
openhab as docker container based on latest “2.2.0-arm64-debian image” from 21.12.17

@rikky could you please submit a new issue on ESH repository? @sjka would you mind taking a look?

cheers

1 Like