MisterHouse <-> OpenHab2 Communication

Moving from Misterhouse has been interesting. Misterhouse is GREAT for X10 control, but I have less impressed with its documentation and support for a changing world. There are simply not enough developers for it. Enter OpenHab. Unfortunately, there little to no X10 support for OH. Thus I had a thought. Use MisterHouse for Rx/Tx of X10 control and send the information over to OH!

I tried geting the exec binding to work sending from OH to MH via “mhsend” with limited success. I could not get the command out from the items file. It would only work for me using a rule with:

executeCommandLine("/etc/openhab2/mhsend -run set \$Living_Room_Lamps ON")

This turned out, for me, to be VERY slow to respond.

I found using the http binding works great from the items file.

{http=">[ON:POST:http://localhost:8080/SET;no_response?$Living_Room_Lamps=on] >[OFF:POST:http://localhost:8080/SET;no_response?$Living_Room_Lamps=off]"}

OpenHab uses the “http” binding to send info to MH
MH uses tcp to send an ASCII string to OH (using the “tcp” binding)

make tcp.cfg in OH services folder which contains one line:


This catches all data from MH

String MH_tcp_rcv "MHTCP [%s]"		{tcp="<[*:'REGEX((.*))']"}

This is the OH item to be controlled

Switch	Light_GF_Living_Room_Lamps	"Living Room Lamps"	<light>	(GF_Living, Lights)	{http=">[ON:POST:http://localhost:8080/SET;no_response?$Living_Room_Lamps=on] >[OFF:POST:http://localhost:8080/SET;no_response?$Living_Room_Lamps=off]"}

After saving the items file you should see this in the openhab.log

2016-12-13 10:32:58.918 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'my.items'
2016-12-13 10:33:01.066 [INFO ] [b.core.service.AbstractActiveService] - TCP Refresh Service has been shut down
2016-12-13 10:33:01.215 [INFO ] [b.core.service.AbstractActiveService] - TCP Refresh Service has been started
2016-12-13 10:33:01.224 [WARN ] [ing.tcp.AbstractSocketChannelBinding] - When using address masks we will not verify if we are already listening to similar incoming connections
2016-12-13 10:33:01.280 [INFO ] [ing.tcp.AbstractSocketChannelBinding] - We will accept data coming from the remote end*

now, MH needs to send the light status in a .pl file:

$OpenHab = new Socket_Item( undef, undef, '' );
if(state_changed $Entrance_Lights)
	if(state_now $Living_Room_Lampseq 'on'){
		set $OpenHab "Living_Room_LampsON";}
	if(state_now $Living_Room_Lamps eq 'off'){
		set $OpenHab "Living_Room_LampsOFF";}
	stop $OpenHab;  

Now, we need a rule to parse the string received by OH:

rule "Misterhouse TCP Parsing"
     Item MH_tcp_rcv received update
	logInfo("x10.rules", "Data received from MisterHouse.  Setting " +  MH_tcp_rcv.state.toString)
	if(MH_tcp_rcv.state.toString == "Living_Room_Lamps ON"){
	        postUpdate(Light_GF_Living_Room_Lamps, "ON") }
	if(MH_tcp_rcv.state.toString == "Living_Room_Lamps OFF"){
		postUpdate(Light_GF_Living_Room_Lamps, "OFF") }

The unfortunate thing is that I need to parse each item in MH separately in the rule. If I could get the TCP binding working from the items file, it would be great!