Webview url for outside home

Can someone possibly share the correct url address for viewing the weather html layout remotely when outside your home in a sitemap?

This works locally in the home:

Webview url="http://192.168.xx.xx:8080/weather?locationId=home&layout=example&iconset=colorful" height=10

And I tried changing to https://myopenhab.org/weather… but that did not seem to work.

Do I need to actually use a DNS and open up port 8080? But that would lead to some security concerns and open access to pretty much anyone.

Never open port 8080 directly to the Internet !!!

You can open whatever port you want at any time, at your own peril.

Getting back to your question. Myopenhab does not provide a possibility to proxy web pages. It only proxies images.

So if you are serving a web page that you want to view when visiting myopenhab you need to refer to your public IP in the URL instead.

However as noted by the gentleman before me if you use port 8080 where openhab is already being served then you effectively open your openhab up to everyone on the internet, which may not be what you actually want.

Instead you should probably serve the weather page on another server like nginx or something on another port and then possibly open only that port to the internet.

1 Like

Yes you can, but it makes no sense!

It will not be long before the forum gets flooded with “Help my Openhab was hacked”!

The point I was trying to make was that your first reply to the question was as unhelpful as this last post from you.

That was a good tip there about using an image. So what I ended up doing was searching a way to convert html to png and since I use Ubuntu came across http://phantomjs.org/ which has a good, easy way to convert the weather to an image. This program phantomjs appears it may also be useful for many things including making your own custom colorwheel, but that’s probably beyond my skill level a this point.

So it it helps anyone else, the basic steps I followed for Ubuntu Server 16 are as follows.

  1. I used these instructions to Install Phantomjs
    https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04

  2. Created a basic script and placed it in /etc/openhab2/scripts called weather.js

var page = require('webpage').create();
page.open('http://192.168.11.123:8080/weather?locationId=home&layout=example&iconset=colorful', function() {
page.evaluate(function() {
  document.body.bgColor = 'white';
});
page.render('/etc/openhab2/html/images/weather.png');
  phantom.exit();
});

You can see the above will place the image in your ‘html/images’ directory. And you can run the script manually like such:

phantomjs /etc/openhab2/scripts/weather.js
  1. With use of the Exec binding installed and the ExecuteCommand line in a rule, I run the script each time my Weather Min and Max Temps are updated. Note, I am using the WeatherUndground for weather that is set to update temps every 5 minutes, but also have the weather 1.x binding installed strictly for making the html image.
rule "Set daily max and min temperature"
when
	Item Wunderground_Temperature changed or
		Time cron "0 0 0 * * ?" or
	System started
then
    val max = (Wunderground_Temperature.maximumSince(now.withTimeAtStartOfDay, "rrd4j").state as DecimalType).doubleValue
	  val min = (Wunderground_Temperature.minimumSince(now.withTimeAtStartOfDay, "rrd4j").state as DecimalType).doubleValue

  if( max != null && min != null) {
    Wunderground_Temperature_Max.postUpdate(max)  
	  Wunderground_Temperature_Min.postUpdate(min)
  }
  //Create Image of the Weather for SiteMap
  var cmd = 'phantomjs@@/etc/openhab2/scripts/weather.js'
	executeCommandLine(cmd) 
end
  1. And then finally in my sitemap I reference the image and can see it both locally and when outside the home
Image url="http://192.168.11.123:8080/static/images/weather.png"

Could you repost this as a separate topic in the Tutorials and Examples section? A lot of people recently have posted about being frustrated getting the old OH 1.x Weather Binding Webview working, particularly in their phone Apps.

This is a good approach to accomplishing that.

And to provide a little more useful information about opening the port.

It is very risky to open an unauthenticated server on the internet. I highly recommend against doing so.

It is very slightly less risky to expose an unauthenticated server on the internet over HTTPS (i.e. port 8443). I highly recommend against doing this.

It is slightly less risky to set up a reverse proxy (see the Security section of the Installation Docs) and expose your OH to the Internet using username and password authentication. This approach can be made relatively safe, but unless you really know what you are doing I highly recommend against doing this. But if you must, this is the minimum one should do.

Honestly, access to Webviews simply does not rise to become an important enough feature to risk opening any of my openHAB ports, even through a reverse proxy, to the Internet.

This is why I usually recommend using myopenhab.org or setting up a VPN.

I want to update this thread because the original solution for creating images does not work on a Raspberry Pi cause of different architecture. After hours of research (I am new to the Raspi-World), I finally found a working phantomjs for ARM.

I installed phantomjs like this on my Pi 3b+:

Download.deb file from here:

https://github.com/fg2it/phantomjs-on-raspberry/blob/master/rpi-2-3/wheezy-jessie/v2.1.1/phantomjs_2.1.1_armhf.deb

Copy it to your Pi on whatever location (or use wget).

From there, use

sudo apt install ./phantomjs_2.1.1_armhf.deb

Verify it is working:

phantomjs --version

It should output

2.1.1

Then continue with the scripts in step 2 from original post from @ptmuldoon .

I was too lazy to set up a rule so I just did a cronjob every ten minutes updating the image:

*/10 * * * *       openhabian   phantomjs /etc/openhab2/scripts/weather.js

Kudos to @ptmuldoon for bringing the solution converting the HTML to an image, a superb idea to overcome the limitations of Webview in the app when using remote URL!