[SOLVED] Rules based on Thing Status Action not fired

My „Thing status” rules using Thing Status Action to get the online/offline status of a Thing seem not be fired reliably after upgrading to 2.4 release. That means e.g. after OH restart many of my thing status related items I switch with the rule show value “OFF(LINE)” although the related thing in paper UI (Configuration>Things) show ONLINE. Especially Hue things and Alexa things are affected. With 2.3 I had no issues.
I use rules based on documented Thing Status Action example, e.g.

    rule "Switch Hue Bridge status"
        when
    	    Thing "hue:bridge:001788665b6a" changed
        then
            var thingStatusInfo = getThingStatusInfo("hue:bridge:001788665b6a")
            if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
                PhilipsHue_Bridge_Status.postUpdate(ON)
                logInfo("philipshue", "Bridge status ON: " + thingStatusInfo.getStatus().toString())
            }
            else {
                PhilipsHue_Bridge_Status.postUpdate(OFF)
                logInfo("philipshue", "Bridge status OFF: " + thingStatusInfo.getStatus().toString())
            }
    end

Checking OH logs (event.log/openhab.log) for this example
during OH shutdown:

    2019-01-19 08:00:17.686 [hingStatusInfoChangedEvent] - 'hue:bridge:001788665b6a' changed from ONLINE to UNINITIALIZED
    2019-01-19 08:00:17.759 [hingStatusInfoChangedEvent] - 'hue:bridge:001788665b6a' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
    2019-01-19 08:00:17.942 [vent.ItemStateChangedEvent] - PhilipsHue_Bridge_Status changed from ON to OFF
    2019-01-19 08:00:17.948 [INFO ] [se.smarthome.model.script.philipshue] - Bridge status OFF: UNINITIALIZED

during OH startup:

    2019-01-19 08:54:38.781 [vent.ItemStateChangedEvent] - PhilipsHue_Bridge_Status changed from NULL to OFF
    2019-01-19 08:55:01.268 [home.event.InboxAddedEvent] - Discovery Result with UID 'hue:bridge:001788665b6a' has been added.
    2019-01-19 08:55:05.112 [me.event.InboxRemovedEvent] - Discovery Result with UID 'hue:bridge:001788665b6a' has been removed.
    2019-01-19 08:55:05.189 [hingStatusInfoChangedEvent] - 'hue:bridge:001788665b6a' changed from UNINITIALIZED to INITIALIZING
    2019-01-19 08:55:16.259 [me.event.ThingUpdatedEvent] - Thing 'hue:bridge:001788665b6a' has been updated.
    2019-01-19 08:55:16.261 [hingStatusInfoChangedEvent] - 'hue:bridge:001788665b6a' changed from INITIALIZING to ONLINE

It seems that the rule was fired during shutdown when thing changed from ONLINE to UNINITIALIZED, but was not fired during startup.

Would be very grateful for any help.

Thanks,
Andy

Check when the rules file was loaded in openhab.log

rule "Switch Hue Bridge status"
    when
	    Thing "hue:bridge:001788665b6a" changed
         or System started // <------------------
    then
        var thingStatusInfo = getThingStatusInfo("hue:bridge:001788665b6a")
        if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
            PhilipsHue_Bridge_Status.postUpdate(ON)
            logInfo("philipshue", "Bridge status ON: " + thingStatusInfo.getStatus().toString())
        }
        else {
            PhilipsHue_Bridge_Status.postUpdate(OFF)
            logInfo("philipshue", "Bridge status OFF: " + thingStatusInfo.getStatus().toString())
        }
end

@rossko57 – good hint: rules file was loaded AFTER the thing was set to ONLINE.
@luckymallari – your proposal did the trick, now its working fine.

Thank you both,
Andy

You can mark it solved :slight_smile: