[Deprecated] Design Pattern: Time Of Day

Bindings can supply default state descriptions to linked Items; there’s probably nothing sinister about different display formats for linked against unlinked Items.
If you needed a pretty user-facing UI display, you’d probably set your own Item state descriptions anyway.

I moved my openhab installation from an x86 server to a raspberry pi. I use the backup and restore script to move the files.

Whenever i run the javascript ‘ephemTimeOfDay’ rule, i get warning messages,

2021-06-20 21:16:47.307 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de.jollyday.impl.DefaultHolidayManager cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 21:16:47.316 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de.jollyday.datasource.impl.XmlFileDataSource cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 21:16:47.338 [WARN ] [de.jollyday.util.XMLUtil            ] - Could not create JAXB context using the current threads context classloader. Falling back to ObjectFactory class classloader.
2021-06-20 21:16:47.452 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de.jollyday.parser.impl.FixedParser cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 21:16:47.460 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de.jollyday.parser.impl.ChristianHolidayParser cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 21:16:47.463 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de.jollyday.parser.impl.IslamicHolidayParser cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 21:16:47.541 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Today is a default day.
2021-06-20 21:17:18.527 [INFO ] [openhab.model.script.Rules.TimeOfDay] - The current time of day is EVENING
# java --version
openjdk 11.0.11 2021-04-20 LTS
OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS)
OpenJDK Client VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)

Any idea what could be the issue?

I doubt this would be caused by a configuration problem but to be sure check any custom ephemeris configs you have for corruption or weirdness.

Beyond the obvious, that it can’t find Jolly Day, I have no idea what could be the problem. If you are running the latest milestone or SNAPSHOT you should file an issue on openhab-core. If not you should try it out with the latest milestone or SNAPSHOT and see if the problem still persists. I can’t think of any way any configuration change you’ve made would cause this.

I dont have any custom ephemeris. The error message seems to trigger on startup. The log file shows that the TimeOfDay rule has been working fine since startup (more than 24 hours).

2021-06-20 23:11:41.127 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel
2021-06-20 23:11:42.710 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2021-06-20 23:11:46.170 [INFO ] [zwave.handler.ZWaveControllerHandler] - Attempting to add listener when controller is null
2021-06-20 23:11:51.349 [INFO ] [ve.internal.protocol.ZWaveController] - Starting ZWave controller
2021-06-20 23:11:51.351 [INFO ] [ve.internal.protocol.ZWaveController] - ZWave timeout is set to 5000ms. Soft reset is false.
2021-06-20 23:12:34.749 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de
.jollyday.impl.DefaultHolidayManager cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 23:12:34.763 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de
.jollyday.datasource.impl.XmlFileDataSource cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 23:12:34.783 [WARN ] [de.jollyday.util.XMLUtil            ] - Could not create JAXB context using the current threads context classloader. Falling back to ObjectFactory class
classloader.
2021-06-20 23:12:34.905 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de
.jollyday.parser.impl.FixedParser cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 23:12:34.912 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de
.jollyday.parser.impl.ChristianHolidayParser cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 23:12:34.916 [WARN ] [de.jollyday.util.ClassLoadingUtil   ] - Could not load class with current threads context classloader. Using default. Reason: ClassNotFoundException: de
.jollyday.parser.impl.IslamicHolidayParser cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.9
2021-06-20 23:12:34.996 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Today is a default day.
2021-06-20 23:13:06.018 [INFO ] [openhab.model.script.Rules.TimeOfDay] - The current time of day is BED
2021-06-20 23:30:00.024 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Transitioning Time of Day from BED to NIGHT
2021-06-21 00:00:30.221 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Today is a default day.
2021-06-21 00:00:30.362 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Moved Default_Morning to today.
2021-06-21 00:00:30.381 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Moved Default_Bed to today.
2021-06-21 00:00:30.427 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Moved Default_Night to today.
2021-06-21 00:01:00.578 [INFO ] [openhab.model.script.Rules.TimeOfDay] - The current time of day is NIGHT
2021-06-21 00:01:00.683 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Today is a default day.
2021-06-21 00:01:30.708 [INFO ] [openhab.model.script.Rules.TimeOfDay] - The current time of day is NIGHT
2021-06-21 05:00:00.002 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Transitioning Time of Day from NIGHT to MORNING
2021-06-21 05:56:00.002 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Transitioning Time of Day from MORNING to DAY
2021-06-21 10:53:56.777 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'livingroom.rules'
2021-06-21 18:46:00.002 [INFO ] [openhab.model.script.Rules.TimeOfDay] - Transitioning Time of Day from DAY to EVENING

I am running openhab 3.0.2-1 which is latest stable.

Your problems have nothing to do with the rule examples this thread is about.

This line, as a “global” definition -

populates your CurrentTime variable with a value only once, at rules file load time.
So far as I can see, you never update it, so yes it will stay the same.
This behaviour has not changed since OH2.
Wouldn’t you be interested in “now” at the time the rule runs?

When you’re ready, you might show us those.

I don’t know what your Zwave problems are about, but not related to this rule.

But it isn’t. It’s populated when the xxx.rules file is loaded. You’ve placed it outside of your rule.

See also

Quick question.
Would an Item that is already defined with { etod="MORNING"[type="default"] } be the same as the API where:

Namespace = etod

{
  "value": "MORNING",
  "config": {
    "type": "default"
  }
}

? One of my day-types isn’t happening so I wonder if it is the metadata that is wrong and would like to update it via the api…

That metadata doesn’t look wrong but it’s hard to tell by just looking at the JSON like that.

If the metadata is present but not well formed then the rule will complain about that.

You can see which Items are being considered by the rule by turning up the logging to DEBUG when it runs. It will list all the Items it’s using for the day.

If you don’t get any errors and you don’t see your Item in the debug logs then for some reason the rule doesn’t see that Item at all. If you see errors then the error should tell you what’s wrong.

Oh I get it now… thanks :slight_smile:

I’m trying to get the javascript version running on my OH3.1 system. But when executing the script imported from ephemTimeOfDay.yml io get this error in openhab.log:

2021-07-18 11:23:15.674 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '1d2a859923' failed: org.graalvm.polyglot.PolyglotException: ReferenceError: "scriptExtension" is not defined

I cleaned /etc/openhab/automation before installing all files mentioned in the README.md at:

https://github.com/rkoshak/openhab-rules-tools/tree/main/ephem_tod

since i got some python and javascript fragments there, from trying some older OH2.5 examples. When looking at the javascript examples at:

it looks like i’m missing some really basic thing here since

scriptExtension.importPreset("default");

is getting used there frequently and without mentioning any requirements?

I’m using the official .deb package on a Ubuntu 20 system if that matters…

regards,

Christoph

Create a simple rule with a JavaScript script action. Just have it log something. Does that generate the same error?

This is something very fundamental wrong and not specific to this role I think. But if the error occurs even on a simple rule maybe not.

Logging into Karaf, would this line to the job? log:set DEBUG openhab.model.script.Rules.TimeOfDay

I still get no debug log, only info.

You’re missing the “org” part of the logger name.

org.openhab.model.script.Rules.TimeOfDay

Thanks for the reply - i’ve created this javascript script and it works:

var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Examples");

logger.info("Typing needed classes");

adding a line with:

scriptExtension.importPreset("RuleSupport");

raises the “ReferenceError” exception…

You are using the built in ECMAScript 5.1, not the GraalVM JavaScript addon? The above only works with the default JavaScript.

How do i select using the “default JavaScript”? When creating a script or rule i only have these options:

I tried the Blockly option where i switched to the code view and pasted the code and the ECMAScript option as well…

It appears that if you’ve installed the GraalVM JavaScript addon it replaces the default one. In other words, you can’t. If you do not plan on using the GraalVM JavaScript, don’t install it. If you do plan on using it you’ll have to rewrite the rule above to work with that.

Thank you for clarifying! After uninstalling the GraalVM addon and restarting openhab, the script is working finally!

You’ve also installed Jython and Groovy too. Do you have plans to use those? If not don’t install them. The more stuff you have installed the more opportunities there are for problems. Only install add-ons (and software for that matter) you intend to use. Don’t install stuff “just in case”.

Good advice - i will do so.