With the openHAB custom integration for Home Assistant you are able to use almost all openHAB items without MQTT.
Unfortunately it is a âWORK IN PROGRESSâ.
I tried the integration but unfortunately it does not support dimmer switches and the switch toggles do not update or stay synced the physical switches without the constant reloading of the integration.
Have made progress controlling devices on openHAB via HA UI input booleans and automations.
Now need to figure out how to keep the input booleans in sync with the physical switches and when they are controlled via openHAB.
It would be nice if one size fits all but it seldom does.
I mean I can use a trash bag as a raincoat but it sure doesnât look good.
It is likely both communities would grow more if there was greater interoperability between the two platforms.
In my experience this will be another automation. My solution looks like this (for a thermostat):
When changed in OH UI/sitemap
OH channel cmd topicâMQTT brokerâHA automation (change temp from payload)âthermostat
or Changed at thermostat
thermostatâHA publish changes via StatestreamâMQTT brokerâOH channel state topic/linked item
Also Changed in HA UI works (I donât control from HA though)
HA changes thermostat and publishes changes via StatestreamâMQTT brokerâOH channel state topic/linked itemâ(now goes back) OH channel cmd topicâMQTT brokerâHA automation (change temp from payload, which does nothing based on conditions in the automation since the thermostat temp already equals the payload).
Everything stays in sync, including state and cmd topics (you can watch in MQTT Explorer).
Thanks for the information.
FWIW I was able to get things working, at least for ON/OFF switches, using Home Assistant MQTT SWITCH.
I will look into your suggestions as I may be a solution for other types of devices that MQTT SWITCH does not handle.
It appears the solution will be to use MQTT Switch
and MQTT Light
on Home Assistant.
MQTT Light
is used for dimmers and allows additional parameters to be set other than just ON and OFF.
My question @rlkoshak how do I publish that additional information in openHAB to MQTT for the dimmers?
For example Home Assistant uses the following information for the MQTT Light
(dimmers):
# Example configuration.yaml entry
mqtt:
light:
- name: "Office light"
state_topic: "office/light/status"
command_topic: "office/light/switch"
brightness_state_topic: 'office/light/brightness'
brightness_command_topic: 'office/light/brightness/set'
qos: 0
payload_on: "ON"
payload_off: "OFF"
optimistic: false
While openHAB from within itâs UI offers MQTT State Topic
& MQTT Command Topic
and the openHAB CODE shows the following:
- id: bedroom_dimmer
channelTypeUID: mqtt:dimmer
label: Bedroom Dimmer
description: ""
configuration:
retained: true
postCommand: true
min: 0
qos: 1
max: 100
commandTopic: oh3/dimmer/bedroom_dimmer/cmd
stateTopic: oh3/dimmer/bedroom_dimmer/cmd
Can I add to/edit that information in the CODE section of the openHAB UI so that it includes the required dimmer information for MQTT submission for Home Assistant?
If so will it be wiped out when I ADD CHANNELS to the THING in the openHAB UI?
You will need to create a separate Channel for the Dimmer topics.
Note: using the same topic for command and state almost always leads to infinite loops, especially when coupled with postCommand enabled. When you send a command to the Item, it publishes a message to the commandTopic. It receives that message on the stateTopic, commands the Item which causes it to publish again ad infinitum. -
OKAY. Thanks for that.
The following is going to be such a NOOB question.
How / when does the information get published to the STATE topic(s)
When I did the following I do not believe anything was published to the STATE topic.
commandTopic: oh3/dimmer/bedroom_dimmer/cmd
stateTopic: oh3/dimmer/bedroom_dimmer/state
And you are correct about the infinite loop.
OH doesnât ever publish to the stateTopic. It only subscribes to the stateTopic. The stateTopic is how something else (HA) sends information to openHAB.
When OH receives a message on the stateTopic, it updates (or commands if postCommand is true) the Item with that new state.
When an OH Item receives a command, it will publish that to the commandTopic. The commandTopic is how OH sends information to something else (HA).
That makes sense BUT when I look at my configuration (see below) I get confused.
ON Home Assistant
light:
- unique_id: my_dimmer
name: "My Dimmer"
state_topic: "oh3/dimmer/my_dimmer/state"
command_topic: "oh3/dimmer/my_dimmer/cmd"
brightness_state_topic: "oh3/dimmer/my_dimmer/state_bright"
brightness_command_topic: "oh3/dimmer/my_dimmer/cmd_bright"
brightness_scale: 100
payload_on: "ON"
payload_off: "OFF"
on_command_type: last
qos: 1
retain: true
optimistic: false
ON openHAB
channels:
- id: my_dimmer
channelTypeUID: mqtt:dimmer
label: My Dimmer
description: ""
configuration:
retained: true
postCommand: true
min: 0
qos: 1
max: 100
commandTopic: oh3/dimmer/my_dimmer/cmd
stateTopic: oh3/dimmer/my_dimmer/state
- id: my_dimmer_level
channelTypeUID: mqtt:colorHSB
label: My Dimmer Level
description: ""
configuration:
commandTopic: oh3/dimmer/my_dimmer/cmd_bright
retained: true
postCommand: true
qos: 1
stateTopic: oh3/dimmer/my_dimmer/state_bright
Who âownsâ the topics? Presumably itâs HA. Whatâs a command and whatâs a state depends on who âownsâ the topics. If you want to command HA to do something, you use the cmd
topic. When HA has done something, it will post the new state to the state
topic.
Therefore OH needs to publish (i.e. commandTopic) to the cmd
topic and needs to subscribe (i.e. stateTopic) to the state
topic.
Mosquitto is running on openHAB.
The physical devices are/were originally controlled by/connect to openHAB.
I have the MQTT Integration on HA configure to the MQTT Broker / Mosquitto on openHAB.
So am I wrong to believe that openHAB owns the topics?
What matter is what dictates that oh3/dimmer/my_dimmer/cmd_bright
is the command topic? If itâs OH, then yes OH owns the topic. An in that case, OH needs to subscribe to the cmd
topic and publish to the state
topic. The cmd
topic is where messages coming from outside OH come and the state
topic is where OH publishes changes to the Item.
However, keep in mind that the binding will only publish commands so you might need a rule to translate changes to commands.
Where Mosquitto is running is irrelevant.
I have multiple 4 relays boards running Tasmota configured to connect to my local MQTT broker. My HomeAssistant instance uses Tasmota Integration to manage (ON/OFF) these relays.
On my OH3.3/3.4 instance have created 4 Channels shown in the attached Yaml file. Iâm able to manage these relays from both OH and HA.
UID: mqtt:topic:nacBroker:nacRC01
label: nacRC01 - Generic MQTT Thing
thingTypeUID: mqtt:topic
configuration:
payloadNotAvailable: offline
payloadAvailable: online
bridgeUID: mqtt:broker:nacBroker
location: System
channels:
- id: Relay1
channelTypeUID: mqtt:switch
label: Relay1
description: ""
configuration:
commandTopic: cmnd/nacRC01/Relay1/POWER1
stateTopic: stat/nacRC01/POWER1
off: OFF
on: ON
- id: Relay2
channelTypeUID: mqtt:switch
label: Relay2
description: ""
configuration:
commandTopic: cmnd/nacRC01/Relay2/POWER2
stateTopic: stat/nacRC01/POWER2
off: OFF
on: ON
- id: Relay3
channelTypeUID: mqtt:switch
label: Relay3
description: ""
configuration:
commandTopic: cmnd/nacRC01/Relay3/POWER3
stateTopic: stat/nacRC01/POWER3
off: OFF
on: ON
- id: Relay4
channelTypeUID: mqtt:switch
label: Relay4
description: ""
configuration:
commandTopic: cmnd/nacRC01/Relay4/POWER4
stateTopic: stat/nacRC01/POWER4
off: OFF
on: ON
Regarding the Dimmer Channel - id: my_dimmer
commandTopic is there a way publish ON if the dimmer value is greater than zero and OFF if the dimmer value is zero rather than a number?
HA is looking for ON / OFF as well as the brightness level.
Anything is possible through rules.
At the moment OH and HA will only update mosquitto and fail to update each others UI.
If I swap out state and state_bright with cmd and cmd_bright OH will update the UI of HA but HA will not update the UI of OH.
Furthermore using MQTT Explorer I do not see state or state_bright.
In MQTT Explorer I have the following:
oh3
dimmer
my_dimmer
cmd
cmd_bright
What am I overlooking?
It seems that this is an issue with state and subscribing.
In HA I have the following:
light:
- unique_id: my_dimmer
name: "My Dimmer"
state_topic: "oh3/dimmer/my_dimmer/state"
command_topic: "oh3/dimmer/my_dimmer/cmd"
brightness_state_topic: "oh3/dimmer/my_dimmer/state_bright"
brightness_command_topic: "oh3/dimmer/my_dimmer/cmd_bright"
brightness_scale: 100
payload_on: "ON"
payload_off: "OFF"
on_command_type: last
qos: 1
retain: true
optimistic: false
In OH I have the following:
channels:
- id: my_dimmer
channelTypeUID: mqtt:dimmer
label: My Dimmer
description: ""
configuration:
retained: true
postCommand: false
min: 0
qos: 1
max: 100
commandTopic: oh3/dimmer/my_dimmer/cmd_bright
stateTopic: oh3/dimmer/my_dimmer/state_bright
*** UPDATE ***
I created the following using MQTT Explorer:
oh3/dimmer/my_dimmer/state_bright
oh3/dimmer/my_dimmer/state
Set the values to 35 and ON.
Viewed the device in OH and HA they had the correct values but changing the dimmer levels in their UI(s) did not change the values of state
or state_bright
within mosquitto or each others UI.
Thanks. Created rule that published ON / OFF.
I am hung-up on the STATE_TOPIC.
The closer I think I get to figuring this out the further away I seem to be to solving this.
When I started this I set up an MQTT Thing should I have set up an HomeAssistant MQTT Component instead?
I am confused on how OH subscribe to topics is it the MQTT Thing that subscribes to the topic and not the channels?
If I use MQTT Thing does that mean I need to create a MQTT Thing for each switch?
If I use HomeAssistant MQTT Component will that handle all of my switches?
Step back.
Get out a piece of paper.
Chart out each and every data flow. That becomes your recipie for how to configure everything. Once you have all the messages and data flows mapped out itâs just a matter of configuring HA and OH to publish/subscribe each data flow. You can address them one by one until you have them all.