How to run OpenHAB behind an internet proxy?

  • Platform information:

    • Hardware: virtual Machine on ESX Server
    • OS: Suse Linux Enterprise Server 15
    • Java Runtime Environment: zulu8.33.0.1-jdk8.0.192
    • openHAB version: 2.4.0
  • Issue of the topic: OpenHAB extensions (OpenHABCloud, Telegram) can’t connect to their servers

  • Please post configurations:

    • Services configuration related to the issue
      /etc/default/openhab2 has EXTRA_JAVA_OPTIONS set to this:
      EXTRA_JAVA_OPTS=" -Dhttp.proxyHost=[my proxy IP] -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts='localhost||.local'"
  • If logs where generated please post these here using code fences:

 # systemctl status openhab2.service
● openhab2.service - openHAB 2 - empowering the smart home
   Loaded: loaded (/usr/lib/systemd/system/openhab2.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-12-10 09:19:47 CET; 26s ago
  Process: 15107 ExecStop=/usr/share/openhab2/runtime/bin/karaf stop (code=exited, status=0/SUCCESS)
 Main PID: 15361 (java)
    Tasks: 165 (limit: 4915)
   Memory: 420.3M
      CPU: 32.714s
   CGroup: /system.slice/openhab2.service
           └─15361 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.logdir=/var/log/openhab2 -Djava.library.path=/var/lib/openhab2/tmp/lib -Djetty.http.compliance=RFC2616 -Dorg.ops4j.pax.web.listening.addresses= -Dorg.osgi.service.http.port=8080 -Djava.awt.headless=true -XX:+UseG1GC -Dhttp.proxyHost=[my proxy IP] -Dhttp.proxyPort=8080 -Dhttp.nonProxyHosts='localhost||.local' -Djava.endorsed.dirs=/usr/lib/jvm/zulu-8/jre/lib/endorsed:/usr/lib/jvm/zulu-8/lib/endorsed:/usr/share/openhab2/runtime/lib/endorsed -Djava.ext.dirs=/usr/lib/jvm/zulu-8/jre/lib/ext:/usr/lib/jvm/zulu-8/lib/ext:/usr/share/openhab2/runtime/lib/ext -Dkaraf.instances=/var/lib/openhab2/tmp/instances -Dkaraf.home=/usr/share/openhab2/runtime -Dkaraf.base=/var/lib/openhab2 -Dkaraf.etc=/var/lib/openhab2/etc -Dkaraf.logs=/var/log/openhab2 -Dkaraf.restart.jvm.supported=true -Djava.util.logging.config.file=/var/lib/openhab2/etc/ -Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true -classpath /usr/share/openhab2/runtime/lib/boot/activation-1.1.1.jar:/usr/share/openhab2/runtime/lib/boot/jaxb-api-2.3.0.jar:/usr/share/openhab2/runtime/lib/boot/jaxb-core-2.2.11.jar:/usr/share/openhab2/runtime/lib/boot/jaxb-impl-2.2.11.jar:/usr/share/openhab2/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.2.1.jar:/usr/share/openhab2/runtime/lib/boot/org.apache.karaf.jaas.boot-4.2.1.jar:/usr/share/openhab2/runtime/lib/boot/org.apache.karaf.main-4.2.1.jar:/usr/share/openhab2/runtime/lib/boot/org.osgi.core-6.0.0.jar org.apache.karaf.main.Main

Dec 10 09:19:47 systemd[1]: Started openHAB 2 - empowering the smart home.

OpenHAB Log shows this:

==> /log/openhab2/openhab.log <==
2019-12-10 09:21:09.324 [INFO ] [e.smarthome.model.script.debug.rules] - Sending Telegram message...
2019-12-10 09:29:52.416 [WARN ] [ab.action.telegram.internal.Telegram] - Transport error: {} Connection timed out (Connection timed out)
	at Method) ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at ~[?:?]
	at<init>( ~[?:?]
	at ~[?:?]
	at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket( ~[?:?]
	at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket( ~[?:?]
	at ~[?:?]
	at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry( ~[?:?]
	at org.apache.commons.httpclient.HttpMethodDirector.executeMethod( ~[?:?]
	at org.apache.commons.httpclient.HttpClient.executeMethod( ~[?:?]
	at org.apache.commons.httpclient.HttpClient.executeMethod( ~[?:?]
	at org.openhab.action.telegram.internal.Telegram.sendTelegram( ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:?]
	at java.lang.reflect.Method.invoke( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature( ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate( ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate( ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.doEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate( ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate( ~[?:?]
	at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute( ~[?:?]
	at org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl.lambda$2( ~[?:?]
	at java.util.concurrent.Executors$ [?:?]
	at [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201( [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:?]
	at java.util.concurrent.ThreadPoolExecutor$ [?:?]
	at [?:?]

What do I do wrong?

OH is not meant to be run behind a (non-transparent) Inet proxy.
Dunno what -Dhttp.proxyPort=8080 is supposed to do. At least it’s no intentional/supported function.
And even if it did work it applies to HTTP. You error is from a Telegram outbound connect which I think is not HTTP.
So that construction of your won’t work in general. Get a transparent proxy (NAT, that is) to work like that in your Inet router.

I have set up a reverse proxy as detailed in the official documentation. You may wist to read the whole security document.

OP’s problem is outbound connections.

Oh okay, didn’t know that. Thought it is HTTP(S) as stacktrace says that org.apache.commons.httpclient.HttpClient and further is in there.

Buy the way, do you know how openhabcloud service connects? Will I have the same problem there? This currently doesn’t work too.

That’s the standard way of Java to configure a proxy:

That’s what we had before and what IT department decided to not offer anymore :frowning:

Thanks, that’s what I already did (for adding SSL and planned future authentication), that’s not the problem. I know that document, I even contributed to details of it, see [SOLVED] [BUG] OpenHAB with nginx redirects HTTPS to HTTP

You’re running OH in a corporate environment ?? And your IT doesn’t want to support you (if so, they would continue providing NAT, wouldn’t they) ?
That sure OH is not built for (means: even if you did get this here to work you’ll likely encounter more issues, many of which you cannot work around using HTTP only).

Most likely. I don’t know what protocol it uses, but the Cloud Connector add-on initiates an outbound connection to If you have a proxy in the way it likely will block that connection.

Ultimately, this is a non-standard setup and one few if any on this forum will have encountered. Many of us have a proxy on our home networks (e.g. pihole) but it’s set up to be transparent. You will need to do the research and experimentation for how to make this work using other resources than this forum I suspect. If you do figure it out a tutorial might be useful to some though.

So regarding the Telegram API I dug into the sources:


botLibClient = new OkHttpClient.Builder().connectTimeout(75, TimeUnit.SECONDS).readTimeout(75, TimeUnit.SECONDS)
TelegramBot localBot = bot = new TelegramBot.Builder(botToken).okHttpClient(botLibClient).build();

So TelegramBot is instantiated with a reference to okHttpClient(). It is based on com.pengrad.telegrambot.TelegramBot

The sources there say:

public static final class Builder {

    static final String API_URL = "";


    public Builder(String botToken) {
        this.botToken = botToken;
        api = new TelegramBotClient(client(null), gson(), apiUrl(API_URL, botToken));

So everything here looks like HTTP/HTTPS.

Even Telegram states:

So I’m quite sure that communication to Telegram servers is done with HTTPS - and should also be possible through HTTPS proxy. But how to do it?

Okay, so I now have a solution - but it’s not an answer to my question here:
I finally got port 443 opened in firewall for connecting to and so both work again for my case.

And yeah as mentioned in other topics, I will have to apt-get install openhab2-addons for having the addons work :slight_smile: