I wanted to use openhab to send RGB values via mqtt. I eventually figured it out, although the catch22 of having to initialize values so you aren’t in a null state so that you can define the values was weird.
Anyway, I figured out how to get it to send rgb values, or formatted rgb values to the specified topic. BUT I want to send each value to a different MQTT topic, and that is where I started loosing my mind. I had done it before in openhab2, (using .rules and such) but now there seem to be about a billion different ways to set things up. I have looked through a bunch of different posts and read different pages in the documentation, but nothing seems to fully explain any one way to do it and there are so many different versions and methods I am never really sure which one I am reading about.
So my question is this, what method should I choose to use? If I can choose one route, maybe I can stop going in 20 different directions at once.
Thanks. Sorry for asking stupid questions but I am really derped up.
I’m running openHAB 3.2.0 on a rasp pi with mosquito as my broker but my question isn’t really about debugging so I don’t think it is particularly relevant.
The built in IDE is nice, but it confuses the hell out of me.
For example, what does this even mean? Why does a tab cause it to fail? Where is the actual program? This looks like I am just defining a datatype right? The documentation doesn’t really seem to explain how multivariable types work. From experimentation, the formatbeforepublish seems to iterate through the array for each %s, but I have no idea how to specify variable[n] or anything like that.
label: Generic MQTT Thing
- id: ter
formatBeforePublish: Red%s, Green%s, blue%s
I think you have landed in the Thing configuration. That has nothing to do with rules. You can still use your rules files (DSL) as before. The difference now is how you set up the connection between your items and the actual mqtt topics. That is why you probably ended up in the thing configuration.
When you change the state of your items, does the light react now? I. E. Does your generic mqtt thing work? If that’s the case, then you can move on to the rules, where you should be able to use most of what you had on OH2…
I got it working. And you are right, I am using the thing configuration, not the rules. I just don’t know which way to do it if I want to get help from other people when I get confused.
Is there a right way to do it?
For example, this works
- id: redchan
- id: bluechan
- id: greenchan
But it seems sloppy. I have now created three channels for one item, which I suppose is what I wanted to do. I don’t know. I think I just need to sleep I don’t know what I am even saying. Please ignore me.
So why not do it that way still? It should work largely the same, perhaps even identically.
That’s a YAML representation of an MQTT Thing configuration. It’s a human friendlier view of how OH internally stores and represents Things created through the UI. Internally it uses JSON which is hard for humans to read and understand. But for the most part you usually don’t need to mess with the YAML in the code tab for Things unless you are doing a copy/paste/edit type operation.
Because in YAML white space has meaning. Only use spaces and two spaces per indent. Don’t use tabs.
Nowhere, this isn’t a program (I assume you mean rule?). This is a Thing. It’s a configuration.
I cannot strongly enough recommend that you (re)review the Concepts section of the OH docs and the Getting Started tutorial. I’m guessing in OH 2 you were using the 1.x version of the MQTT binding so the whole concept of Things and Channels are foreign to you. These and other concepts introduced in OH 2 are explained and demonstrated in those parts of the docs.
That is defining a Thing. A Thing represents a device. A Thing has one or more Channels, each of which represents a sensor or actuator on the device. Channels are linked to Items.
Hard to say without more details. In general, the “right” way is any way that works.
This is a somewhat unusual use case where each color gets published as a separate message on a separate topic. Because they are separate topics than yes, this is probably the best way, using a Thing.
An alternative would be to use a Rule and the publishMQTT Action. In that case you wouldn’t have the Thing at all. Just a Color Item that triggers a a Rule.