Customize the JavaScript code of OpenHAB 2 project

@Web_Solution, the Javascript code for HABPanel is in the web folder here:

But you can’t modify the one which is included in your distribution, you can however do either of these things:

  • make the changes you need, recompile the bundle with Maven (follow the docs here: Developer Guide | openHAB - basically, run mvn clean install -DskipChecks in the bundle’s directory) then add the resulting .jar file in the target folder to the addons folder in your distribution (uninstall the current distribution’s add-on with Paper UI first: Add-ons > UI > Click Uninstall next to HABpanel);
  • (simpler) clone the repository with Git and copy the above mentioned web folder to the openHAB configuration folder, in html/myhabpanel for example. It will then be accessible under: http://<openhab>:8080/static/myhabpanel/. You can then change the code however you want. Note that this will be a customized version that is not accessible from the tile on the home page.

That being said, maybe you don’t really need to change the code itself, for widget development you can lazy-load additional Javascript with the technique described here:

(read this part: Advanced: Injecting custom JavaScript code)

1 Like