Setup OpenHAB3 with CLI and textfiles

Dear OpenHAB community,

after having experimented with other smart home solutions, I decided to give OpenHAB3 a try as well :slight_smile: since I was using OpenHAB 1.x and 2 before, where I actually liked the text-based configuration a lot, I wonder whether that’s still working on OH3.

So I went for installing Z-Wave and so far that worked all well. From defining stuff in the things file and the items file. Also configuration in the .things file worked. Great job! :+1:

Now I’ve stumbled upon an issue. I would like to set up MQTT as well through text files. In earlier OH, that went through the services files, but it looks like that I now define things for that as well. Fair enough! Yet, on the bindings doc, I couldn’t find any documentation that explain how to set up MQTT in a similar way like Z-Wave. On the forum I searched, but also only found the UI based way.

So I’d kindly ask, whether somebody could either help me the way to point me on documentation that explains the text-file-based way for MQTT, or help me with samples, of how to define things and items for MQTT.

Thanks a lot and have a great Sundy.

dont know if i can help, i use the mqtt-binding in oh3 text-based.

my things-file looks like:

Bridge mqtt:broker:unsecure_stove "MQTT Broker" @ "MQTT" [
    host="stove",
    // host="xx.xx.xx.xx",  (alternativ ip-adresse)
    port="1883",
    secure=false,
    username="xxx",
    password="xxx",
    clientID="xxx"
] {
    Thing topic stove "MQTT - Ofen" @ "MQTT" {
        Channels:
            Type number : temp [
                stateTopic="stove/temp/state"
            ]
            Type colorHSB : led [
                stateTopic="stove/led/state",
                commandTopic="stove/led/set"
            ]
            Type string : visualize [
                stateTopic="stove/visualize/state"
            ]
            Type switch : last_burn [
                stateTopic="stove/last_burn/state",
                commandTopic="stove/last_burn/set",
                on="True",
                off="False"
            ]
    }
}

and my items-file looks like:

Number iEWoK_Ofen_temp "Abgastemperatur[%d]" <fire> (iG_Ofen) { channel="mqtt:topic:unsecure_stove:stove:temp" }
Color iEWoK_Ofen_led "Status-LED" <rgb> { channel="mqtt:topic:unsecure_stove:stove:led" }
String iEWoK_Ofen_visualize "Statusmeldung[%s]" <info> { channel="mqtt:topic:unsecure_stove:stove:visualize" }
Switch iEWoK_Ofen_last_burn "Letzter Abbrand[]" <none> { channel="mqtt:topic:unsecure_stove:stove:last_burn" }

perhaps this may help you :slightly_smiling_face:

1 Like
1 Like

Thanks a lot for your help! I think this will be my occupation next Sunday :slight_smile:

Thank you @hafniumzinc - I wasn’t aware that there’s such stuff also on Github. I was looking at the text docs.

You were looking in the right place, don’t worry. This particular sub-page never made it into the docs unfortunately.

2 Likes

Hello @bastler & @hafniumzinc,

thanks but one question is still open to me: imagine that the devices are Z-Wave devices and hence, the channel configuration is already done with the Z-Wave channel.

How can I now - when a sensor reports a temperature publish that via MQTT and when over MQTT the command for a switch comes in set the appropriate state (ON/OFF) for the Z-Wave switch?

It actually also looks like I will have to write quite some code for all my sensors and actors. For each item, I need a corresponding definition in the things file, right? Puh - gonna be a long weekend :joy: I assume there is no “simple” or automated way to publish/receive states and commands for any item via MQTT?

Thanks a lot for your help.

So to be a bit more precise, I would like to control my Z-Wave devices via MQTT, but the following doesn’t work:

Switch 		PLUG_Ventilation			"Ventilation"				{ channel="zwave:shenzhen_coolcampwrplug_00_000:controller:plugVentilation:switch_binary", channel="mqtt:topic:mosquitto:ventilation:state" }

In the log I can actually see, that via MQTT the command (ON/OFF) was sent, but the Z-Wave device doesn’t change its state. Same with power consumption - the numbers aren’t reported via MQTT.

@rlkoshak: I was pointed to you by @bastler who said you might know more about the MQTT stuff in OH3. Perhaps you have an idea and can help me a bit? I basically want to connect 2 OpenHAB instances via MQTT and several Wifi MQTT devices including a switch, that should “virtually” change the state of my Z-Wave device. Do you have any idea of how to make this work? What am I doing wrong?

Thanks a lot for all your help guys. You are amazing!

