Date Time

I give up…i’ve looked through countless entries here; none of them work.

I simple have a string item; let’s call it stringy
It is defined in my items file

All i want to do is assign it the current date and time something like now.GetDateTime
Or one of the other countless ways people are doing it here…which none of them work

17-10-09 19:43:26.469 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Test.rules’
2017-10-09 19:43:35.088 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Test Rule’: An error occured during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
2017-10-09 19:43:35.481 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Test Rule’: An error occured during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
2017-10-09 19:43:35.881 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Test Rule’: An error occured during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
2017-10-09 19:44:04.713 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'Test.rules’
2017-10-09 19:44:04.715 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Test.rules’ is either empty or cannot be parsed correctly!

2017-10-09 19:47:51.918 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Test Rule’: An error occured during the script execution: The name ‘datetimeitem’ cannot be resolved to an item or type.

You should have posted the rules you’re using.

val DateTime strDateTime = now
postUpdate(Garage4in1LastBattOrig, strDateTime)

An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

Essentially all i want to do for now, is get a current date and time and store it into an item(string, datetime, whatever type i am allowed to use).

Nothing i do seems to work

Garage4in1LastBattOrig.postUpdate(strDateTime.toString)

See

http://docs.openhab.org/configuration/rules-dsl.html#datetime-item

Why is strDateTime a String Item? A more typical usage would be to use a DateTime Item and you can populate it with:

Garage4in1LastBattOrig.postUpdate(new DateTimeType)

See

http://docs.openhab.org/configuration/items.html#state-presentation

for how to format the DateTime on your sitemap in a way you want.

The section above the first link I provided has a brief discussion of Type and how you need to convert between types to use certain types of objects to command an Item.

Thanks!
It’s actually defined as a datetime in the items file
DateTime Laundry4in1LastTempOrig “”

Now it’s saving the value to the item using what you suggested: Laundry4in1LastTempOrig.postUpdate(strDateTime.toString)

Result:
link "http://172.16.1.242:8080/rest/items/Laundry4in1LastTempOrig"
state “2017-10-10T11:34:19.571-04:00”

Question:
Am i going down a bad road. My goal is to now take this time and compare it later on in a rule.
Something like (pseudocode coming)

Every day at 8 AM
Compare this item(last updated date time) to now and if it’s >25 hours send me an email.
Will i successfully be able to compare this stored value to the current time and gauge if its > 25 hours old?

Trying to do this but it doesn’t work:

if((Laundry4in1LastTempOrig as DateTimeType).calendar.before(now.MinusHours(25))){
sendMail("xx@gmail.com", “greater than 25 hours”, “greater than 25 hours”)
} else {
sendMail("xx@gmail.com", “not greater than 25 hours”, “not greater than 25 hours”)
}

end

2017-10-10 11:44:58.860 [ERROR] [ssage.ApplicationCommandMessageClass] - Error processing frame: Message: class=ApplicationCommandHandler[0x04], type=Request[0x00], priority=High, dest=255, callback=0, payload=00 07 02 30 03 >> Attempt to read message payload out of bounds: Message: class=ApplicationCommandHandler[0x04], type=Request[0x00], priority=High, dest=255, callback=0, payload=00 07 02 30 03 (5)

My first link (which it doesn’t appear you clicked on yet) shows all the ways to compare and manipulate DateTimeType.

I also suggest you go through the Beginner’s Tutorial and the Rules documentation in its entirety. ESH Designer will also be of great help to you.

One accesses the State of an Item in rules using .state.

if((Laundry4in1LastTempOrig.state as DateTimeType)....

You would also benefit from reading some of the Design Patterns which show common ways to implement common problems like these.

Thanks!