From your answer I assume that the solution must be written somewhere. But from a rookies point of view this is a bit hard … It’s not that the documentation on OpenHab is that exhaustive isn’t it? And the simple fact that a text file consists of imports, declarations, and rules does not exclude what I was trying to do. Or did I miss that?
Probably I am too much preloaded with other language syntax that I’am doing things wrongly here, but I am willing to read into it.
If you please give me a second chance and a hint on this issue, it gives me the following error. The logs working fine, but the avgRoomTemp reports a null exception. What do I miss here?
An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
> rule "React on TEMP_FFParents change/update"
> Item TEMP_FFParents received update or
> Item TEMP_FFParentsSet received update or
> Item GFH_FFParentsForceFlow received update
> logInfo("GFH", TEMP_FFParents.state.toString)
> logInfo("GFH", TEMP_FFBath.state.toString)
> logInfo("GFH", TEMP_FFEmil.state.toString)
> logInfo("GFH", TEMP_FFFelix.state.toString)
> logInfo("GFH", TEMP_FFOffice.state.toString)
> val avgRoomTemp = (TEMP_FFParents.state + TEMP_FFBath.state + TEMP_FFEmil.state + TEMP_FFFelix.state + TEMP_FFOffice.state) / 5
> //logInfo("GFH", "avgRoomTemp: " + avgRoomTemp.state)
> logInfo("GFH", "avgRoomTemp: ")
Your original post stated you only has one line in the rules file. Obviously that is not a valid rule. That was the basis for my original comment.
Why the > at the beginning of the rule lines? Here on the forum we only know the data you provide about your system. In rules, spacing and syntax are important. I doubt you wrote the rule as posted here.
No, it isn’t. It is an Item, of flavour Number.
Items are not variables, Items are complex objects with several properties - label, icon, name.
The interesting part is the state.
Items can have states like “Help” or CLOSED or 223.47 or 55% …
The state is not a Number or a String or a DateTime etc… it’s a state.
Because it’s a state, if you need to handle it like a number that’s what you do. If you need to handle it like a string, you do something else.
Actually it’s a NumberItem. It carries a state (among other data members like name, label, list of group names, if it’s a Group the list of group members, etc). The state is of type State. Different Item types carry a different subclass of State. In NumberItem’s case, it carries a State of type DecimalType which itself implements the Number interface. When you call SomeItem.state you get back a State Object. You need to cast it to a Number (or DecimalType) if you actually want to do number type stuff with it like comparisons or calculations.
Also every Item can carry a special pair of states called NULL (never initialized) and UNDEF (Item is in an unknown state, for example the binding lost the connection to the device). If you cast a Number Item’s state to Number without first checking that the state isn’t NULL or UNDEF will result in an exception.
As I said, TEMP_FFParents isn’t a Number, it’s a NumberItem. You can sometimes get away with TEMP_FFParents.state.intValue though, if there is enough context at runtime for the Rules Engine to figure out that TEMPParents.state is of type DecimalType and therefore has an intValue method.
Thx for all the explanations and the tips for using HABApp and Jython - I will look into this.
All the explanations that it’s an object with additional properties like label etc. is fine, but it is not good enough to tell why there is no .getInt or similar way of doing this.
But again thank you for the heads up!