The Follow Profile might work here. Items | openHAB

Or you can use the Remote openHAB add-ons to link the two OH instances together. It’s not MQTT though. Remote openHAB - Bindings | openHAB

Or you can use the MQTT Event Bus which you can install from the Marketplace if running OH 3.2 M2 or later. Marketplace MQTT Event Bus

Or you can use a Rule.

1 Like

Hello @rlkoshak ,

thanks a lot for your help. The follow profile unfortunately didn’t work out. My try was:

Switch 		PLUG_Ventilation		"Ventilation"				{
	channel="zwave:shenzhen_coolcampwrplug_00_000:controller:plugVentilation:switch_binary",
	channel="mqtt:topic:mosquitto:ventilation:state" [profile="system:follow"]
}

but then there’s no reaction to an incoming MQTT event at all on the Client/Z-Wave side. Without the profile attribute, at least the state is propagated, but the Z-Wave device itself doesn’t actually turn on (what is weird - the item state is set to the one received by MQTT, but the device is not turned on physically).

I will check the other possibilities you mentioned. The EventBus stuff looks very promising, especially if I want my installation to grow. One sensor easily has 4 or more channels, and dealing with each of them manually, can end in a lot of work I suppose :speak_no_evil: :rofl:

Thank you very much. Very much appreciate the help.

Hello @rlkoshak,

sorry if I am perhaps just too new on this to fully be able to execute your instructions, but I’ve installed the Remote OpenHAB binding, defined the remote server in it and then added changed my device to be like this:

Switch PLUG_Ventilation “Ventilation” {
channel=“zwave:shenzhen_coolcampwrplug_00_000:controller:plugVentilation:switch_binary”,
channel=“remoteopenhab:server:oh2:PLUG_Ventilation”
}

Yet, the same issue as with MQTT: the device doesn’t change or work.

So, once again to explain my Situation - perhaps that is what I yet haven’t done too well:

  • I have one OpenHAB 2 server that servers my Basic UI that I use on my phone. This server is running since quite some time.
  • I have now got a second Raspberry Pi with OpenHAB 3. I have some Z-Wave devices managed by that device.
  • I would like commands from OpenHAB 2 server’s items (through BasicUI) to be propagated to the OH 3 Raspberry Pi and states (like energy consumption) be reported back to the OH2 server.

I don’t get that set up, yet. Neither through MQTT, nor through Remote OH.

What I could try, would be this Event Bus thing in OH2 and install OH2 on the Raspberry, but since it’s a new device, I would actually like to run OH3 on that, also to gain some experience, before upgrading my server.

But now I’m stuck :frowning:

Edit: What actually happens is that the state of the item changes in the log and on the OH 3 UI (a switch for instance). But the device effectively doesn’t change its state, i.e. the consumption stays at let’s say 10W and when I look at the powerplug, it is still on, though I turned it OFF and the switch is set off in UI. When I then in the OH3 UI change the switch on and off again, the device changes physically its state.

You probably need to review openHAB basics, then examine what you are expecting in a new light.

OpenHAB Items have a state.
This represents the condition “this is how it is”.
OpenHAB Items can be sent commands. This is an instruction, “do this”.

In general, bindings pass incoming data to Item state, “the light is on”.
Item commands are passed through the binding to the device, “turn the light on”.

So if you link two ordinary channels to one Item, either can update the Item state.
An incoming state update is never passed to either device.
An Item command is passed out to both devices.

There are ways to link devices to follow each other, but first be clear about what you want to be passed around when.
This stuff can be quite a headache and very often the most understandable way to control it is with separate Items and rules doing the sharing.

1 Like

Hello @rossko57,

thank you very much for explaining this to me. It looks like my aim to use the new Raspi with OpenHAB3 and keep the old one with OpenHAB2 is not a good idea. I read now a bit through the docs and figured that OpenHAB2 with MQTT Eventbus is doing what I need. It passes the commands from the main instance to the node and updates states back the other way. This way I can turn on lights but also get sensor data back to the main node. So I have erased the OH3 installation from the Pi and put on OH2.

My biggest headache now is though, that I expect that I am riding “a dead horse” as I have no idea of how long OpenHAB2 will be supported. I am taking the pragmatic approach that for now it does the job.

Thanks all for you help.

I don’t see why. Whatever you want to do, it can be done by setting stuff up right.
First be clear about what you want to do.

No problem, use the postCommand option on the incoming MQTT channel, so that incoming MQTT message will be treated as an openHAB command by the zwave binding.