[SOLVED] How do I refer to things and items in rules which were defined in the paper ui?

Hey all,

I need your help, because I’m a little confused right now. First let me explain my situation: I’ve developed a little smart device (let’s just call it “MagicKnob”) and I wrote a custom binding for it. It supports Upnp discovery, eventing and so on. In it’s current state, it’s almost ready to hit the market (altough it’s just a product developed during my bachelor thesis and some other projects). The core idea is that I want as little work as possible for the enduser to do in order to use the MagicKnob. Keyword: Plug and Play. The same goes for the use of the MagicKnob with OpenHab2. The user just has to turn the MagicKnob on and OpenHab2 will discover it. To add the MagicKnob as a new thing in OpenHab2, the user shall use the Paper UI (with it’s simple mode for channels). There shouldn’t be any needs to configure the .things or .items files. Let’s assume the end user did all necessary stuff, and the thing with all it’s channels (and therefor bound items) is present in the paper ui. Now the user wants to add some rules. Currently there is no full functional rule configuration engine within the paper ui (besides the experimental one). The user has to create a custom .rules file (or modify an existing one) in order to add a rule. Throughout every ressource I found out there (examples and stuff), every thing or item that is refered to in the .rule file is also present in the .thing or .item files.

tl;dr: I want to know how I can accesss the things and items that are only present in the paper ui (and not the thing/items config files) within the rules file. It’s stated by @martinvw in this thread/post that it actually is possible, but it was never explained how it is done (didn’t want to reply there, cause it’s quiet old). My problem is, that I don’t have a name to access the thing or item.

Example for a case where the item is defined in the items file:
This is in the item file

Switch switchOfMagicKnob

This is in the rules file

rule
when
   switchOfMagicKnob.someBoolFunction(...)
then
   switchOfMagicKnob.sendCommand(ON)

Example for a case where the item is defined in the paper ui:
There is nothing in the item file

This is in the rules file

rule
when
   ???.someBoolFunction(...)
then
   ???.sendCommand(ON)

My thoughts were that it may be possible to declare a val which refers to the item or thing like:

val myItem = Item <someUniqueIdentifier>

Hope you can help me out with this :slight_smile:

You’d use the Item’s name as shown in PaperUI, that is its unique identifier. Items are shared across “the system” whether they are created by PaperUI or by .xxxx.items files.

Which text do you mean by “name” in case of a thing and not an item? Is it the normal label or the udn/uuid (not sure which one it is) like yahooweather:weather:losangeles . How do I have to address it when it has spaces?

Yep, that’s a Thing name. yahooweather:weather:losangeles.wind or suchlike would be a channel name

EDIT - re spaces, perhaps you mean this kind of channel?

 Channel "astro:sun:home:rise#event" triggered START
1 Like

Think I got it! One can use the udn/uuid like yahooweather:weather:losangeles but one has to place it in " ". That is not pointed out in the rules explanation. I will not mark my problem as solved just in case if I’ve got any new question refering the same problem.

Instantly back with a new question after your answers @rossko57. What do I have to do, to call a method of an item from the paper ui?

I would access the item like this:

Item "myexampleitem:something:1"

Now I want to check the state of the item. The rules explanation states that you have to do something like this:

MyExampleItem.state.toString

But this doesn’t seem to work if the item is from the paper ui and therefor has no variable name. And this doesn’t work:

Item "myexampleitem:something:1".state.toString

Can you help me out with this one too? I thought maybe one could do something like this:

val myExampleItem = Item "myexampleitem:something:1"
myExampleItem.state.toString

Edit: Need to know the same for Things. Something like

Thing "mything:something:1".state.toString

is also needed.

Hi @TheTmirror

First of all I would suggest you take time to try and understand the difference between a Thing and an Item as your questions suggest you do not have an good understanding. An example, for instance, is that a Thing doesn’t have a state and you cannot treat it like an Item by calling .state.toString().

Hey @danielwalters86,

I’m pretty sure I know what’s the difference :wink: the .state method was just an example, I didn’t pay attention if you can actually use it with a thing :sweat_smile:

Let’s just say I meant:

Thing "mything:something:1".someMethod

err, no you wouldn’t. There seems to be some basic confusion here. It’s just myexampleItem

var someVariable = myexampleItem.state.toString

You don’t have to declare or introduce your Items to rules in any way, they are just automatically available by name as Item ‘objects’.

1 Like

@rossko57 thanks for your reply.
I guess there wass my mistake. Is it possible to do it the same way with things?

By the way:

Item "myexampleitem:something:1"

works if you use it in the “when” clause

So far as I know, you can only use Things in the rules language as rule triggers. And then only if that particular Thing supports triggering, no all do.

If you want to inspect data from a Thing within a rule, you would link an Item to one of its channels. This is what Items are for.

Hmmm…

There is no problem at all finding my thing in the trigger section. My thoughts were, that you doesn’t need an item for general informations like if a thing is online of offline. These are non channel specific informations…

1 Like

That helps, thank you :slight_smile:

Hopefully I didn’t come across as abrupt but there was definitely something misunderstood or confused on your part.

I don’t think you can access a Thing or its properties in the when part (happy to be corrected).

Having read your OP you mentioned that you wanted your device to be plug and play for the user. Are you expecting them to write the .rules file for their setup? As that doesn’t sound like a plug and play solution.

Hey @danielwalters86,

yeah I agree that I may explained it a little bit confusing (and may confused myselfe in the process :sweat_smile:)

I don’t think you can access a Thing or its properties in the when part (happy to be corrected).
Found out that you actually can. You can use the following:

getThingStatusInfo(String thingUID)

With this you can access all of status informations (may be not all informations a thing has, but better than nothing). However even if you can use it in the “when” - clause, it’s only usefull in the “then” - clause I guess. Never the less, I hope this information may help you in the future :slight_smile:

Having read your OP you mentioned that you wanted your device to be plug and play for the user. Are you expecting them to write the .rules file for their setup? As that doesn’t sound like a plug and play solution.

I try to do it as much Plug and Play as possible. The thing is, that my device is primary (not only) a controller with which you can control other devices connected to OH2. Due to the fact, that the device itselfe doesn’t know the other devices, the logic between my device and for example a hue lamp must be inside OH2. But this is another topic and shouldn’t be discussed here ^^