-
-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Event-Bus
- ItemUpdatedEvent
to also trigger on metadata changes - or add new event like ItemMetadataUpdatedEvent
#4409
Comments
If it's configuration data for the rule, why do you need to trigger the rule to run when the configuration changes? You need to load the metadata when the rule runs anyway so the next time the rule runs it will get the new version of the metadata. I use this in a couple of my published rule templates on the marketplace. I don't quite understand your need for an event to trigger a rule in this case. |
If you check my rule - you can see it has a special coding path when the Configuration changes, in this case it prepares the groups and cleans up the groups it no longer watches. This is just one scenario where triggering a rule based on Metadata changes of an item can be useful. The request is not specific to configuration containing items, but just items in general and responding to Metadata changes - perhaps even go a little further and also allow subfiltering to the namespace you want - in my opinion this is a valid request in general, my example was just about a configuration item for a rule - but it can also be used for metadata on items which are used to set stuff like temperature etc. |
Adding a whole new set of events has performance and load impacts on the whole OH system. One needs to be careful about the impacts. Given that the vast majorioty of users would not use this event, is the overall impact low enought that it doesn't matter that the load is increased on their system? I can't answer that but I do want to make sure that it does get answered. If this is going to slow down people's MainUI or something like that the use case needs to be pretty compelling. Given there are other ways to accomplish what you've done without an event I personally don't find the use case to be that compelling, especially since there are several other approches to accomplish the same thing. But if the impact is overall really small then the use case doesn't have to be all that compelling. I'm not a developer so it's up to whom ever volunteers to implement it to decide if the use case is compelling enough to justify the amount of work it will take to implement. Some of the alternative approaches include:
I'm not saying this isn't a valid request. I'm just cautious that we don't go down some path that causes a huge impact to all users to solve a pretty niche problem with alternative solutions. |
It's not really a duplicate - as my feature request is about sending an event on the Event Bus when metadata changes - this can have all sorts of uses. But maybe, we need to introduce something new to OpenHAB as currently an item and it's metadata are misused for rule configuration - maybe In the case of the If a |
I agree I don't think it's a duplicate. The Item metadata doesn't need to be bound to the Item in those ways to generate an event on the bus when the metadata changes.
The term "misused" is a little loaded. What do you mean by misused? Most of us who use Item metadata for rule configuration do so such that the rule behaves different for each Item it processes. For example, I use Item metadata to encode the proxy Item and how long to debounce an Item's state for my Debounce rule tempalte. Moving that to a Rule Metadata doesn't make sense because it controls how that specific Item is processed. Any configuration of the rule over all is encoded in the rule itself or, in the case of rule tempaltes, through the properties filled out when instantiating the rule from the template. Soemtimes configuration can be done through libraries or loading a configuration file when the rule is loaded (mainly an option for file based rules). What are some of the use cases where the most appropriate way to configure a rule is to use Item metadata where the metadata isn't on a per Item configuration but for the whole rule? I'm not arguing against this, mind you, I just don't see it and I've done configuration of rules like this in OH for many years so have some experience to bring to bear. I would like to see a way to create and use templates that does not require one to publish it on the marketplace to install and use it. Not only would that improve the experience for the developers of templates but it is also quite useful in cases like this. |
Let me state In my example I have a run, which automatically creates groups based on the tags an item is tagged with - instead of doing it for all tags, I filter out the tags I want it to look for - as my rule comes from a file - I want this configuration to be inside the UI side somehow, so I let the rule create and manage an Item which contains it's configuration - but if I change this items configuration (metadata) I want the rule to run, for example when I remove a tag from the configuration the rule needs to be triggered to clean up the group it created for that tag. Maybe using a rule for this is wrong, I don't know, but I don't know of a different way to add logic to OpenHAB except perhaps creating an addon. Maybe the solution I am looking for is what But still, adding a way to listen for Metadata changes could also help - as my next project I am gonna try to create something like https://community.openhab.org/t/timeline-picker-to-setup-heating-light-and-so-on/55564 - but then store the schedule per item in its metadata - would be great if the metadata gets updated that also a rule could be triggered to for example change the temperature if needed. The documentation states one can define extra EventTypes - so maybe I could take a look to see if I can listen for metadata changes on the MetadataRegistry and create an addon which sends the events I want - that way it's |
What are these Groups used for? I would use the tags themselves probably instead of Groups, though without knowing how the Groups are used 🤷♂️ . For an example, in the past I've had rule generators which trigger based on system started and a switch Item. If I change the configuration (e.g. add some tags to some Items) I'd command the switch which triggers the rule which deletes the old rule and recreated it anew using the tag to identify those Items for which triggers should be created. Today that might not even need to be done; there might be a way to adjust the triggers of a rule dynamically. Sure, you need to remember to manually trigger the rule to process the changes, but if these changes are somewhat disruptive you'd probably want to do that once for many changes anyway, instead of processing the changes one at a time.
That's simple enough. Create a function that creates a rule based on the arguments passed to the function. There is nothing really special about the data one passes to JSRule. For example,
Put this in a personal library and there's little you can't do along these lines. All UI rule tempaltes do is have a "find and replace" operation to replace It's up to you to figure out when to call the above rule, in response to an event or a manually run rule or based on a cron. Again, I'm not arguing against a MetadataChanged event, but from what I can see what's driving this request is a little niche as well as potentially an XY Problem.
I'm pretty sure that's for creating Event Channels on a Thing, not creating new core events. You'll need to modify core to add a new event and modify the Item Metadata Registry to emit this event. |
These are used to setup the
So you've got a rule which creates other rules when triggered? How did you setup the triggers? Did you manually add each item as trigger to the rule? Or create a rule per item?
You're perhaps right, but I just mentioned one thing, of course there are more examples out there - for example, if I store the schedule for an item inside the metadata, if I change this schedule having the item update accordingly to the new schedule would also need MetadataChanged event - or like you said before, manually trigger a rule or script to update all items based on their schedule. But thanks for the insight into the Rule Generators - this is something I am going to explore more and can help a lot! |
See the example code above. I create all the triggers for the one rule.
Given that there is a Now one thing that would be nice in that case would be to do something like a |
This is a great suggestion, then there's no need to store it inside the Metadata but you can create a hierarchy of items/groups to store it instead - also I forgot about the |
Your Environment
It would be great if one can use the
triggers.GenericEventTrigger
in the Javascript library to also trigger when an items metadata gets updated - or by usingItemUpdatedEvent
or a new event likeItemMetadataUpdatedEvent
on a topic ofopenhab/items/*/metadata/updated
oropenhab/items/*/updated/metadata
As to why, I am storing information inside metadata to configure my rules - this way it's cached but also accessible from the UI instead of relying on the caching functionality. (See below rule, compiled from Typescript to Javascript for an example, it uses an item to store configuration for the Rule as I couldn't think of another way to do this and have it available from the UI for editing)
Example Rule: Typescript
Example Rule: Compiled Javascript (EsBuild with custom plugin)
The text was updated successfully, but these errors were encountered: