How do I filter on a specific icon category in a js script similar to filtering on tags? For example, see the filter below to get the lights via the location. Now I would like to find the door sensor in the same location. I need the filter to check that it has a category ‘door’ and then I can check to see if it has tags with OpenState and Status.
var location = items.getItem(actions.Semantics.getLocation(items[event.itemName]).name);
var lights = location.members.filter(i => i.tags.includes("Lightbulb"));
I’m trying to use the semantic model and identify the door status in my rule (keep the lights on in a room if the door is closed when motion ends). If I put a tag on the door sensor, I can search for ‘Door’ above and it works. But that doesn’t seem to fit the semantic model. This is a door sensor, not a door equipment that can be operated. So it seems it should be a point with a property. But then I need to search and find the point which has the door icon label. Is there a better way to approach this?
You can’t, directly. The icon is not exposed directly through JS. However, you can get at it through the rawItem. Just be aware that you are dealing with Java at that point. A Java String is not a JS String so you have to be very careful you understand what types you are working with at any given time.
items.MyDoorItem.rawItem.getCategory(); // returns a Java String
But I think it’s an XY Problem because you can, and probably should do this through the semantic model. You are already using the semantic model to get the location. With the location you can get all the “Door” equipment and then get the OpenState Point Items from those.
That’s one of the ways the semantic model becomes powerful in rules.
An equipment can be just sensors. An equipment can be made up of only one sensor even. There is nothing special about an equipment that says it must have both sensors and actuators and a bunch of both to qualify. If you want to use the semantic model for this, putting the contacts into a door equipment would be the way to do it.
But as I showed above, you could use the category too. Or you can create your own new tag. Or use the name or label of the Item. Or use a non-semantic Group Item. There are lots of ways to solve this. But if you want to stick with the semantic model, you need to create door equipment.