ragoth
Junior Member
Posts: 64
|
Post by ragoth on Feb 27, 2017 1:40:17 GMT
Dear Papa and Computourist, Please provide general guidance and also Tips and Tricks to cross check, whether the Items follow the Rules file contents or the Rules tallies with Items file contents.
This mismatch makes the OpenHab to give Warnings, sometimes it hangs or delayed while loading the Startup files. Especially when loading the Rules file at Startup.
Please also clarify whether the Rules should be in the order of Items file contents or it can be any where within the Rules file.
I am correcting it by trial and error method, which consumes lot of time and frustrating, because I don't know how to pin point my mistakes.
Since you have vast expertise and "hands on experience" in OpenHab, your guidance will be a boon to beginners like me to trouble shoot this Startup problem.
Thanks in davance
|
|
|
Post by papa on Feb 27, 2017 19:44:07 GMT
Thanks for your confidence in my expertise, ragoth. However, I often think my remaining ability to make mistakes & learn from them might be among my more valuable qualities. I may have learned a lot, but still have so much to learn. I just spent a lot of time on Automating Irrigation where I was learning & correcting by trial & error. Based on what I think you're asking, here's some hints from I'm learning so far about troubleshooting OpenHAB config files (items, rules, etc) When you mention "Warning" I assume you are watching the main logs being displayed via terminal commands: tail -f /var/log/openhab/openhab.log tail -f /var/log/openhab/events.log That's a good way to see errors for correcting although such messages can be cryptic & if multiple, eye-crossing. Lately, I try to minimize the errors I see at one time, by building a rule a little bit at a time. Get one part working then move on to the next thing. At least for testing, insure that a rule will always fire once a minute by including a cron expression at the end of the when section: rule "Test_Case" when [possible change(s) in item states] Time cron “0 0/1 * * * ?”then [actions] end ragoth: "whether the Items follow the Rules file contents or the Rules tallies with Items file contents." Papa if an error says an openhab rule does not recognize a specific item, say valveOff, carefully examine how the item is spelled in xx.items & xx.rules They could be slightly different, like ValveOff (2 upper case letters) in the xx.items file. ragoth: "clarify whether the Rules should be in the order of Items file contents or it can be any where within the Rules file" Papa: My experience is item references can be anywhere in the .rules file. In addition my current experience is that one can have more than one xx.rules files, but only one xx.items. << Update 3/6/2017: Turns out one can have more than one items file, in fact it is recommended here for purposes of better organization. Added 3/8/2017, a caution about more than one .rules file with OpenHAB 1: each .rules file must include the imports needed for the .rules coding. (OpenHAB 2 does not require much importing, but if OpenHAB 2 still requires some import, each .rules file must include it for that file's coding) I often select & copy a significant part of an [error message] & then internet search for OpenHAB [error message content]. Here's where someone asked about a common error message rule "Control Kitchen heater" when Item Temperature_GF_Kitchen received update then if (Temperature_GF_Kitchen < 27) .... The above rule produced this log result ... Error during the execution of rule 'Control Kitchen heater': The name '<XFeatureCallImplCustom> < <XNumberLiteralImpl>' cannot be resolved to an item or type. This error message is cryptic, but we can learn to start reading it. We're told the error is in the rule "Control Kitchen heater." "cannot be resolved to an item or type" says we violated using items or types (if we try to relate two things, they must match in type). In the error expression "name '<XFeatureCallImplCustom> < <XNumberLiteralImpl>' notice the "<" (less than sign) & also <XNumberLiteralImpl> which means a literal number like 27. That points us to the rule line "if (Temperature_GF_Kitchen < 27)" As noted later, the line needed to be if (Temperature_GF_Kitchen. state < 27)
|
|
|
Post by papa on Feb 27, 2017 21:19:06 GMT
More hints on cleaning up OpenHAB errors Take a look at this post & go back to it often. If you (like me) don't know this stuff already, it takes a while to soak in, but even a first read may start you on being able to understand & avoid errors from not respecting types. I also use log generating statements in the rule to help pinpoint how far things are working & where they may be breaking down. The format is logInfo("arbitrary name you give the logging file", string message) For example, early in (made up) "Test_Rule" you might start with the line: logInfo("Test_Rule_Log", "Just triggered the Test_Rule") That should show up on the screen from tail -f /var/log/openhab/openhab.log being run in Terminal. logInfo("Test_Rule_Log", "Current Temp =" + Temperature.state) might show the results of a Temperature item Again you can strategically place such logging throughout a rule to see how far things are working & where they break down. Later you can comment out or delete the logInfo(). Be aware that the logging statements (like Rules) expect us to respect how to use items & literals or primitives. Also be aware that if you have multiple rules, even multiple rule files, logging display may interleave reports from different rules.
|
|
ragoth
Junior Member
Posts: 64
|
Post by ragoth on Feb 28, 2017 0:09:33 GMT
Dear Papa, thank you so much for your helpful immediate reply. Please keep sharing with us the kind of problems you came across and the solution you find, as and when you recollect from the past because you involved and spent so much in this technology.
|
|
|
Post by papa on Feb 28, 2017 2:08:09 GMT
You're welcome, ragoth. I still remember stumbling in the dark & still find myself there sometimes yet. Actually I done (as an amateur) other kinds of programming years ago, but just got into this javaish stuff & openhab for just the last year & a half. So I'm not so long at it, but I think that helps me be more aware of what a beginner might need to know.
I cannot seem to help myself from sharing. As I said above, I've just (I believe) finished work on Irrigation Automation that I hope to share before too long.
BTW I added another hint above about using logging statements to help debug rules.
Other readers ??, what hints for rule debugging do you suggest?
|
|
|
Post by papa on Mar 3, 2017 19:45:38 GMT
Rich Koshak provides great tutorials & assistance. The following (perhaps expanding) tutorial give some Rule Errors & what they mean Rule Errors and their actual Meaning IllegalStateException: this occurs when you have two copies of a Rule running at the same time trying to access the same data, in particular a container like a HashMap or List. Put a ReentrantLock around the access or the entire rule so only one instance can access the data at a time. NullPointerException: this is a catchall exception which usually means: you are referencing an Item that doesn't exist you are trying to cast the state of an Item that is NULL/Undefined to a type (e.g. DecimalType) you are trying to parse a String into a Number and the String is of an invalid format Ambiguous method call: this usually occurs when you try to call the postUpdate or sendCommand using a DecimalType. The problem is a DecimalType is also a Number and there are two different methods, one that takes a DecimalType and one that takes a Number and the interpreter doesn't know which one you meant. Cast the DecimalType to Number.
|
|
|
Post by papa on Mar 3, 2017 19:55:14 GMT
Recently the openhab.log display said ... Error during the execution of rule More Water Estimated: An error occured during the script execution: index=1, size=1 So the problem was in ... rule "More Water Estimated" when Time cron "0 0/1 * * * ?" then var Number WTH = Weather_Temp_Max.state var Number WTL = Weather_Temp_Min.state var Number moreWater = (((WTH + WTL) / 2) - 60) * .05 [etc] So I googled "openhab rule error index=, size=" In one case & another people discovered they left out a ")" Here an omitted keyword caused an Index Out Of Bounds error & logInfo() omitting the log file name caused a index=, size= error ^^ Those cases indicate the index=, size= error happens when something expected is left out. To check lines with multiple brackets, I use an editor like Notepad++. Such editors, when the cursor is near a bracket, highlight the matching bracket. In my case, I did not omit a matching bracket, but I did omit something expected. I was inspired to add a leading zero to .05. This fixed the error ... var Number moreWater = (((WTH + WTL) / 2) - 60) * 0.05
|
|
|
Post by papa on Mar 6, 2017 18:29:27 GMT
Update 3/6/2017: Turns out one can have more than one items file, in fact it is recommended here for purposes of better organization.
|
|
|
Post by papa on May 27, 2017 18:52:55 GMT
As seen in this thread, I like to maximize space on the User Interface (UI) display by using a rule to combine multiple items into one "dummy item." Then via the sitemap, I can display the combined items on one video line. One example of this stopped working. Others might benefit from what I learned in fixing it. (This presupposes one has installed OpenHAB's Weather Binding.) Relevant entries in the .items file (the first 3 to be combined into the last item) String Forecast_Today "Today's Forecast [%s]" <Question_Cloud> {weather="locationId=home, forecast=0, type=condition, property=text"} String Trend "Pressure Trend [MAP(trend.map):%s]" <Question_Cloud> {weather="locationId=home, type=atmosphere, property=pressureTrend, scale=1" } Number Precip_Probability "Precip probability [%d %%]" <rain> {weather="locationId=home, forecast=0, type=precipitation, property=probability"} String Forecast_Trend "Today, Trend, Precip ? [%s]" <Question_Cloud> In the .rules file: rule Predict when Item Forecast_Today updated or Item Trend updated or Item Precip_Probability updated then var String F_Today = Forecast_Today.state var String P_Trend = Trend.state.toString var int Precip_P_r = (Precip_Probability.state as DecimalType).intValue Forecast_Trend.postUpdate(F_Today + ", " + transform("MAP", "trend.map", P_Trend) + ", " + Precip_P_r + "%") end A created trend.map file in OpenHAB's transform folder contains the following: -=- equal=steady up=cooler/drier down=warmer/moister ^^ Question_Cloud.png added to OpenHAB's images folder .sitemap file:Text item=Forecast_Trend ======================================= Regarding that rule, OpenHAB reported an error on instance of NULL. The items seemed OK. They display fine individually on the UI. The "then" section of the rule can be tricky. I wondered if I or OpenHAB had changed something to cause the error. I experimented with various parts of the rule's then section & still got the error. I looked again at the items (amidst a long list) which actually looked like this: String Forecast_Today "Today's Forecast [%s]" <Question_Cloud> {weather="locationId=home, forecast=0, type=condition, property=text"} String Trend "Pressure Trend [MAP(trend.map):%s]" <Question_Cloud> {weather="locationId=home, type=atmosphere, property=pressureTrend, scale=1" } Number Precip_Probability "Precip probability [%d %%]" <rain> {weather="locationId=home, forecast=0, type=precipitation, property=probability"} NumberString Forecast_Trend "Today, Trend, Precip ? [%s]" <Question_Cloud> Finally just above the last item (which I wanted to display as a collection of the other 3), I finally saw the line that started with " Number" & nothing else. Apparently that Number line corrupted the Forecast_Trend item that I wanted to display. Once I deleted that line that only said Number, the rule worked. Lesson learned: The source of an OpenHAB error is not necessarily in an expected place (like complicated rule lines). It may be a little thing (like an almost blank item line) that we overlook amidst a long list of other things that we are studying intently.
|
|
|
Post by papa on Aug 14, 2017 16:17:50 GMT
Can you tell the difference between this OpenHAB item entry ... String Node12Rssi "Gardn_12_RSSI (db)[[%s]" <network> (Nodes) {mqtt="<[mosquitto:home/rfm_gw/nb/node12/dev02:state:default]", mqtt=">[mosquitto:home/rfm_gw/sb/node12/dev02:command:*:default]" expire="3m,Offline?" }
and this version of the same OpenHAB item entry that works better? ... String Node12Rssi "Gardn_12_RSSI (db)[%s]" <network> (Nodes) {mqtt="<[mosquitto:home/rfm_gw/nb/node12/dev02:state:default]", mqtt=">[mosquitto:home/rfm_gw/sb/node12/dev02:command:*:default]" expire="3m,Offline?" }
An anomaly was bugging me. When I viewed the OpenHAB User Interface through a computer on the same network as the MQTT server, the first version showed up fine. However, Node12Rssi & similar items did NOT report their values on my iPhone OpenHAB app.
I just closely compared the Node12Rssi item with working similar items. Did you see the extra character in the first version, [[%s] instead of [%s] in the second version that works correctly on the OpenHAB app?
It's interesting that the first version worked sometimes. This is another lesson in troubleshooting by reading the symptoms & details carefully. I probably copied, pasted, & edited an earlier RSSI entry that seemed to be working. It's a good reminder that copy/paste/edit can prevent some errors & perpetuate other errors.
|
|
|
Post by papa on May 2, 2018 13:56:01 GMT
ngy was having problems getting his first RFM69 Gateway, Node, & OpenHAB working together. we had a good analysis of symptoms: "Gateway & node are talking. Gateway is connected to local network & MQTT. Still node data was not getting through the gateway to the OpenHAB User Interface or logs, but the cause did not seem to generate a log error." ngy found the problem or at least a solution. Searching online showed having MQTT Action installed with the MQTT binding has issues: github.com/openhab/openhab1-addons/issues/5038 (by Richard Koshak, a very knowledgeable user) ngy reflashed openhabian, and only installed the MQTT binding, and voila! everything worked like a charm. Lessons learned ??: 1) I remember similar things about the voice command feature interfering with other features. Sometimes in excitement over a new project or in frustration trying to get things to work, we try too much. It's probably best to get the minimum aspects working & then add other things. 2) ngy reflashed openhabian, started a new OpenHAB install, but NOW he was using all his gained experience about correct installation. Perhaps he cleaned out other problems introduced when he was trying everything. Again, it may be best to go back to minimums & gradually add more & watch how well the additions work before moving on to more additions.
|
|
|
Post by papa on Nov 3, 2018 0:57:58 GMT
OpenHAB 2 Error Not What It Seemed I had these items: Number Water_Stat21 "Water Status [MAP(water.map):%s]" <cistern> {mqtt="<[mosquitto:hom2/rfm_gw/nb/node21/dev66:state:default]"} Number Water_Display "Water Level [%d %%]" <cistern> Switch Node21VibState ==========================
I had a rule that included rule Water_Data when Item Water_Data21 received update then var Number W_Stat = Water_Data21.state var Number W_Show = 0 if (Node21VibState.state == OFF && W_Stat == 0) { W_Stat = 1 W_Show = 0 } Water_Display.postUpdate(W_Show) Water_Stat21.postupdate(W_Stat) end ========================
The Water_Data rule threw an error message on the last line before "end", something like "the name xxxxxxxxxx.postupdate xxxxx cannot be resolved to an item or type" I believed that I had mismatched types, but that was not my error.
Finally, helped by Water_Display.postUpdate(W_Show) just above the errored line, I realized a tiny spelling error tripped me: I needed Water_Stat21.postUpdate(W_Stat) instead of Water_Stat21.postupdate(W_Stat) Missing one uppercase letter caused the error.
|
|
|
Post by papa on Apr 14, 2019 21:21:00 GMT
Good Hints on Troubleshooting openHAB RulesSee these helpful hints by knowledgeable openHAB Foundation member, Rich Koshak.
|
|
|
Post by papa on Aug 7, 2020 16:23:38 GMT
Dealing with Ghost Rules & Other Ghost Configurations "Ghosting" can happen in openHAB. For example, I currently drip irrigate my garden for a certain morning period unless (with a user interface switch) I turn off the flow to a garden bed. Recently I saw strange behavior on the user interface. Seemingly by themselves, water valves turned on. Also on a user interface, supposedly inactive items were active. I thought, "This seems like openHAB is running another set of irrigation rules that I had deactivated by renaming the file tag from .rules to .rule r. Those previous rules were like ghosts that materialized. Configuration ghosting can go both ways. Sometimes we add an item or a rule or ... & openHAB does not change accordingly. They disappear like a ghost. openHAB is built to preserve the status quo which is usually helpful for us, but can sometimes cause issues like this ghosting. The fix is the same for both types of ghosting: clear the openHAB cache. That is, stop openHAB. Then in openHAB's \userdata folder, delete the \cache & \tmp folders & restart openHAB. That causes openHAB to start fresh with the current configuration.
|
|