Plugwise-2-py with reconnecting websockets

One of the problems with the Plugwise-2-py web application ( was that when a computer running a browser with the web client fell asleep, that in the next session the page had to be manually reloaded to get the websocket stream of power readings started again.

This seemed easy to fix, with a timeout call in the javascript or something like that. But before coding this I thought of gooling it. And of course it did already exist.
It did not only exist, but also got it working within 30 minutes. Reliably!

Very minor changes to the .html and .js file:

  Loading ReconnectingWebSocket
  <script src="/components/reconnecting-websocket/reconnecting-websocket.js"></script> 

to include the work of joewalnes, and change the WebSocket constructor in the javascript:

	var ws;
	if (window.location.protocol == 'https:') {
		//ws = new WebSocket("wss://"+host+"/");
		ws = new ReconnectingWebSocket("wss://"+host+"/");
	} else {
		//ws = new WebSocket("ws://"+host+"/");
		ws = new ReconnectingWebSocket("ws://"+host+"/");

The if/else section is all there is to make the websockets run over a secure SSL or unencrypted HTTP connection.

One thought to “Plugwise-2-py with reconnecting websockets”

  1. I have problems with getting the schedules working,you told on domoticaforum to mail you so here i am

Leave a Reply

Your email address will not be published. Required fields are marked *