Visual Studio Code - howto: connect to Rest API?

Hi Guys,

i found this on github:

now i want to connect with the REST API - i changed:
“Arbeitsbereicheinstellungen” & " Benutzereinstellungen"
( Workspace-Setting / User-Setting )

to something like this:

{
   "openhab.host": "openhabianpi.local",
   "openhab.port": 8080
}

also tried with IP:

But what is the Username and Password ? - i always get the same error:

Error while connecting to openHAB REST API.

thanks

There is no username and password. Do you perhaps have a firewall or something like that that mght be blocking the access?

It might work out better to install it through the standard channels:

http://docs.openhab.org/configuration/editors.html#openhab-vscode

nothing blocks - still the same error :frowning:

which settings do i need to edit ? nothing ?
thanks

Same problem. I do not know how to solve :frowning:

I wish I had an idea. Many @kubawolanin had an idea.

In looking at the screenshot, try removing the ending comma after the last item.

"openhab.host": "http://192.168.xx.xxx",
"openhab.port": "8080"

And OpenHab is running right?

thanks , good eye :wink:
i’ve already found this comma, too - but didnt help

yes, openhab is running and i can see something in http://xxx.xxx.xxx.xxx:8080/rest

but still the same error

did you add http:// to the openhab.host ?

no , like in the code and picture above :wink:

Could you try to move the openhab.host and openhab.port parameters to User Config? There might be a problem for VSCode to access the settings file. Just an idea.

no success :frowning:

User-Config (Test #1):

{
    "window.zoomLevel": 1,
    "workbench.colorTheme": "Liqube Dark Code",
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.panel.location": "bottom",
    "openhab.host": "openhabianpi",
    "openhab.port": 8080
}

User-Config (Test #2):

{
    "window.zoomLevel": 1,
    "workbench.colorTheme": "Liqube Dark Code",
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.panel.location": "bottom",
    "openhab.host": "XX.XX.XX.XX",
    "openhab.port": 8080
}

Workspace-Config:

{
}
Error while connecting to openHAB REST API.

You can try forcing the rest API by setting that value to TRUE. Or to FALSE to disable and get rid of the warning.

Also, did you add “Http://” to the front of your 192.168.xx address?

This is my entire settings.

{
    "window.menuBarVisibility": "default",

    "openhab.host": "http://192.168.11.123",
    "openhab.port": "8080",
    "openhab.useRestApi": true,
    "openhab.sitemapPreviewUI": "classicui",
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "openhab.karafCommand": "ssh openhab@%openhabhost% -p 8101 -t 'log:tail'",
    "window.zoomLevel": 1,
    "python.disablePromptForFeatures": [
        "pylint"
    ]
}

thanks, i tried but no success :frowning:

RestAPI to = false
is not the thing i want :wink:

{
    "openhab.host": "http://xxx.xxx.xxx.xxx",
    "openhab.port": 8080,
    "openhab.useRestApi": true,
    "window.zoomLevel": 1,
    "workbench.colorTheme": "Liqube Dark Code",
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.panel.location": "bottom"    
}

I think port 8080 needs to be in quotes.

{
    "openhab.host": "http://xxx.xxx.xxx.xxx",
    "openhab.port": "8080",
    "openhab.useRestApi": true,
    "window.zoomLevel": 1,
    "workbench.colorTheme": "Liqube Dark Code",
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.panel.location": "bottom"    
}
Error while connecting to openHAB REST API.

00

Hmm, could you go to xxx.xxx.xxx.xxx:8080/rest/items and tell if it’s returning anything?
I see that you’ve loaded Things successfully so I assume there’s something wrong with the Items.

Also, what’s your distro number?

1 Like

my /rest/items result:

its the stable 2.1 version

openhabian - 7.05.170509
openHAB 2.1.0-1 (Release Build)

i got it working!

i deleted those items (bottom), saved and clicked on the OPENHAB ITEMS refresh-button ( in VSC ) - then i got the correct Items in VSC - strange…

(pasted the code for items back and saved again, still working )

i tried to reproduce the same procedure on my macbook.

  1. attempt = same Error with Port = 8080,
  2. attempt = i got it working too - i edited the Port to = “8080” and added useRestApi=true

( strange thing, on my macbook its working, WITH the items i deleted in the first try with my main computer. )

this is my working USER CONFIG now - nothing in Workspace-Config

{
    "openhab.host": "http://xxx.xxx.xxx.xxx",
    "openhab.port": "8080",
    "openhab.useRestApi": true,
    "window.zoomLevel": 1,
    "workbench.colorTheme": "Liqube Dark Code",
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.panel.location": "bottom"    
}

this is my working USER CONFIG on my macbook - nothing in Workspace-Config

{
    "openhab.host": "http://xxx.xxx.xxx.xxx",
    "openhab.port": "8080",
    "openhab.useRestApi": true
}

Thanks to all for the help - hopefully it stays functional :wink:

this are my items i deleted (saved) and pasted back in (saved) and its working now…
dont ask me why … - i just deleted the items i added lately


Switch Sonoff_2_Dual1 "Sonoff Dual1"   	<switch_status> 	(gLight,OG_Office,OG_Office_Light,Sonoff) 		[ "Lighting" ]
{ 	mqtt="	>[broker:cmnd/Sonoff_2/POWER1:command:ON:1],
			>[broker:cmnd/Sonoff_2/POWER1:command:OFF:0],
			<[broker:stat/Sonoff_2/POWER1:state:default]" 
}

Switch Sonoff_2_Dual2 "Sonoff Dual2"   	<switch_status> 	(gLight,OG_Office,OG_Office_Light,Sonoff) 		[ "Lighting" ]
{ 	mqtt="	>[broker:cmnd/Sonoff_2/POWER2:command:ON:1],
			>[broker:cmnd/Sonoff_2/POWER2:command:OFF:0],
			<[broker:stat/Sonoff_2/POWER2:state:default]" 
}


String Sonoff_2_uptime        	"Uptime [%s]"   							<clock>  (OG_Office,Sonoff)

String Sonoff_2_LAUFZEIT    	"Uptime RAW [%s]"   						<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/LAUFZEIT:state:default]"}
String Sonoff_2_LAUFZEIT2      	"Uptime [%s Stunde(n)]"   					<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.Laufzeit)]" }
String Sonoff_2_Update     		"Last Status Update [%s]"   				<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.Zeit)]" }
String Sonoff_2_VCC        		"Stromaufnahme (VCC) [%s Volt]" 			<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.VCC)]" }
String Sonoff_2_Status1       	"STATUS POWER 1 [%s]"   					<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.POWER1)]" }
String Sonoff_2_Status2       	"STATUS POWER 2 [%s]"   					<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.POWER2)]" }

