I am experiencing a similar issue to this. It seems the cause in my case is when I edited an item in my .items file and wrote a wrong syntax, the item will be unloaded from openhab, and the link to the channel is removed.
Then after I fixed the syntax error and saved the .items file, openhab will recreate the item, and re-link it to the channel. At this time, I will receive an update “item XX changed from NULL to YY” with YY being the actual value held by the thing’s channel, prior to the item deletion above.
My trigger type is “received update” so I cannot just change it to a specific “changed from X to Y” as suggested.
My current workaround, as ugly as it may be, and it’s in jython, is to change my trigger type from “received update” to “changed”. This is done purely so I have access to “event.oldItemState”.
# If the new / current state is NULL, just return
if isinstance(event.itemState, UnDefType):
###### This part is purely because I want a "received update" trigger, not "changed" trigger
state = event.itemState.toString()
if state == '' or event.oldItemState.toString() != '':
###### end of "received update" hack
# This is the KEY: if the oldItemState == NULL then just return
if isinstance(event.oldItemState, UnDefType):
In this case, every time I received an update, I would read the state value and then update the item’s value to a blank string. This would ensure that I would keep receiving “changed” event, even though the item received updates of the same value, e.g. “click”, “click”, “click”, which was originally caught by the “received update” trigger. This approach would not work if you do not wish to do this.
I hope there’s a better solution to this. Specifically, if “event.oldItemState” can be made available in “received update” events, then I won’t have to resort to updating the item state to an empty string.
Note that in RulesDSL this is called
previousState but afaik it only applies to “changed” triggers