events.sendCommand v myItem.sendCommand

I am using openHAB 3.0.1 via my browser to its Main UI and continue to stumble around wrt Javascript rule & script writing. I have seen recommendations that I use the method myItem.sendCommand(ON) rather than static function events.sendCommand(myName, ON). My problem is that I have not successfully mapped an item’s name to its corresponding item object. I have tried to use ir(myName) which (I believe) is the same as ScriptServiceUtil.getItemRegistry().getItem(myName), but the resulting object does not have the method I am looking for.

So any insight regarding getting an item with a sendCommand method is appreciated. Or, perhaps the advice is stale?

That’s only for Rules DSL. In the other languages the Items do not even have these methods.

You have to pull it from the ItemRegistry.

var MyItem = ir.getItem("MyItem");

But that still won’t get you to where you can call MyItem.sendCommand(). That simply doesn’t exist in JavaScript or Python. You must use events.

Thank you! You have brought immense clarity to my understanding, much like being whacked with a 2⨯4 brings clarity regarding carpentry.

I’m beginning to believe DSL is the only viable mechanism for custom scripts and that Main UI, Javascript, and Python are really neat demos, but not a lot more. My next quest is to figure out what DSL stands for.


That’s quite a leap, and absolutely false. Check this recent post for the current state of play. You’ll find that the ‘real’ languages (JavaScript, Python, JRuby) are far more capable than DSL.

Yes, I have been reading (a lot for me) about openHab’s DSL, Python, and Javascript. I’d like to think that my assertion is more a reasoned conclusion than a leap. Nonetheless, I’ll continue to pursue various aspects with a mostly open mind. Your answer has been most helpful in that it narrows the possibilities while better defining my mental model of what openHab provides.

My problem with being a newcomer is that documented information seems non-existent. So I spend a lot time with google, grep, find, and diff. Then I risk wasting a forum member’s time with my queries.

Reading forum threads about the differences between OH 2.x and 3.0 when the new-comer is just trying to grasp a simple fundamental with a simple working example is like reading about the differences between Beowulf and The Queen’s English when a new comer needs directions to the nearest transit stop.

Again, thank you for your response. I really appreciate it.

see here for a structured information of DSL