DateTime with plusMinutes. Or how do i add some extra (variable) time to the clock?

474 views
Skip to first unread message

Rumle

unread,
Dec 29, 2014, 12:07:57 PM12/29/14
to ope...@googlegroups.com

Hi. I am trying to show a DateTime, some (variable) minutes from the current time. As this is my first OpenHAB project, I am struggling a bit.

My question: I would like to add 10 minutes to the current time, and display the clock with these added minutes . I have been trying with the following.

 ITEMS
DateTime SystemTime "Current time [%1$tT %1$tA, %1$td.%1$tm.%1$tY]"
DateTime PlusTime "Plus time [%1$tT %1$tA, %1$td.%1$tm.%1$tY]" 


RULES
rule "Get System time, and add some minutes"
when
Time cron "* * * * * ?"
then
postUpdate(SystemTime, new DateTimeType())
PlusTime = SystemTime.plusMinutes(10)
postUpdate(PlusTime, new DateTimeType())
end

The SystemTime shows just fine, but i get nothing on the PlusTime. I get the error "Couldn't resolve reference to JvmIdentifiableElement 'plusMinutes'." so obviously this is not a valid method.

Can anyone point me in the right direction?

Ben Jones

unread,
Dec 29, 2014, 2:59:40 PM12/29/14
to ope...@googlegroups.com
Try this;

postUpdate(PlusTime, now.plusMinutes(10))

Rumle

unread,
Dec 29, 2014, 4:52:05 PM12/29/14
to ope...@googlegroups.com
Thanks Ben.

Unfortunately your suggestions leaves me with another error. This time: "Incompatible types. Expected java.lang.Number but was org.joda.time.DateTime". 

Any ideas?


Martin Klimke

unread,
Dec 29, 2014, 11:24:29 PM12/29/14
to ope...@googlegroups.com

PlusTime.postUpdate(new DateTimeType(""SystemTime.plusMinutes(10)))

Rumle

unread,
Dec 30, 2014, 11:44:17 AM12/30/14
to ope...@googlegroups.com
Thanks Martin.

Your suggestion brings me back to my initial errror: "Couldn't resolve reference to JvmIdentifiableElement 'plusMinutes'."

Could it be some import I am missing? Right now it looks like this:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*



Martin Klimke

unread,
Dec 30, 2014, 11:06:22 PM12/30/14
to ope...@googlegroups.com
I have imported the following 

import org.openhab.core.library.types.*

import org.openhab.core.persistence.*

import org.openhab.model.script.actions.*

import org.openhab.library.tel.types.CallType

import org.openhab.core.transform.actions.Transformation

import org.joda.time.*

import java.lang.Double

import java.lang.Math.*

import java.util.Date


I guess the last could be crucial.

But since there is hardly any documentation, it is always an trial and error to get it working.

Rumle

unread,
Jan 2, 2015, 2:57:28 PM1/2/15
to ope...@googlegroups.com
Hi again.

I finally got it working, using a mix of what Ben and Martin suggested, and a lot of "trial and error". The line that is working is:


postUpdate(PlusTime,new DateTimeType("" + now.plusMinutes(10)))


This gives me a clock 10 minutes ahead of time.

 

Wow, coming from arduino (and not being a programmer) this is more difficult than expected, as there is very little documentation, and no official example collection.

 

So thanks a lot for the help guys.Most appreciated.



Reply all
Reply to author
Forward
0 new messages