Ephemeris datetime parameter

Tags: #<Tag:0x00007f432e6d5f38>

Openhab version 2.5

According to the docs you can use Ephemeris with a Joda DateTime parameter.
For example isWeekend(<datetime>), but when I do the follow:

logInfo("test",Ephemeris.isWeekend(now.plusDays(1)).toString)

I get the following error:
Could not invoke method: org.eclipse.smarthome.model.script.actions.Ephemeris.isWeekend(int) on instance: null

What it tells me that it expects a int instead of a Joda DateTime.

But other methods with DateTime give another error, such as getDaysUntil(<datetime>, <holiday name>)
Example:

logInfo("test",Ephemeris.getDaysUntil(now.plusDays(300),"CHRISTMAS").toString)

This gives the error: Could not invoke method: org.eclipse.smarthome.model.script.actions.Ephemeris.getDaysUntil(java.lang.String,java.lang.String) on instance: null
Here it expects a String parameter instead of a Joda DateTime.

Do I something wrong?

2.5 release? The DateTime versions of these Actions were added pretty close to the release so if you are on an older milestone release those methods may not be there.

You don’t say which Rules engine you are using. If you are using Rules DSL, which is implied by your logInfos, than you would just call the method without Ephemeris in front of it.

isWeekend(now.plusDays(1))

Only in Scripted Automation do you need to import and use the Ephemeris Object to access the methods.

I was using 2.5 stable version, just updated to 2.5.1.
I use indeed the Rules DSL, I didn’t no I could call the method without Ephemeris. I misread the docs

Scripted Automation

One must import the Ephemeris Action and then call the above functions using Ephemeris.<function> , for example Ephemeris.getNextBankHoliday() .

Anyhow, even with version 2.5.1 and without Ephemeris it doesn’t work.

This gives the error:

Could not invoke method: org.eclipse.smarthome.model.script.actions.Ephemeris.isWeekend(int) on instance: null

Even VSCode gives this warning:

Type mismatch: cannot convert from DateTime to int

Is this a bug or am I really do something wrong?

“Scripted Automation” is what will be the replacement for Rules DSL. It’s coding Rules using Python instead of a custom language.

It’s probably a bug. I wrote the docs to the code but didn’t have opportunity to test out all the methods. File an issue at openhab-core. See How to file an Issue.

Thanks, I’ve filed an issue

Joda will be removed in OH 3.0 and there are no planned releases of openHAB core before OH 3.0, so this is not likely to be implemented and the docs should be updated to reflect the current functionality. The ephemeris Action does not even import org.joda.time.DateTime. Check the methods though. You can use an int offset or a ZonedDateTime, which is probably what you’re after.

from core.actions import Ephemeris
LOG.warn(Ephemeris.isWeekend(DateTimeType().zonedDateTime.plusDays(1)))

For the DSL, it should be something like this…

logWarn("Rules", isWeekend(new DateTimeType().zonedDateTime.plusDays(1)).toString())

Ah, so I’ve to use a DateTimeType instead of JodaTime.
That means that I can use it also this was
logWarn("Rules", isWeekend(new DateTimeType(now.plusDays(1).toString))

No, that won’t work since it is using a DateTimeType as the argument where the ephemeris Action requires a ZonedDateTime. Actually, this has more issues than just that. Use the DSL example I gave you… it was missing a toString, but I’ve updated it.