Hi. I run OH as main automation system and HA as secondary automation system since it has additional bindings/integrations not available in OH. I tried to integrate both via MQTT since this is supported by OH and the relevant binding was developed - see relevant page.
I have not found any end2end instruction, so this integration was not straight forward for me as I actually also beginner in MQTT protocol. So I just want to share my experience as I finally got it working with “some warnings”. I did not get HomeAssistant MQTT binding to work, but Generic MQTT Thing worked (almost) fine.
Hope this info will be useful for someone.
HA. Install and then configure MQTT Mosqitto broker. Documentation is here.
Configuraiton can be done manually by editing configuration.yaml or by using HA user interface (Configuration >Devices and Services > Mosquitto broker > (re-)configure
Set also username and password for security.
Install MQTT Explorer utility. A very useful tool for monitoring of MQTT topic data. It can also be used to verify that HA broker is actually running:
HA. Create necessary MQTT devices. As an example we will create a virtual number device by adding following number device in configuration.yaml
number: - platform: mqtt command_topic: "homeassistant/number/mynumber1/cmd" name: "Bedroom Temperature" state_topic: "homeassistant/number/mynumber1/state" unique_id: number111111111111111111 min: 1 step: 1 max: 100
OH. In OpenHab create an MQTT Broker thing and connect it to HA Mosquitto broker. You will need to fill the IP adress of your HA instance, port 1883 (standard MQTT port), username, password. State of the new thing must be “Online”.
OH. Now create the new Generic MQTT Thing and put the MQTT Broker as bridge.
Create new number channel and fill relevant configuration.
Once created, create also the relevant number item for the newly created channel. At the end you will have:
That’s it. It worked for me. The only thing still not working - status of Generic thing. The availabilty topic should be homeassistant/status and payload is online, offline - but for some reason state is constantly offline in OH.
Verification of data flow HA > OH
HA. Publish the state change message to the number device topic “homeassistant/number/mynumber1/state” that we previously assigned to MQTT number device in HA.
This can be done f.ex. via Developer Tools in HA:
Check that the value really reached the MQTT broker by looking into MQTT Explorer:
OH item will now also be updated:
Verification of data flow OH> HA
- Write a short OH script calling MQTT broker:
val mqttActions = getActions("mqtt","mqtt:broker:1b72424470"); mqttActions.publishMQTT("homeassistant/number/mynumber1/state","44", true);
Do not forget to put actual ID of your OH Broker thing of course. Execute the script.
Check that MQTT_Number1 item is 44 in OH:
it reached the HA broker:
Check HA number got the update: