I hope this is the appropriate place for such a question. I’ve been playing around with OpenHAB for a number of months now and have finally gotten around to writing some rules. One (seemingly) obvious thing seems to evade me though after a bunch of searching. Where is the reference material for properties of items, groups, etc.?
For example, I see plenty of examples for things like item.name, and item.state. Where do I go to find the available properties for an item that I can then write rules against? I’ve looked through OpenHAB and Eclipse documentation, but I’m coming up empty. Surely this is documented somewhere and everyone isn’t just adapting existing examples.
By far the easiest is to use Eclipse SmartHome Designer 0.8 and the <ctrl><space> shortcut. Basically type the name of an Item and . and then press <ctrl><space> and a dialog will pop up with all the valid ways that statement can be completed. This will give you a list of all the methods and properties on that entity, in this case the Item.
However, I don’t think there will be too many “advanced” things you are missing out on. In all my years writing rules for my self and others on this forum the only methods I’ve ever used are:
previousState // requires persistence
lastupdate // requires persistence
The Javadocs for the classes are located here, Item is located here. But for the most part, you shouldn’t need to go to the JavaDocs.
Most of the advanced stuff you would be doing with Items is going to have to do with Persistence which is documented here, in particular this section.
Rich, you’re a one-man army on these rules. Thanks for the tip. I ended up logging the item itself and then kind of working backwards from the item’s properties as they showed up in the log. The persistence related properties obviously don’t show up that way, but I digress.
I was getting along with the basics that I’d seen from your countless tutorials and responses as well. I actually ended up needing to use the type property on an item for a rule. I have dimmers and an outlet in a group that I want to set to a certain brightness. The outlet obviously doesn’t take a number via sendCommand, so I had to test the type first and send the numeric or ON/OFF accordingly.
Next on my list is parsing an item’s group list so I can potentially skip it (or maybe not include it at all via lambda) in a rule if it’s also a member of a different group.
Just when I think I’ll never use something is when I find I need to use it more than ever.
Thanks again, man, you’re a life saver around here.
This is super useful. I don’t know if you know or not. is it possible to define a new object property, for example.
Item.triggeredByMotion = true
I am in the process of writing some Lambda global functions that handle switching lights on and off via a presence sensor, while retaining full manual switch operation and would rather not have to reference external variables if I can simply define them on the object. I’m sure there would be a bunch of other useful scenarios too.
The typical approach for this example would be to create a TriggeredByMotion Group and add each light that is triggered by motion to that Group.
Seems like a generic single Rule would be a better approach than lambdas. Obviously I don’t have details but from what you describe I see absolutely no reason why this would need to be implemented in a lambda.
IMHO, global lambdas are a code smell and should only be used rarely. There are all sorts of ways to achieve this. Look at the Design Pattern postings, in particular the Associated Items DP. Also look at the triggeringItem implicit variable and the Member of Rule trigger.
The Separation of Behaviors DP could also be useful.