Select elements in rule using filters / queries #318
Replies: 2 comments 1 reply
-
I’m guessing a bit as to how you are using the above code but just wanted to explain the usual way of doing things. Ordinarily you have a lights off image of your whole floorplan and then have separate SVG or PNG for the light on indication. So all you need to do is show or hide the light on image based on the state of the entity. I am not sure why you think you need to access the Inkscape labels as they can be the same as the ID (and mine usually are) so I don’t know why you would need one over the other. Rather than trying to discern patterns in the labels if I have a complex series of events I want to run on a state change or tap action I just call a script. |
Beta Was this translation helpful? Give feedback.
-
I like the idea here, but couldn't you just re-use a function or a rule, or similar? It's for sure not the same.. But I mean.. It's something. Creating a general rule would also open up the discussion about how the entities and elements should be mapped, what statements should be pushed, and similar things. The idea is good, and should limit the code-duplication a lot, but, I feel there's too many cases where it wouldn't fit that well :) We're always open for ideas, suggestions and pull requests btw., so keep them coming. I won't look info this, but as states, it sounds like a useful thing - also for more "basic"-knowledge users. Personally I would be very worried about functions growing very large and bulky, and very hard to manage, cause it's living in a YAML-context (for most users, at least) 😄 . |
Beta Was this translation helpful? Give feedback.
-
Hi,
first of all, thanks for the amazing work. I'm quite new to HA and floorplan, I might miss some features already available..
I tend to overengineer things :) and I'm currently trying to minimize the effort in creating the floorplan yaml, specifically by exploiting the svg attributes.
As we know, currently the fastest/easiest way to map entities is by using the entity id in a svg node.
I was wondering if you would consider the possibility of extending the rule configuration with something like "filterElements" and "filterEntities", as an alternative to the "elements" and "entities" attribute; these would allow to specify a filter function to select elements/entities instead of a list of IDs.
This would open to a lot of possibilities to tinkerers/power-users, in a similar fashion of what the custom functions do.
One example: map elements via inkscape labels instead of IDs.
In inkscape, labels are quickly editable in the "Layers and Objects" tools; you can quickly create a model like this:
with this kind of structure:
that could be reused in different rooms:
and with a bit of fantasy if could be possible to create a single function that interacts with all the common elements of a room (send valetudo bot, open/close curtains, turn on/off main light) just by using some patterns in the labels.
I'm already doing something similar, but it oviously uses IDs and imho it is quite redundant:
Ideally the filterElements could support CSS query syntax, to be able to define something like
"filterElements: [inkscape:label='studio']"
, but i believe that would be more complex to do, depending on libraries available in ha-floorplan, while enabling the direct use of Array.filter should be quite straightforward since it is already there in the initGetEntityRule* methods in floorplan-elements.ts.Thanks for listening to my rant :)
Beta Was this translation helpful? Give feedback.
All reactions