Testing OpenHAB with Domoticz via MQTT

(Anders) #1

I have a full working Domoticz solution with RFLink with light switches and temperature sensors, Life 360 and Gigaset Elements running on a RPi.

I would like to test OpenHAB to see if it’s something for me and wondering if I can sync Domoticz with OpenHAB via MQTT to see what it looks like and how it works. Want to try Google Home as myopenhab have support for it.

If it’s possible, how do I setup that? Maybe there is people here who have already done this?

(Rich Koshak) #2

Should be possible. Start here:

(Anders) #3

Okey, it’s up and running. Let’s see if it’s possible to make it even better.

  • Had Domoticz running on RPi at port 8080 (and 443)
  1. Installed Mosquitto and configured Domoticz to connect to it
  2. Installed zulu java for embedded as it wasn’t installed in the Domoticz image
  3. Installed OpenHAB and change port to 8081. After installation I had to wait 10-15 minutes before it was up and running and listening at port.
  4. Installed following OpenHAB addons:
  • MQTT binding
  • MQTT Actions
  • JSONPath, Map, Javascript and RegEx Transformation
  • openHAB Cloud Connector
  1. Configure MQTT binding
  2. Configured rules, items and javascript as below
  3. Configured openHAB Cloud Connector
  4. Now, I can control my domoticz devices with my Google Home and ask for temperature. If I want I can use the openHAB webinterface as they sync with each other. I can do stuff via myopenHAB if I want to. And everything without open any ports in my firewall.
    I will only add domoticz items in openHAB that I think is secure to let Google Home to have control over.

So this is how I solved it and it works for me. I would prefer to not enter idx number two times on same row in items-file, but I couldn’t solve it any other way.


Switch idx123 "Outdoorlamp" (gLight) [ "Lighting" ] {mqtt="<[mqttBroker:domoticz/out:state:JS(get_state.js):(?s).*idx\".?.?.?123,.*]"}
Number Outdoor_Temperature "Temperature [%.1f]" <temperature> ["CurrentTemperature"] {mqtt="<[mqttBroker:domoticz/out:state:JSONPATH($.svalue1):(?s).*idx\".?.?.?124,.*]"}

123 and 124 is device idx in Domoticz. mqttBroker is what I configured the mqtt-connection to be called in mqtt binding.


rule "Send MQTT message on Light command"
	Member of gLight received command
	var idxStartPos = triggeringItem.name.indexOf("idx") + 3
	var idxStopPos = triggeringItem.name.length()
	var  myString = ""

	if (triggeringItem.state.toString() == "ON" || triggeringItem.state.toString() == "OFF")
		var cmd = triggeringItem.state.toString().toLowerCase.toFirstUpper()
		// {"command": "switchlight", "idx": 2450, "switchcmd": "On" }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"' + cmd + '\"}'
		// {"command": "switchlight", "idx": 2450, "switchcmd": "Set Level", "level": 100 }
		myString = '{\"command\": \"switchlight\", \"idx\": ' + triggeringItem.name.substring(idxStartPos,idxStopPos) + ', \"switchcmd\": \"Set Level\", \"level\": ' + triggeringItem.state.toString() + '}'

	publish("mqttBroker", "domoticz/in", myString)


    var parsed = JSON.parse(i);
    if (parsed.nvalue == 0)
        return "OFF"
    else if (parsed.nvalue == 1)
        return "ON"
    else if (parsed.nvalue == 2)
        return parsed.svalue1