Item last update using JSR223 Jython (openHAB2 2.2)

Hi there!

Would you like to help a NOOB?

I have persistence set up and working.

I just like to find out an items last update using JSR223 Jython on openHAB2 2.2
Nothing fancy. Just like to retrieve the date.

Can the following script easily be modified:

scriptExtension.importPreset("RuleSimple")
scriptExtension.importPreset("RuleSupport")

class MyRule(SimpleRule):
    def __init__(self):
        self.triggers = [
             Trigger("MyTrigger", "core.ItemStateUpdateTrigger", 
                    Configuration({ "itemName": "TestString1"}))
        ]
        
    def execute(self, module, input):
        item = ir.getItem("A580IP")
        # Here... what to do to get the items last update time?????


automationManager.addRule(MyRule())

Just the way that I do in the following Xtend script which works great:

rule "Test"
when
    Time cron "0/15 * * * * ?"
then
    var String Timestamp = Bathroom_Door.lastUpdate.toDateTime.toString("yyyy-MM-dd HH:mm:ss")
    if (!Bathroom_Door.updatedSince(now.minusSeconds(90))) {
        logInfo("Bathroom_Door", "Bathroom door was opened : " + Timestamp)
    }
end

I appreciate your kind help!!! Cheers!

Edit: I hope it doesn’t matter what kind of persistence service I’ve setup. But in case it does, I’ve set up InfluxDB (v 1.0) Persistence.

Hi guys. The answer to my question, the following should work:

scriptExtension.importPreset("RuleSimple")
scriptExtension.importPreset("RuleSupport")
from org.eclipse.smarthome.model.persistence.extensions import PersistenceExtensions
from org.slf4j import LoggerFactory

class MyRule(SimpleRule):
    def __init__(self):
        self.triggers = [
             Trigger("MyTrigger", "core.ItemStateUpdateTrigger", 
                    Configuration({ "itemName": "TestString1"}))
        ]

    def execute(self, module, input):
        item = ir.getItem("A580IP")
        mystring = str(PersistenceExtensions.lastUpdate(item))
        LoggerFactory.getLogger("org.eclipse.smarthome.automation.examples").info(mystring)

Cheers!