String to DateTime

Hi,

I am integrating my alarm to OpenHAB using a Python3 script as my Java knowledge is too limited to create an binding for it. I managed to get all info needed to OpenHAB, but I have a problem with DateTimes.

I tried to transfer the DateTime objects from the alarm system to OpenHAB with the OpenHAB Python3 class. This didn’t work, as it stated the item was null. Instead, I transfered it to OpenHAB as a String, which worked fine. I would however like to convert the string to a DateTime type, but I cannot get that to work.

The String object contains a DateTime in the format “2020-06-08T19:30:25.000Z”. According to the documentation that I found, that is a conversion of type 1.

I created a rule, as follows:

// Store arm state time as DateTime
rule "alarm_armstate_date_raw_to_datetime" when Item alarm_armstate_date_raw received update then
        logInfo("Alarmtest", "Start")
        val String sdate = alarm_armstate_date_raw.state
        logInfo("Alarmtest", sdate)
        val DateTimeType udate = DateTimeType.valueOf(sdate)
        alarm_armstate_date.postUpdate(udate)
end

However, that results in an error:
2020-06-09 14:00:04.629 [INFO ] [ipse.smarthome.model.script.Alarmtest] - Start
2020-06-09 14:00:04.632 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘alarm_armstate_date_raw_to_datetime’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

UPDATE: I forgot to add the item definitions:
String alarm_armstate_date_raw “Armtime raw” (alarmsystem)
DateTime alarm_armstate_date “Armtime” (alarmsystem)

Any suggestions?

Thank you in advance!

That’s a state object. logInfo() needs strings. Try
val String sdate = alarm_armstate_date_raw.state.toString

1 Like

Thank you!