Visual Studio Code - howto: connect to Rest API?

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…

I’ve just encountered it myself and will try to fix it in the following days.
Cheers

1 Like

Hmm I’ve added some additional error output to the message popover and I get the error regarding REST connection to the host param from User Settings, and not from Workspace settings.
There might be some issue with retrieving the configuration parameters from /.vscode/settings.json file stored in our openhab-config folders or higher.

I’m still not sure how to resolve this. Seting everything in user settings looks like a workaround (which works in my case) but it’s not an option for the multi-workspace environments…

I’ve submitted an issue: https://github.com/openhab/openhab-vscode/issues/67
Please provide as much details there as possible. Your OS, OH version, where is it stored etc.

EDIT: Please also take a look at the VSCode backlog of issues with respect to the workspace/user settings. There are quite a few of them and they might be related to our issues too.

Thanks

2 Likes

I am trying to get this working too and can’t. My problem is that openhab is only reachable over https.
https://192.168.2.xxx:8444/rest/things is working and returning some text. So I added

"openhab.host": "https://192.168.2.xxx",
"openhab.port": 8444

But it can’t connect. Any idea how to get this working?

PS openhab is running on a raspberry pi in the network and VS code on a windows pc if thats important (config files are shared via samba)

Small update: as advised to me here I installed another version of the addon and now I get a slightly different warning which says that I am using a self signed certificate. This is right as I am using the one generated by Openhab. There should be a settings to allow this :wink:

Hi All,

I also struggled with the Rest API connection. It was possible or get a connection to an openHAB server running on a Synology NAS, but I couldn’t connect to a local openHAB server running on Windows7. What helped me was to disable => reload => enable => reload in the openHAB VS code extension dialog:
grafik
After doing so, I suddenly could connect also to the local openHAB server running on Windodws.

Hope this helps someone.

5 Likes

Wow, it helped me as well. Great!

For me, just restarting VS Code made the REST connection work.
However, you must right-click on the conf folder and select “Open with Code”.

Hidden Folder: .vscode
File: settings.json

{
    "openhab.host": "192.168.1.xxx",
    "openhab.port": 8080
}

image
…assuming you have Samba setup:

1 Like

Error while connecting to openHAB REST API. Invalid protocol: 

Have the same problem!
I tested everything, but nothing worked.
Does somebody has any idea?

Can you provide some more date?

Which version of code?
Which version of the extension?
Did you open the conf folder direct from the network or did you add a drive to your explorer?

Maybe you could also list what “everything” means in detail.

The more information, the better the chance of finding the problem. :slightly_smiling_face:

1 Like

Sorry that I did not name any details… :confused:

VSC Version : 1.30.1
Extension Version: 0.4.1

I mount the conf folder as a drive to my explorer.


as configuration i used this:
(For USER CONFIG and 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”

But nothing worked, so I used all the configurations that were shown here, but didn’t work

Could you try to remove the http:// in openhab.host ?
I think there was a filter in the extension which recognized if there was an http set, but i am not sure.

1 Like

On windows 10, it did not work for me, but I’ve just installed deepin and configured everything there from new …

It worked

But i must thank you because i use openhab.host instant of http:// and it works.

1 Like

Just for the record…

I just started VSC, setup the right directory for my files and put the following into settings.json (accessible from Settings in VSC and search for openhab.

{

    "openhab.host": "192.168.xxx.x"

}