My first steps with OpenHab

I don’t really use openHABian so I can’t say for sure if this is expected or if an error during upgrade occurred.

Those files are hidden. Did you use ls -a? If they are not there there is a system default version of them under /etc somewhere.

Frontail is the third party application that lets you view the openHAB logs in the browser. That capability is not built into openHAB itself and is installed separately. It’s one of the many many things that openHABian does for you.

I did not. I found and removed the “2” from .bash_profile so that it points to /var/lib/openhab/etc/version.properties. I checked /var/lib/openhab/etc/version.properties and it has the right version. But, even after restarting the RPi I still see 2.5.9-1.

I’ve installed Crazy Ivan’s helper libraries for Javascript:

Still getting a ton of java.lang.ClassNotFoundException errors.

I redirected the logs back to the USB stick.

More tomorrow, maybe.

I realised it needed to be the js-rewrite branch.

Made no difference. Still getting trillions of errors like:

java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.ScriptExecution cannot be found by org.openhab.core.automation.module.script

I worked out the problem with the rules. The Samba shares are not updated by the upgrade and still point to openhab2, rather than openhab. This means any modifications I made to my rules were being ignored.

@rikoshak, since you seem to be an expert on JSR223/Javascript, could you explain what we are supposed to do now instead of using the JSRule syntax? I’ve read multiple posts mentioning the problem but I can’t discern anything resembling a solution.

Trying to get the 3.0 version of my Awair binding up and running. At first I copied it to the addons directory and nothing happened. Then I realised that Samba was still sharing the openhab2 directory.

I needed to install Java 11 and set JAVA_HOME (apparently the plugin config in pom.xml is not recognised as a means of setting the required Java version). Still an error right at the end though.

I’m stuck on:

[WARNING] The POM for org.openhab.core.bom:org.openhab.core.bom.compile:pom:3.0.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.openhab.core.bom:org.openhab.core.bom.openhab-core:pom:3.0.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for org.openhab.core.bom:org.openhab.core.bom.test:pom:3.0.0-SNAPSHOT is missing, no dependency information available

and

[ERROR] Failed to execute goal on project org.openhab.binding.awair: Could not resolve dependencies for project org.openhab.addons.bundles:org.openhab.binding.awair:jar:3.0.0-SNAPSHOT: The following artifacts could not be resolved: org.openhab.core.bom:org.openhab.core.bom.compile:pom:3.0.0-SNAPSHOT, org.openhab.core.bom:org.openhab.core.bom.openhab-core:pom:3.0.0-SNAPSHOT, org.openhab.core.bom:org.openhab.core.bom.test:pom:3.0.0-SNAPSHOT: Failure to find org.openhab.core.bom:org.openhab.core.bom.compile:pom:3.0.0-SNAPSHOT in https://openhab.jfrog.io/openhab/libs-snapshot was cached in the local repository, resolution will not be reattempted until the update interval of openhab-snapshot has elapsed or updates are forced ->

Time for a post…

I’m not certain that rewrite is complete so it might not be fully working yet.

The JS Helper Library never did have parity with the Jython one and I know @CrazyIvan359 is doing his best to bring it to the same level as the Jython library but I think it’s still a work in progress.

I’m using UI created rules exclusively. My end goal is to write rule templates that can be installed from the up and coming marketplace so I’ve not been using the Helper Libraries at all and only writing rules through the UI with support from some modules. So I’ve never actually written a JavaScript rule in a .js file and couldn’t tell you how to do it.

There is an example in the Helper Library Docs but I don’t know if that matches any changes made to the Helper Libraries yet. I’ve lost the ball on the Helper Libraries but hope to catch back up over the coming months.

1 Like

(I actually had the answer ready to post. I was waiting for the confirmation from the log that it works, and now I have it)

I think I’ve solved the JSRule problem. For those unable to follow the link to the link to the link that I found, it’s here:

and it’s easily summarised: change JSRule to rule. That’s it.

Example:

rule
(
 {
    name: "OnReboot_SaveDateStamp",
    description: "Saves time of reboot",
    /*Runs every minute*/
    triggers: 
    [
        TimerTrigger("0 0/1 * * * ?")
    ],
    execute: function( module, input)
    {
      // Stuff       
    }
 }
);

I also worked out how to port my log configuration (which the OH3 trashed) to the new XML format (which is much better, by the way), thanks to this page:

https://openhabforum.de/viewtopic.php?f=8&t=3019&start=40

To add the rules.log file for rule output:

Add this to the appenders section:

		<!-- Rules file appender -->
		<RollingRandomAccessFile fileName="${sys:openhab.logdir}/rules.log" filePattern="${sys:openhab.logdir}/rules.log.%i" name="RULES">
			<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
			<Policies>
				<OnStartupTriggeringPolicy/>
				<SizeBasedTriggeringPolicy size="16 MB"/>
			</Policies>
		</RollingRandomAccessFile>

And this to the loggers section:

		<!-- Custom RULES logger -->
		<Logger additivity="false" level="INFO" name="org.openhab.core.model.script.rules">
			<AppenderRef ref="RULES"/>
		</Logger>

I also have a filter to remove this persistent, non-meaningful output from openhab.log (the Modbus gateway is actually turned off most of the time, hence the error). It requires a regular expression filter to be added to the openhab logger To do this, you modify the openhab.log config in appenders:

	  <RollingFile fileName="${sys:openhab.logdir}/openhab.log" filePattern="${sys:openhab.logdir}/openhab.log.%i" name="LOGFILE">
	          <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
	          <RegexFilter regex=".*connect try 1/4 error.*" onMatch="DENY" onMismatch="NEUTRAL"/>                        
	          <Policies>
	                  <OnStartupTriggeringPolicy/>
	                  <SizeBasedTriggeringPolicy size="16 MB"/>
	          </Policies>
	  </RollingFile>

Next problem: I get

"ReferenceError: "UpdatedEventTrigger" is not defined"

And the same for every other trigger name I try:
UpdateEventTrigger
ChangeEventTrigger
ChangedEventTrigger
TimerTrigger"

This was an easy one. You need to include triggers.js.

Yep. It’s a good idea to look through the core library files to see what’s in each file so you know which files need to be loaded in each context. It’s also a great way to see how it all works under the hood.

1 Like

It now looks as if ItemStateUpdateTrigger is the new Update(d)EventTrigger, and ItemStateChangeTrigger is the new Change(d)EventTrigger. StartupTrigger works, at last, we’re promised. Let’s see.

And TimerTrigger is now CronTrigger.

Not getting any output in rules.log. Not sure my configuration is correct.

All sorts of packages have moved around on OH 3. Rules live at org.openhab.model.script now. Notice the lack of core in that path now.

It’s not clear how you are creating your loggers though. You can create loggers with any arbitrary name if you create the logger yourself rather than using the openHAB Actions.

 this.log = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.Rules.Deferred");

If that doesn’t work, remove your custom appender and logger config for the rules and see if they appear in openhab.log. From there you should see most of the logger name.

Ahh. I had “org.openhab.core.model.script.rules”. I’m editing /var/lib/openhab/etc/log4j2.xml. OK I’ll try with that package.
It may also be that my rules are not outputting anything for some reason.