JS Scripting using the GenericEventTrigger and ItemAddedEvent

Is there a way to use the ItemAddedEvent from the GenericEventTrigger in JS? I do not see a way in the documentation to capture these events?


I don’t know about file based rules but it should be possible using the UI. I would expect it to look something like:

  - id: "3"
    label: An Item was Added
    description: Triggers when any Item is added to OH
      types: ItemAddedEvent
      payload: ""
      topic: openhab/iterms/**
      source: ""
    type: core.GenericEventTrigger

I don’t know what the payload looks like but suspect it has at least the name of the Item added. You should be able to limit the trigger to just the Item in question through the topic (e.g. openhab/items/MyItem/added).

The GenericEventTrigger is mostly intended to be used by developers of helper libraries and the like so I am not surprised that openhab-js does not expose it. You could look a the triggers code in the library and see how to interact with the raw Java API in your rule to create a generic event trigger.

Note, if you are using .items files, you will get ItemAddedEvents every time the file containing that Item is loaded/reloaded.

I have this working, submitted a PR to add this to the triggers.js module.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.