Crossover from OH to HA and MQTT item config

Hi All,
I’m changing over my home from OpenHAB to HA and most things are coming across without issue.
I have the following light that uses the below OH config:

Switch Wall_Lights "Wall Lights"	<light> 	(gHouse,gLight) 
    {mqtt=">[mqtt_server:/ESP-5-S-SW/gpio/12:command:ON:1],
    >[mqtt_server:/ESP-5-S-SW/gpio/12:command:OFF:0]",alexa="Switchable",ga="Light" }

How do I create this in the configuration.yaml? I have what I beleive to be the beginning but lost after that

mqtt:
  light:
    - name: Family Room Wall Light
      state_topic: ESP-5-S-SW/gpio/12

I also have the below envirmental sensor. How do I bring this into HA?

Number Garage_Temperature	"Garage Temperature: [%.1f]"	    <temperature> 	(Office, gOffice_Temp_Chart,gChart)	{mqtt="<[mqtt_server:NWE/Satellite_Sensor/Temperature:state:default]"}
Number Garage_Humidity  	"Garage Humidity: [%.0f %%]"	    <temperature> 	(Office,gChart)				{mqtt="<[mqtt_server:NWE/Satellite_Sensor/Humidity:state:default]"}
Number Garage_Barometric  	"Garage Barometric: [%.0f]"	    <temperature> 	(Office,gChart)				{mqtt="<[mqtt_server:NWE/Satellite_Sensor/Barometric:state:default]"}

Thanks,
Neil.

Could you pinpoint exactly what is unclear in the documentation?

I have already looked at this document and I don’t understand how this works.
I have quite a few of these style of devices and just need a hand with the first two types.

Well, there are plenty of examples.
Basically:

  • state_topic: is the topic from which the current state of the light will be read. Must be “ON” or “OFF” by default. Use payload_on/ payload_off to change the default
  • command_topic: is the topic where state changes are published by HA. Same goes as above regarding the actual values.

Once again, if you are not more precise regarding what you don’t understand, we cannot help you precisely.

Suggest you install MQTT Explorer and see what the topics involved contain. Once you know that, it should be easy to get the entities working.

It may be obvious from the OH config to someone who understands that.

The following message turns ON the light
/ESP-5-S-SW/gpio/12=1

The following message turns OFF the light
/ESP-5-S-SW/gpio/12=0

How is this information placed into the yaml?

If the device can only be turned on/off and doesn’t allow for adjustment of brightness, you may wish to consider modeling it as an MQTT Switch instead of an MQTT Light entity. However, you’re not obligated to do that and you can model it as light if that’s your preference.

According to your openHAB example, this is the topic used to publish a command to the device:

/ESP-5-S-SW/gpio/12

In Home Assistant, that’s called the command_topic.

What is the topic that your device uses to report it’s current state? In Home Assistant, this topic is called the state_topic.

mqtt:
  - switch:
      unique_id: abc123xyz456
      name: "Family Room Wall Light"
      state_topic: <enter the topic used by the device to report its current state>
      command_topic: "/ESP-5-S-SW/gpio/12"
      payload_on: "1"
      payload_off: "0"
      state_on: "1"
      state_off: "0"

If the device doesn’t report its current state then it operates in what Home Assistant calls “optimistic mode” (a command sent to the device is assumed to be received and executed because the device does not report its current state).

mqtt:
  - switch:
      unique_id: abc123xyz456
      name: "Family Room Wall Light"
      command_topic: "/ESP-5-S-SW/gpio/12"
      payload_on: "1"
      payload_off: "0"
      optimistic: true
1 Like
command_topic: "/ESP-5-S-SW/gpio/12"
payload_on: "1"
payload_off: "0"
1 Like

To convert openHAB’s Number entities to Home Assistant’s Sensor entities, refer to the documentation for MQTT Sensor.

mqtt:
  sensor:
    - name: "Garage Temperature"
      state_topic: "NWE/Satellite_Sensor/Temperature"
      device_class: "temperature"
      unit_of_measurement: "°C"
      value_template: "{{ value | round(1) }}"
      unique_id: "nwe_garage_temp"

I assume that this:

(Office, gOffice_Temp_Chart,gChart)	

makes the Number entity a member of three groups. An MQTT Sensor’s configuration doesn’t support assignment to a group.

You will have to perform that step separately, after the sensor has been created.

1 Like

Hi Neil,
I ported my system across from openHAB to HASS some years ago after several months of parallel running with one MQTT broker. Both openHAB and HASS connected to the same instance of Mosquitto allowing automations and other config to be ported across one by one.

Similar to openHAB 2.0, MQTT devices can be defined manually or using HASS auto-discovery. The latter works is much easier for devices that support it (e.g. older Tasmota) as you configure the device once, not the automation platform.

The MQTT messages you posted suggest at least these devices are custom ESP-based modules, for which manual MQTT config might be easier in the short-term.

For an overview, here’s a walkthrough of HASS Mosquitto broker Add-In, MQTT integration, Tasmota Integration. If you wanted to add autodiscovery to a custom device, there’s some tips and examples in this thread.

The hardest part of moving across from openHAB is shifting from a “Java-like” mindset (tabs) to “Python-like” paradigm (spaces, JSON/YAML). Consistent YAML indentation is painful at first, but prototype using the visual automation editor first THEN tweak. Most of my automations ended up a fraction of the size of openHAB once I’d masterd the dev tools to live-protoype Jinja2 templating functions (e.g. {{ object }}).

In general, HASS documentation is function with few examples BUT search for terms in this forum to find (usually) working code.

If this helps, :heart: this post!

1 Like

Thanks everyone.
These Switch/Light and Temperature examples got me going and I now have working lights, temperatures and humidity readings.

Not sure about the “-” before name: though. Do I need this at the beginning?

Thanks,
Neil.

That’s a YAML list marker. If you have more than one switch / sensor / whatever under the main heading, you need it. So:

mqtt:
  sensor:
    name: one and only sensor
    [other parameters]

is fine, but you need:

mqtt:
  sensor:
    - name: sensor one
      [other parameters]
    - name: sensor two
      [other parameters]

for more than one. Better to put it in even if you only have one, for consistency and ease of later expansion.

Glad to hear they helped you get it working.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.