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.
Configuration steps:
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
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”.
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:
Create rule that will synchronize values of cmd and state once cmd topic is updated for MQTT Select item. This is needed since OH String item only listens the state topic while changing selection in HA only updates cmd topic.
Append this code into automations.yaml:
- id: '1641586360163'
alias: Sync MQTT Arm State Cmd to State
description: ''
trigger:
- platform: mqtt
topic: homeassistant/select/arm_state/cmd
condition: []
action:
- service: mqtt.publish
data:
topic: homeassistant/select/arm_state/state
payload_template: "{{ trigger.payload }}"
mode: single
WORK DEMO 1: Update HA Item in UI will update OH Item
>>
WORK DEMO 2: Update OH Item in iOS app will update HA Item
Hey @Bender1 , thnx, was already helpfull, i’m also new to Openhab, and was struggling with the state too , for a simple light in my case … sending payload to turn on/off is already working,
can you have a look for me? seems you were struggling too with state?
But try that custom component, its the other way around, and its HA thats creating the MQTT item correctly
i use HA for main purposes and openhab for limited stuff
I am going in circles with the STATE of the STATE. I do not know where it comes from or what should be committing it to MQTT STATE TOPICS. Was told that STATE topics were the responsibility of the devices and what about SUBSCRIBING to topics is that done system wide or is that on a device/channel bases?
thats indeed verry strange , but sorry, i’m beginner user in openhab, so not have a lot of experience here, but i believe i had it working using that custom component, at the moment i dont use it anymore, i just tested it for later when i have some more time
but i still have copy/pasted my config that i use for later
in HA i just have lights/swiches that i expose to mqtt with that discoverystream
and this was my config in openhab that was working in both directions
OH is the main system, Mosquito is running on the same device as OH. I have docker with HA that I only use to send some strings so that HA publishes that on my Google Home speakers (I have struggled some time with the Google TTS loosing authorisations and this setup works for me for the last 2 years).
It still works, but there is something wrong with the OH decoding the LWT from HA.
In the broker the status is “online”, but OH returns Offline
Is the online/offline message retained? Those MQTT Explorer screen shots seems to indicate that it is not. Unless OH happened to be connected to the LWT topic at the time that the online message was sent from HA, OH doesn’t know whether the end device is online or not so it defaults to offline.