I admit it. I’m getting grumpy. I’ve been somewhat appalled at the number of users who seem to turn off their brain as soon as they post on this forum and do not think to do even the most basic things to help solve their problems. The purpose of this post is to give you a jiggle and maybe reengage your brain.
When I have a chance to calm down a bit I’ll probably work this into a page in the Getting Started Tutorial, with edits of course.
How do I …
Everyone, from the expert to the first time user is going to encounter something they don’t yet know how to do in openHAB. There is no shame in not knowing how to do something. We all have to start somewhere. So how do you figure it out?
Look in the docs
Even if you think you know, look in the docs again. OH changes with every release and not every change gets announced, or you may have missed the announcement. So be sure to frequently return to the docs and look for changes. There may be a better way to do it now. There may be more information. Something may have been removed or the behavior changed.
So particularly if something worked before but doesn’t work now, the first place to look is the docs.
Text file users
Look in the UI. Set it up in the UI. Take note of the options that are presented to you. Pay attention to the notes under the fields. Look at the code that is generated when you set some fields. To some extent, the UI is self documenting and often that is much more effective than the written docs. The UI is also constrained. It won’t let you create an unsupported configuration (most of the time).
So if something isn’t clear or incomplete in the docs, especially when creating Things in .things files, look at how to do it in the UI. Frankly, if you refuse to use the UI even to learn you are basically cutting off your nose to spite your face.
What does this button do?
Channel your inner DeeDee. Push the button! In the time it takes you to ask on the forum and for someone to reply you could have just done it. Don’t be afraid to click around and try stuff. I promise, there is no self destruct button. Watch the logs as you do it.
I did X and it didn’t work
Before posting on the forum, look in the logs. I’ll be the first to admit that the errors in the logs don’t always make obvious sense, but often they get you pretty close to what the problem is. Sometimes the lack of logs is going to be informative.
Logs will be the first thing we will ask for, so save us all some time and look at the logs to begin with. Post the logs when you ask your question.
My Rule didn’t run, why?
First you need to make sure. If you haven’t added logging to your rule, unless you know where to look (more on that in the advanced section below) there will be no evidence in the either openhab.log and events.log if your rule ran or not. Only if there is an error or you added logging to the rule will there be any evidence that the rule ran.
Sometimes you can infer that the rule ran based on the events that take place in events.log.
Add lots and lots of logging to your rules
It is pretty frustrating when a user posts a bunch of code with basically “it doesn’t work” or “I get an error around line 12” or something like that. The first thing you need to know to figure out what is going on and the first thing we need to know to help you is what is going on in that rule at the time it runs. What are the states of the Items that are being used? What is being returned by that call to persistence? What was the result of that calculation? What are those variables set to?
The only way to definitively answer these questions is to log them out. Before opening a new thread asking for help, you will drop by more than half the amount of time it takes for us to get you to the answer if you add this logging and posted that in your original post. You will most likely figure out what is wrong on your own and not even need to post.
If you have a particularly thorny problem, every other line of your rule should be a logging statement.
Advanced Ways to See What’s Going On
OH 3 brings a number of new tools to see what’s going on that can be very helpful. But OH 2 and before also have a number of features.
Binding Trouble
Change the logging configuration to put the binding into debug or trace level logging. The easiest way is from the Karaf Console. See the docs for details. If there really is a problem with the binding, we on the forum and the developers will need those lower level logs to see what’s going on and help.
Following Events
events.log has all the Item changes, Item commands, and Thing events. In OH 3 the Developer Sidebar event stream will also include Item updates, and Rule events. So between the two you should be able to see every event that is taking place in OH over a period of time. Use these to answer questions like:
- Did my Item update?
- Did the rule run?
- What state is my Item in?
Write throw away code
OH 3 has a --Scratchpad-- Script Rule accessible from the Developer Sideboard. Use this (or your own equivalent) to send commands, post updates, log out the states of important Items, and do any other exploration or testing necessary to figure out what is going on. A couple of lines of rules code can often tell you a ton of information.
Run the rule by clicking the play button in the UI and how ever you prefer to do so if using text based rules.
Developer Sidebar
Use this tool. This tool is probably the most useful and important new feature added to OH 3. From this you can:
- See all the events your OH instance is generating (filterable)
- See and set of Items, Things, or Rules that is relevant to what you are working on at the moment. This can be particularly useful to see the current states of the relevant Items.
- Enter and test out Expressions used in MainUI widgets.
- Access the --Scratchpad-- Script Rule
- Create a custom menu of shortcuts to perform various activities.
Look at the JavaDocs
Every time you are interacting with openHAB from a rule, no matter what language it’s written in, you are interacting with a Java Object. All of the Java Objects that make up openHAB are pretty well documented at Overview (openHAB Core 3.1.0-SNAPSHOT API). So if you are wondering what you need to import in order to create a timer, search for “createTimer” there and you will see it’s in * org.openhab.core.model.script.actions.ScriptExecution. Want to know what all you can do with an HSBType (state from a ColorItem)? Search for HSBType and you’ll see everything it can do.
Especially if one is using JavaScript or Python and wants to do some of the more advanced stuff like mess with metadata, create rules, etc and do not want to use the Helper Libraries.
Helper Libraries
Speaking of the Helper Libraries, if using JavaScript or Python, even if you are not planning on using the Helper Libraries directly, you should always use them as the first place to look for how to do something .
When you do need to post to the forum
Please please please make sure to read all of the replies in their entirety. It’s no fun to have to type in the same answer over and over again. Definitely ask questions if you don’t understand something in a reply. But it is very frustrating when asking a question that is clearly answered in a previous reply.