String Sonoff_2_SUM1        	"SUM POWER 1 [%s]"   						<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:stat/Sonoff_2/ERGEBNIS:state:JSONPATH($.POWER1)]" }
String Sonoff_2_SUM2        	"SUM POWER 2 [%s]"   						<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:stat/Sonoff_2/ERGEBNIS:state:JSONPATH($.POWER2)]" }

String Sonoff_2_SSID       		"SSID [%s]"   								<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.WLAN.SSID)]" }
String Sonoff_2_RSSI        	"Signal (70 gut / 110 schlecht)  [%s dBm]"	<clock>  (OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.WLAN.RSSI)]" }

// funktionieren aber kein Bedarf
// String Sonoff_2_AP        		"Access Point [%s]"   				<clock>  (gLight,OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.WLAN.AP)]" }
// String Sonoff_2_APMAC        	"AP MAC [%s]"   					<clock>  (gLight,OG_Office,Sonoff) 			{ mqtt="<[broker:tele/Sonoff_2/STATUS:state:JSONPATH($.WLAN.APMac)]" }


works :slight_smile:

47

3 Likes

workstation - windows 10x64 (1709)
openHAB2 - Ubuntu 16.04.3 server
openHAB 2.2.0 Build #1120

Workspace Settings:

{
}

User Config:

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

or

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

if we add http://

{
    "openhab.host": "http://192.168.215.2",
    "openhab.port": "8080"
}

User Config:

{
}

Workspace Settings:

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

Снимок экрана (16)

Снимок экрана (17)

I have 4 servers openHAB, I would like to work with the settings of the workspace. Help me to solve this problem.
Thank you!

its broken again, same settings… :frowning: buggy thing…