Hi everyone, I just installed VSCODE with the extension for OH, and I am using OH3 on Raspberry. In the VSC settings I do not in any way set the correct address for “host”, in order to use the extension correctly. I tried both with IP 192.168.etc and with xxx.local etc … with and without ports etc … but I can’t find a solution.
I am using VSC on MacOSx latest version and the OH volumes are already mounted. I have searched in various forums, communities, google, etc … but I have not found solutions … or at least updated solutions. thank you all !!!
You will need to create an auth token by visiting
http://{your_oh_ip}:8080/createApiToken
here is my config for the extension in VS code on a mac.
"openhab.connection.authToken": "oh.VSCODE.blah blahblahohmyyoushouldn'tbe lookingathisasitsmysecret",
"openhab.connection.host": "10.0.10.231",
"oh-alignment-tool.enableBetaFeatures": true,
"openhab.languageserver.remoteEnabled": false,
…mmm… I don’t understand if I have to modify user setting or workspace setting, could you pls see what I did if it is correct ?? thanks
Here you are my workspace setting (user setting is empty) :
{
// Impostazione set icone
“workbench.iconTheme”: “openhab”,
// Porta utilizzata
// "openhab.port": null,
// comando per abilitare preview basicUI in VScode
// "openhab.sitemapPreviewUI": "basicui",
"window.zoomLevel": 1,
"[openhab]": {
"editor.defaultFormatter": "max-beckenbauer.oh-alignment-tool"
},
"workbench.startupEditor": "newUntitledFile",
"C_Cpp.updateChannel": "Insiders",
// Token API per accesso esterno :
// oh.VisualStudioCode.xxx
"openhab.connection.host": "192.168.1.yy",
"openhab.connection.authToken": "oh.VisualStudioCode.xxx",
"oh-alignment-tool.enableBetaFeatures": true,
"openhab.languageserver.remoteEnabled": false,
"openhab.itemCasing": "snake"
}
THANKS !!
Looks good so far (besides that you should not post api keys in a public forum).
Are you facing any problems?
I am not sure what the problem is.
With a correct host and auth token you should be able to receive items and things in the sidebar when opening the openHAB item/things explorer.
Also extension should report a succesful token configuration in the related output.
are you getting any errors in the extensions log/terminal in vscode?
if so please post.
Hi Jerome,
I do not quite understand the using of the tokens (when) and if necessary how to create.
I have running two Pi’s (OH2 + OH3), with settings.json in the ".vscode-Folder)
The settings.json for OH2-Pi is:
{
"openhab.languageserver.remoteEnabled": true,
"openhab.languageserver.remotePort": 5007,
"openhab.connection.host": "192.168.178.xx",
"openhab.connection.port": 8080,
"openhab.useRestApi": true,
"openhab.connection.basicAuth.username": ""
}
The settings.json for OH3-Pi looks like:
{
"openhab.connection.host": "192.168.178.yy",
"openhab.connection.port": 8080,
"openhab.languageserver.remoteEnabled": true,
"openhab.languageserver.remotePort": 5007,
// "openhab.sitemapPreviewUI": "basicui",
"openhab.useRestApi": true,
"openhab.connection.basicAuth.password": "sagichnicht",
"openhab.connection.basicAuth.username": "weissichnicht"
}
and a “Default-settings.json” on my Windows-Machine:
{
"openhab.languageserver.remoteEnabled": true,
"openhab.languageserver.remotePort": 5007,
"openhab.connection.host": "192.168.178.xx",
"openhab.connection.port": 8080,
"openhab.useRestApi": true,
"window.zoomLevel": 0,
"editor.fontSize": 12,
"editor.renderWhitespace": "none",
"editor.renderControlCharacters": true,
"breadcrumbs.enabled": true,
"workbench.startupEditor": "newUntitledFile",
"editor.minimap.enabled": false,
"workbench.statusBar.visible": true,
"workbench.activityBar.visible": true,
"workbench.sideBar.location": "left",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
"workbench.iconTheme": "openhab",
"editor.fontLigatures": false,
}
and at the very end I activated the API-Security-Switch (Allow Basic Authentication) in my OH3-Settings.
Now I’m a bit confused where to set the Parameter “openhab.connection.authToken”:, and what Key I have to use and how to create, if necessary. Do you have some hints for me ?
Thx in advance - Peter
It should not be necessary to enable basic authentication. I recommend to remove all openhab settings in your settings .json and start over with a fresh minimal set like this:
"openhab.connection.authToken": "oh.***.***",
"openhab.connection.host": "192.168.0.54",
"openhab.connection.port": 8080
To create the API key you navigate to your profile page (lower left corner of you openhab ui where you see the user when logged in). There you can create an API token for your VS Code (then insert it into the configuration).
Hi @fibu-freak
Short answer:
→ What @patrik_gfeller says
Longer answer:
In your environment i would focus on two things in general:
- Keeping the config for each environment on it’s own
- Avoid using shared configurations in user config
Both should already been achieved with your settings.json approach shown above.
Anyways you could double check possible existing user settings and move them to the OH3 or OH2 environments.
About auth tokens and basic auth:
Basic auth may be used in some cases but is not mandatory.
So it is up to you and your environment to choose if you need those settings.
Basic Auth was/is a common settup in openHAB 2, which does not provide any api authentication, as a (more or less) workaround.
Since openHAB 3 implements a native authentication, basic auth is obsolete there, if it was just used as such a workaround.
You can then completely remove the basic auth from your environment (and vscode settings afterwards) and instead use a proper apitoken.
Generation explained:
vscode extension will then use the token in a http header, instead of trying to use username password in requests.
This seems to be more failproof so far, at least from my observations.
Hi to all, I do a lot of test but nothing work…
I only would like to understand the right combination between configuration on OH3 and setting.json in VSC. On OH3 I have to use the switch “Allow basic hautentication” ? in combination autToken in VSC? Or with username and password in VSC ?? etc…etc…
I try all this configuration with and whitout “Allow basic hautentication” but nothing work,
sorru but I’, still don’t understanding the right configuration, thanks
"openhab.connection.authToken": "oh.VisualStudioCode.xxxxxxxxxx",
"openhab.connection.host": "192.168.1.10",
"openhab.connection.port": 8080,
"openhab.useRestApi": true,
"openhab.languageserver.remoteEnabled": true,
"openhab.languageserver.remotePort": 5007,
"openhab.connection.basicAuth.password": "aaaaaa",
"openhab.connection.basicAuth.username": "bbbbbb",
What data did you configure in there?
aaaa = username for web ui ?
bbbb = password for web ui ?
Yes i try it’s. Isn’t clear what they have to be,
in any case my username e pw for webui is equal to username e pw i put for token…
Please remove them completely basicAuth
and Web-UI are completely different things.
host
, port
and authToken
should be enough te get the connection running.
Hi @Confectrician and @patrik_gfeller !
Thx for your help. Even if I do not understand everyhing correctly (i.e. “Avoid using shared configurations in user config”), I understand that do not need
"openhab.connection.basicAuth.password": "sagichnicht",
"openhab.connection.basicAuth.username": "weissichnicht
anymore in OH3-settings.json, but using now
"openhab.connection.authToken": "oh.***.***",
included a Token created within OH3, as @patrik_gfeller explained.
And thx again @Confectrician for the “Longer answer”.
Cheers,
Peter
ok finally now it works, and the one above is the step I did. I deleted the previous token in OH3 and generated a new token, deleted all settings in VSC for both workspace and user, and only re-entered these three settings as USER :
Now from VSC I finally see Things and Items.
Thank you all !!
Short clarification on this in different words:
It would be useful to just keep all config parameters for each openHAB environment in its corresponding settings.json
(Theoretically it would be possible to only configure some of them once, but i think that is not really intuitive for the normal usecase.)
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.