VSCode extension for js rules and variables

GitHub - openhab/openhab-vscode: VS Code extension for openHAB configuration files is a nice extension for DSL rules where you can get mouse over item state tool tips.
However, it does not seem to work with js files. Is there an equivalent for javascript ?

No, there is no extension for VSCode that supports JS openHAB rules like that.

In the UI one has access to the developer sidebar which provides that sort of thing and more, but through VSCode there’s just support for generic JS extensions that are not openHAB aware.

I thought there might be something for js files. The extension hasn’t been updated in a while so I asked my friend Claude to modify it for me:

It was just one line of code and now the extension also has mouse over on js files:

1 Like

From JavaScript Scripting - Automation | openHAB

openHAB JavaScript library provides type definitions for most of its APIs to enable code completion is IDEs like VS Code (opens new window). To use the type definitions, install the openhab npm package (opens new window)(read the installation guide (opens new window)for more information), and manually import the used namespaces (see above).

You need to special extension for VS Code, VS Code only needs the type definitions available.

You need more than that to do what OP was after, hover over an Item’s name and see it’s current state.

Thx, works great, was looking for that for a long time already :+1:

Ah, sorry did overlook that. Probably I shouldn’t use the community from my phone.

I just updated the extension. Tooltip now also reports variable states if found in the log. All you have to do is log the variable. E.g. myVariable=”state” should appear in the log and when you mouse over it looks like this:

If the string is found in the log and has no = “..” formatting, it looks like this:

Check it out here: Release v1.0.1 · s0170071/openhab-vscode · GitHub
You have to configure the location of the log. In the settings you would search for openhab.log and then edit the settings file:


    "openhab.log.openhabLogPath": "/opt/openhab/userdata/logs/openhab.log",

    "openhab.log.eventsLogPath": "/opt/openhab/userdata/logs/events.log"

Now Iet me look into breakpoints…

1 Like

Mouse over for Item values does not work anymore on *.sitemap files. Any idea?

Jep. That never had worked in the first place. Noticed that too. Added sitemap support.
Here you go: Release v1.0.1 · s0170071/openhab-vscode · GitHub

Works like a charm, makes troubleshooting so much easier.
Thx a lot :+1:

I would encourage you to consider a PR or series of PRs with all of these improvements being made. It will benefit the community more widely.

1 Like

https://github.com/openhab/openhab-vscode/pull/329

1 Like