Skip to content

Does an openHAB Item exist?

In a more complex openHAB2 Rule I'm writing, I need to find out if a certain Item exist. If I try to access it when it does not exist, the Rule will fail. Not good.

I could pass in a parameter to the framework which builds the Rule, but that is cumbersome and requires changes on several places.

Let's see if I can have the Rule figure this out.

 

There is the getItems() function in ScriptServiceUtil. If I call this function and don't net a newArrayList back, the Item exist. That's easy to code:

import org.eclipse.smarthome.model.script.ScriptServiceUtil

if (ScriptServiceUtil.getItemRegistry.getItems("myItem") != newArrayList) {
    myItem.postUpdate(OFF)
}

That's all which is required to have the Rule not fail.

  • Twitter
  • Bookmark Does an openHAB Item exist? at del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • Digg Does an openHAB Item exist?
  • Bloglines Does an openHAB Item exist?
  • Technorati Does an openHAB Item exist?
  • Fark this: Does an openHAB Item exist?
  • Bookmark Does an openHAB Item exist? at YahooMyWeb
  • Bookmark Does an openHAB Item exist? at Furl.net
  • Bookmark Does an openHAB Item exist? at reddit.com
  • Bookmark Does an openHAB Item exist? at blinklist.com
  • Bookmark Does an openHAB Item exist? at Spurl.net
  • Bookmark Does an openHAB Item exist? at Simpy.com
  • Bookmark Does an openHAB Item exist? at blogmarks
  • Bookmark Does an openHAB Item exist? with wists
  • wong it!
  • Bookmark using any bookmark manager!
  • Stumble It!
  • Identi.ca

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options