MQTT Things Textual Configs

  • Platform information:
    • Hardware: Intel Core i3-6100T/16GB/256GB SSD
    • OS: Ubuntu 22.04.3 LTS
    • Java Runtime Environment: OpenJDK Runtime Environment Zulu17.46+19-CA (build 17.0.9+8-LTS)
    • openHAB version: openHAB 4.1.1
  • Issue of the topic: MQTT Configuration

First, thanks so much to the contributors of this project. It’s an incredible project and I know that folks have dedicated a great deal of time making it so wonderful. Thank you.

I am using zigbee2mqtt and zwavejsui. I have them setup with zigbee and zwave devices connected to them. I have a Mosquitto Eclispse MQTT server running, and zigbee2mqtt and zwavejsui are sending messages to the broker. I can see the messages whizzing by in MQTTX and MQTT Explorer. Fantastic. I’m pleased.

In OpenHAB, I’ve used the GUI to create the MQTT Broker Thing, and now it’s time to configure the Zwave and Zigbee Things. It’s really nice to click through the GUI to create the MQTT Generic Things for each device and create the channels. Nice. My code in the GUI looks something like:

label: F2_BonusRoom_Fan
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:8fd56e1f3c
channels:
  - id: Dimmer
    channelTypeUID: mqtt:dimmer
    label: F2_BonusRoom_Fan
    description: null
    configuration:
      min: 0
      max: 99
      commandTopic: zwave/nodeID_4/switch_multilevel/endpoint_0/targetValue/set
      step: 5
      stateTopic: zwave/nodeID_4/switch_multilevel/endpoint_0/currentValue
      off: "0.0"
      on: "99.0"

This works swimmingly.

One thing that I learned early on with OpenHAB is that I wanted my Items to be textual files, and that was a great decision. I have several hundred Items, and it’s -so- much easier to make wide/sweeping/repetitive edits than clicking through the GUI.

Up until this point, all of my Things have been created in the GUI and all my Items have been created with textual files.

My SpiderMan sense is suggesting that I’m going to want to have all these MQTT Things (and associated channels) to be defined in a textual .things file(s). (I suspect I’m going to want to make major changes to my MQTT Topics and I’ll want to make sweeping changes). I’m an MQTT rookie,

The problem in my mind (laziness?) is that I don’t particularly understand the Things documentation here: MQTT Things and Channels - Bindings | openHAB, and there are a million options in there that someday I’m sure I’ll understand (it took me two years to understand all of the components of an textual Item configuration.

I’ve figured out that the .things file should look something like this:

Thing mqtt:topic:F2_BonusRoom_Overhead_Light "F2_BonusRoom_Overhead_Light" (mqtt:broker:8fd56e1f3c) 
{
    Channels:
    Type dimmer : dimmer "F2_BonusRoom_Overhead_Light" 
    [ 
        stateTopic="zwave/nodeID_2/switch_multilevel/endpoint_0/currentValue", 
        commandTopic="zwave/nodeID_2/switch_multilevel/endpoint_0/targetValue/set", 
        min=0, 
        max=99, 
        step=5 
    ]
}

It would be great if the Code segment in the GUI matched the .things code segment in the textual .things file. Or, in other words, I could click through the GUI and it would generate a textual .things file segment for me, rather than me having to plug through documentation and forums especially the first time, while learning, etc. Or another option would be to take the GUI Code segment and just plop it into a mythings.things.yaml file in the things folder.

I’m hoping that maybe I missed something in the documentation, and someone will tell me. Whoa! There is a much better way to solve this problem!

Appeciate the help as always!

SixO

Unfortunately there is no such feature.

If you really wanted this, you could write a “converter” (with the yaml as input), or if the Thing is already loaded in the UI, simply tell it the thing uid and generate “.things” code for it.

Many people here prefer the UI way of creating everything (things, items, rules). However, I am a fan of textual config for all those. You’re right about being able to perform mass changes more easily, but I went one or two steps further. I programmatically create them!

This was my earlier attempt at dealing with this: Another Things and Items file Generator

Today, I still use a yaml file as the “list” of my “devices”, but instead of generating .things and .items files, I create the actual Things and Items at runtime.

Hi, it’s easier to include the bridge into the things file.

Bridge mqtt:broker:mqttbroker  [host="localhost", secure=false] 
{
    Thing  topic IkeaColorlampe "IkeaColorlampe" [availabilityTopic="zigbee2mqtt/IkeaColorlampe/availability", payloadAvailable="online", payloadNotAvailable="offline"]
    {
        Channels:
            Type switch : state "power" [ stateTopic = "zigbee2mqtt/IkeaColorlampe/state", commandTopic = "zigbee2mqtt/IkeaColorlampe/set/state", on="ON", off="OFF"  ]   
            Type color  : color_rgb "Farbe" [ stateTopic = "zigbee2mqtt/IkeaColorlampe/get", colorMode = "RGB", commandTopic = "zigbee2mqtt/IkeaColorlampe/set", formatBeforePublish="{\"color\":{\"r\":%1$d,\"g\":%2$d,\"b\":%3$d}}" ]
		    Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/IkeaColorlampe/linkquality" ]
		    Type dimmer : brightness "Helligkeit"  [ stateTopic = "zigbee2mqtt/IkeaColorlampe/brightness", commandTopic = "zigbee2mqtt/IkeaColorlampe/set/brightness", min = 0, max = 254 ]   
    }

Thing  topic Flur1 "Flur1" [availabilityTopic="zigbee2mqtt/Flur1/availability", payloadAvailable="online", payloadNotAvailable="offline"]
    {
        Channels:
            Type switch : state "power" [ stateTopic = "zigbee2mqtt/Flur1/state", commandTopic = "zigbee2mqtt/Flur1/set/state", on="ON", off="OFF"  ]   
			Type number : linkquality "linkquality" [ stateTopic = "zigbee2mqtt/Flur1/linkquality" ]
		    Type dimmer : brightness "Helligkeit"  [ stateTopic = "zigbee2mqtt/Flur1/brightness", commandTopic = "zigbee2mqtt/Flur1/set/brightness", min = 0, max = 254] 
            
    }
} 

This is my structure of zigbee2mqtt things file
Greets

I want to point out that if you were needing to make “wide sweeping changes” for managed Items, depending on the nature of the changes, the most efficient way would be to:

  1. navigate to the Thing → Channel
  2. unlink and remove Items
  3. “add equipment to model” or “add points to model”
  4. recreate the Items with the sweeping changes applied.

I don’t recommend it, but one can also edit the JSONDB manually.