Get status in "Thing received update" rule

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: Latest raspbian
    • Java Runtime Environment: 11.0.12, Zulu
    • openHAB version: 3.1.0

I have a rule that listens for Tradfri Scene button presses:

rule "Shortcut Button"
when
    Thing "tradfri:0820:[gw-id]:65586" received update
then
    logInfo("tradfri", "pressed")
    // Do other stuff, e.g. set scene based on current scene
end

However this rule isn’t just triggered on button presses, but also when the gateway refreshes its config and therefore the button is not ONLINE, but UNKNOWN for a short moment. How do I get the status that is sent on button presses?

I don’t see any “Thing ‘tradfri:0820:[gw-id]:65575’ changed from […]” when the button is pressed in the log.

In the first place I’d trigger upon an Item rather than the Thing. That would remove a need to distinguish inside the rule. I don’t know Tadfri but possibly there’s also a channel trigger ?

Or you might be able to retrieve the thing status.
You can use ScriptServiceUtil.getItemRegistry.getItem(<name>) to access the item by name and I think a similar possibility exists for Things. Don’t know code off the top of my head but I think have seen it on the forum.

I don’t think it’s possible as I can only see channels for battery:

There’s also an open feature request, so I guess this is only working “by accident”: [tradfri] Support for new IKEA Scene button in Tradfri product lineup · Issue #9953 · openhab/openhab-addons · GitHub

Probably so. Items yes but a thing is not meant to change its status after all.