getLocation or getEquipemt available?

Hi guys,

I have installed a new openhab3 instance and configured a complete semantic model.
For my window sensors, I have created an equipment “window” and linked the two points from the knx sensor to it. One point is for a tilted window, one for an opened window. I want to calcualte a status item for each window for the actual status as a string.
To use design patterns, my plan is to put each point in a group “tilted” or “opened”. If a member of these groups is changed the script calculates the new status. But therefore I want to know the equipment of the point that has changed. Only with this information I can find the right status variable.
I saw a Design Pattern example where this was solved with the help of the name. But I think with the semantic model of openhab3 it can be solved better?
Is something available like this?

If you are using the Item Registry you can get all the Items with a given tag and then filter those down to the one with the name you are looking for, but if you have that you may as well just pull the Item from the registry by name anyway.

Locations and Equipment are just regular old Groups. So you can get the list of all the Groups an Item belongs to and then pull it from the Item Registry. Then you can filter that list based on Item name, or tag, or type. But again, it’s not really “better” than just using a consistent naming scheme and accessing the Item by name in the first place.

Finally, I’ll mention that you may not even need the rule at all if all you are doing is showing the status on a page widget. When defining the icon and label for an Item on the page you can set an expression that checks the states of any of your Items, not just the Item being displayed. So you could configure it to show the open window Icon and say open if either of the sensors are OPEN.

Thank you for your response. I like your final idea, but as I understand this is only possible to display open or closed but not an additonal state like “tilted”?

You can display anything. If you want “cookie monster” for open and “chair” for closed you can do that.

=(items.MyOpenWindow.state == "OPEN" || items.MyTiltedWindow.state == "OPEN") ? "cookie monster" : "chair"

You can even nest the ternary operator to get more options:

=(items.MyOpenWindow.state == "OPEN" && items.MyTiltedWindow.state == "OPEN") ? "Both" : (items.MyOpenWindow.state == "OPEN" && items.MyTiltedWindow.state == "CLOSED") ? "Open" : (items.MyOpenWindow.state == "CLOSED" && items.MyTiltedWindow.state == "OPEN") ? "Tilted" : "Closed"

If you use one of the F7 icons, you can then have four different colors or four different icons and use a similar expression to choose between them.

See [Wiki] Building Pages in OH 3 - Item Customization on Auto Generated Pages for more details.

1 Like

Thank you. Your posts and community input is awesome. Thank you very much for your support

But one more question: do I understand right that I have to add the Code to all items and adjust each item Name? My general Idea was to have a global rule that does all calculations. Ist that possible without seperate items?

You can create a custom widget with properties where you can define the Items and anything else desired. That custom widget can be applied to any Item. See [Wiki] Building Pages in OH 3 - Custom User Defined Widgets for an example custom list widget.

So I can have a list of all windows status,but to have a single Item in each room, I have to create seperate items, or mit?

I don’t understand the question.

Let’s say you have a dozen windows that all appear in the various Location cards, for example. Each Window is represented by two Items, one for open and one for tilt. Then you can create a custom widget for your window with properties to define each window. Once defined, you can go to the Item and choose your new custom window from the list to use as the default widget, and set the properties for that particular window. Repeat for all the other windows, selecting your new custom widget as the one to use for the default list widget and setting the properties for the new window.

As shown at that link, I’ve created a custom list widget for my lights. I want all my lights to look and work the same in the automatically generated parts of MainUI. Once created I go to each of my light Items, choose “light_list_widget” as the widget type for that Item’s default list widget and enter in the text and Item name the widget controls. Now all my lights look and act the same. And if I want to change it later I just need to edit the custom widget and it will automatically apply to all the Items that use it.