Rule with "Thing ... changed from ... to ..." does not compile for ON/OFF state - why?

Hi,

I just started to dive into the DSL language and connecting my first devices. In fact it’s a Homematic switch with some shelly boxes.

I wanted to create a rule with a Thing identifier like this

[...]
when
    Thing "homematic:HmIP-WRC6:3014F711A0001F9D8989ADD2:000B5BE99F6BF2:1#PRESS_SHORT" changed from OFF to ON
then
[...]

However, this file produces an error “no viable alternative at input ‘OFF’”, so it looks like the constant names ON and OFF are not recognized?
This is strange, because if I use instead an “Item” trigger, openhab perfectly understands “[…] changed from OFF to ON”. I also tried to put it in double quotes, but still the same problem. Obviously in the background some enumerations seem to be in place, but I cannot find any hint how to use it in the Thing context.

OFF and ON are only states that an Item can have. They do not apply to a thing. Things statuses are a different list. See here:

1 Like

Okay, thanks, got it. As a newbie I still stumble across the difference of things and items, so I need to read more frontup.
Right now I feel a little uncomfortable with the concept, that all item names seem to reside in the same - flat - namespace, so once you really get a larger number of items, e.g. one must apply some meaningfull naming convention (I suppose) in order not to get screwed up with the clearness of item names. Maybe something like hungarian notation ,-) This also explains to me now, why Item names are immutable, once created.

Thanks for the quick answer!
Soeren

This was 100% true in the older versions of OH. I’d say it’s still good practice, but with the new MainUI, most of the places where you might be searching for an item name, you can also search by the item label. There’s also the developer side bar which gives you access to a quick search function on any page of the UI so you can quick lookup exactly what that item name was. These two new features do take a little of the pressure off of any comprehensive naming scheme. Nonetheless, for anyone who is going to do a lot of work with scripting and/or widgets a good naming convention is still a timesaver.

There are any number of breakdowns that try to help make this distinction clear both in the docs and if you search the forums. But the most simple, I find, is:

  • A thing is OH’s representation of a single piece of hardware or a service. This is usually going to include lots of different data types to fully capture the thing’s function or current status. Each of these different data line are the thing’s channels.
  • An item is one quantum of OH information. Usually these are read/write (although some, like the Contact type, are read only by default) and are therefore how the user interacts with OH. Items can stand alone (often referred to as Proxy items) in order to hold some useful variable for a rule or widget. But items can also be linked to the channels of a thing meaning the quantum of information in that item now represents one of the many different data points of that thing. Depending on how the channel is configured (often by the binding for the thing but sometimes by the user) that link can send the item’s information to the thing, receive the thing's info into the item, or, most often both.
2 Likes

Hi Justin,

very helpful explanation - quite the difference in a nutshell. Actually I am targeting a middle sized installation, I suppose we’ll end up with about 600~700 things at the end. So I need to get back to school for a day or so and do some more concept work.
I noticed the search bars already, they are quite helpfull. Also made contact already with the VScode extension which also provides some nice helpers for DSL coding. Those tools ease in fact the “flat namespace” issue. So I think after some time, I’ll get used to openHAB specific things ,-))

Regards,
Soeren