Like most of us I am lazy person and want to write fast Codeblocks
Happily I am Java BE-Dev in my fulltime job and my employer supports me with a IntelliJ-Ultimate.
(I know all other IDEs are fine too, but If you dont care lets take that one as example for know)
But when I connect with SAMBA (default) to that folder and load this file into my IDE I am missing all the usefull thinks like autocomplete/autoimport etc.
I’m very much in the same situation. I’m a professional software developer and I’m now trying to setup a dev environment to develop openHAB scripts which supports autocomplete support and the like.
The closest I could get so far with IntelliJ was inspired by [Solved] Setup IDE for JSR223 Code Completion - #2 by Philipp
I’ve also sucessfully set up VSCode and connected it to openHAB but that does not really has autocompletition support for the rules DSL.
Even if I could not get autocompletition to work I would be very happy if I could just find a complete API reference documentation or code examples beyond ‘hello wolrd’ to get started.
Groovy is lacking documentation and rules DSL is not what I’d recommend when getting started anymore.
I would suggest to have a look at JavaScript Scripting (from my experience Java devs have no problems working with JS Scripting) or JRuby Scripting.
Both provide a comprehensive API documentation (just check out the add-on docs), and JavaScript even provides auto-completion through type definitions when openhab-js is manually installed from npm.
Not sure if JRuby provides autocompletion though, I don’t know.
Thank you! I’ll give it a go then. Actually JavaScript was the first thing I’ve considered to use, but when I did read about the modularization support (JavaScript Scripting - Automation | openHAB) I’ve decided to try groovy as I can simply reference other groovy files without fiddeling around with NPM packaging and directly editing in the node_modules folder. But is it also possible to just include .js files within the same folder? I just want to keep my code clean and well organized and not put everything in a single file
Sharing of code between multiple files should be done through npm. While I think you will be able to import code from js files in the automation/js dir, this is not the intended way to do so — all files in that folder are automatically loaded, if they don‘t specify rules that won‘t do anything however.
I would consider checking online how to create a npm module, then simply pack and install it with npm and once you have done that you can continue developing your shared library inside its folder in node_modules and npm shouldn‘t wipe it out.
Actually JRule looks nice. I really like the IDE support. I’ve created a fork of the jrule-user demo project and managed to adapt it to have code completition working and I can sucessfully run ‘mvn clean install’, see: GitHub - lkleen/jrule-user: JRule User Demo and Test Project. It took me some time to figure out that I have to copy the compiles items file from openHAB to my project.
Everything looks good so far, but the rule does not work. It triggers when I’m pressing the button of my switch, but then only outputs: [e.automation.internal.RuleEngineImpl] - Failed to execute rule ‘fireplace_toggle’: Invalid Rule UID. At this point I’m stuck again.
After trying groovy and JRule I’ve now also tried to get on track with openhab-js and prettiy much had the best experience so far. With the openhab-js npm library installed I could eventually setup an environment where I have rudimentary code comletition support and instant feedback in the log file. So this is my current setup in TLDR notation:
host is running ubuntu server 24 LTS
openHAB 4.2.2. in a docker container with a host bind mount to the openhab conf dir (/home/system/docker-app-data/openhab/conf)
smb share to /home/system/docker-app-data
VSCode with openHAB extension (openHAB container maps ports 8080 and 8101 to the host)
docker exec -it openhab-container /bin/bash → the, in the containers console ‘tail -f openhab/userdata/logs/openhab.log’ to have realtime feedback from openhab → keep this console open for the log output
installed javascript addon in openHAB
file configuration for things and items in conf/items/.items and things/broker.things (I have zigbee2mqtt and Eclipse mosquito mqtt containers configured for that, another story)
npm install openhab@5.7 in the folder conf/automation/js
add script files in conf/automation/js → when saving openhab will automaticall detect changes and you can instantly see the result in the open console tailing the openhab.log
basically that’s it. I can now open the shared folder and work on it, modify the script, have some basic code completition and syntax checking and get instant feedback from openhab
Hi, @Lars_K.
I could try to help you check your issues with JRule, although I use it with Scala, so I pre-compile the rules jar.
It might be useful to post the issues in the JRule discussion thread or send me a PM so we don’t hijack this discussion.
I’ve now reinstalled openHAB and started over with a fresh mind. This time with more success
The ‘invalid UID’ error was caused by a rule I forgot to delete in the UI. The ‘zip END header not found’ was caused by macOS which generates stupid artefacts when copying to a network drive.
JRule is not to blame for that. I had just find it a litte faster if the output would list the loaded jar files.
I could now setup my first rule which is correctly triggered and toggling a light, yes!