How can I evaluate an Item change based on the source of the change? I have a Switch Item that can be changed either by a rule or manually in the sitemap. Is there an Item property that can be used as a condition in a rule? E.g. do not change the switch when it was switched manually.
The source of the event is on the event. In JS it’s event.source. Look in events.log to see what the source will look like. Sometimes the source will be a chain as an event goes from one part of the system to anotheeer (e.g. Thing → Item → rule → Item). So you may need to do some parsing of the source.
if(event.eventSource == 'org.openhab.ui=>org.openhab.core.io.rest$rich') {
// Item event came from a UI/REST API from user rich
}
… yeah, this is what I figured and my favorite LLM confirms:
Can I inspect the event source?
Not in Rule DSL.
The event bus internally knows whether an event came from REST, UI, a binding, etc., but that information is not exposed to Rule DSL triggers.
The LLM suggested solution is to work with postUpdate() vs. sendCommand() while the sitemap (manual) change triggers a sendCommand(). So in the RuleDSL trigger on the Item I can use
when
Item MySwitch received command
then
But this does not help to evaluate the state change source within a rule. So I’m supporting the PR as it addresses my needs.
The LLM is making stuff up. Changing the trigger type isn’t going to do anything for you in this context.
For now, you either need to use one of the other langauges, wait for the PR to get merged before addressing this requirement, or using ooooone of these much more complicated approaches described in Design Pattern: Manual Trigger Detection. the Proxy Item appraoch is the most full proof.
Why won’t using postUpdate help you here? Because it surves a completely different purpose. postUpdate will only update the state of the Item. But anything can update an Item so using postUpate doesn’t give you any additional information. And an update doesn’t cause the device to do anything. It only changes the Item’s state. You cannot turn on a light using postUpdate.
On the other side, sendCommand usually results in a follow on update. For example, if a command to turn on a light is sent, if the light isn’t already ON, following the command there will be an update and then a change event.
You can’t use any of this to determine where the event came from.
I got new release OH5.2.1 installed (docker) and added the following line to my DSL rule:
logError("ctx", "Ctx: {}", ctx.toString())
This leads to an error that “ctx” cannot be resolved. I searched through the OH documentation but cannot find any hint on how to use the context on a changing item. Any advice?
That PR will make it to 5.3 but not 5.2.x. It’s a new feature, not a bug fix, hence why it doesn’t get backported to 5.2.x. - I was wrong it got backported!
I can’t explain that. I just started a docker version of 5.2.1 to test, and when I literally copy the code that fails for you, I get this in the log:
15:08:21.649[ERROR] [org.openhab.core.model.script.ctx] - Ctx: {event=Execution triggered by manual, ruleUID=b585bb72be}
Are you sure that your docker is running 5.2.1?
I can explain this at least. The reason you can’t find it is that I haven’t written it yet. I was waiting for feedback from the maintainers about another DSL change, because I wanted to update the documentation for both changes in one go, but never got any, so the whole documentation of this has kind of stalled.
…yes, I do have docker container OH5.2.1 running. Can you share your full rule? Mine looks like this:
rule "Luefter2"
when
Item LuefterSwitch received command
then
logError("ctx", "Ctx: {}", ctx.toString())
end
and the error message is:
2026-08-12 20:38:21.522 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'wallbox-8' failed: The name 'ctx' cannot be resolved to an item or type; line 193, column 29, length 3 in wallbox
Is “ctx” an implicit function like “receivedCommand”? Or what is it?
Great, but where is the Source information? I thought I can get the source of the event through this? This switch can be changed manually from the sitemap or by a rule. How do I get that information?
I have shut down the VM and the docker container and all that, I could start it all up again, but all I did was to modify an existing rule by pasting your line verbatim. I then ran the rule manually from the UI. There was nothing special about the rule, it was just some other test rule I had there. Actually, now I remember that the other two lines in the rule were invalid (it was from a previous test of a different situation, that was invalid outside that test scenario), so I just commented out the other lines, leaving me with a rule with only “your” line. I don’t remember how the trigger was, but it doesn’t matter, as I ran it manually.
It’s an implicit variable, just like the others that were there already. I also added inputs and eventObject, so you should be able to find them as well:
No, now you only log the Item. If you want the source information, you should probably use eventObject directly. But, if these don’t exist in your installation, you can’t be running 5.2.1… I have no other explanation. There is no “qualifying logic” here, these are always inserted.
That is a genuine mystery; however, you didn’t show the bundle where this actually is, which is org.openhab.core.model.script.runtime. Wasn’t that bundle in your output?
edit: It’s probably not a “feature”, try bundle:list instead.
… with " logError(“eventObject”, “eventObject: {}”, eventObject)" I get an error too:
2026-08-12 21:10:08.937 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'wallbox-8' failed: The name 'eventObject' cannot be resolved to an item or type; line 194, column 45, length 11 in wallbox
and:
openhab> bundle:list | grep -i runtime
62 │ Active │ 80 │ 3.2.0.v201101311130 │ ANTLR Runtime
70 │ Active │ 80 │ 3.6.10 │ Apache CXF Runtime JAX-RS Frontend
73 │ Active │ 80 │ 3.6.10 │ Apache CXF Runtime Security functionality
74 │ Active │ 80 │ 3.6.10 │ Apache CXF Runtime HTTP Transport
104 │ Active │ 80 │ 3.20.300.v20251111-0312 │ Common Eclipse Runtime
140 │ Resolved │ 80 │ 2.43.0.v20260525-1205 │ Xtend Runtime Library
148 │ Active │ 80 │ 2.43.0.v20260525-1205 │ Xbase Runtime Library
178 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Console for OSGi runtime Karaf
202 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Model Items Runtime
206 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Model Persistence Runtime
209 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Model Rules Runtime
212 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Model Script Runtime
215 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Model Sitemap Runtime
218 │ Active │ 80 │ 5.2.1 │ openHAB Core :: Bundles :: Model Thing Runtime
295 │ Active │ 80 │ 25.0.1 │ GraalVM :: Truffle :: Runtime