Set item DateTimeType minus mintues

datetimetype
Tags: #<Tag:0x00007fd3127f6e20>

(Ahiel) #1

Hello,
How can I set item data as DateTimeType - 10 minutes?
I’m using now the item.postUpdate(new DateTimeType) but I need to set the time -10 mintues (I’m using it to know when I’m living home - no ping for 10 minutes, I want to update the item to -10 minutes)

Thanks?


(Sascha Billian) #2
MyItem.postUpdate(now.minusMinutes(10))

(Ahiel) #3

But it is not DateTimeType and it is not recommended to use it as far as I remember, am I wrong?


(Sascha Billian) #4

Oh, sorry. I didn’t note that the types are differen. The following article shows some possibilities to convert Joda DateTime to DateTimeType. Maybe it helps:


(Ahiel) #5

Thank look like it is not updated.
The constructor DateTimeType(Calendar) is deprecated


(Vincent Regaud) #6

@Ahiel


(Ahiel) #7

So the right way to do it is:
MyItem.postUpdate(now.minusMinutes(10))
Or
MyItem.postUpdate(now.minusMinutes(10).toString)
?


(Vincent Regaud) #8

First one


(Ahiel) #9

MyItem.postUpdate(now.minusMinutes(10))

I’m getting:

[ERROR] [.model.rule.runtime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘Initialize variables’: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,org.eclipse.smarthome.core.types.State) on instance: null


(Vincent Regaud) #10

How did you create you item?


(Ahiel) #11

DateTime MyItem “leave home at [%1$tm/%1$td %1$tH:%1$tM]”