openHAB generator - design your smart home in no time!

So recently I’ve been working on this secret project that’ll hopefully help you to get started with openHAB home automation in no time :slight_smile:

Meet openHAB generator - Yeoman based tool that allows you to quickly create *.items, *.sitemap and HABPanel layouts by simply providing details about your home:

  1. How many floors are in your house
  2. Select the rooms on each floor (e.g. Kitchen, Living room and Bathroom)
  3. Assign smart devices to each room

Then the tool will create all the files for you :slight_smile:

See it in action

Here’s the project’s repository:

Installation

First, install Yeoman and generator-openhab using npm (we assume you have pre-installed node.js).
If you’re using openHABian, Node.js should be already installed. (right @ThomDietrich? :slight_smile: )

npm i -g yo generator-openhab

Then go to your openhab-config/ folder and generate your files:

cd /etc/openhab2
yo openhab

Feedback

It’s an early stage and I have a few more ideas on how to improve it. I’d love to hear your feedback on this!

When the project is mature enough, I believe we could make it official? @Kai would you agree?

Please let me know what do you think. And of course “star” this repository :wink:

25 Likes

:laughing: This is brilliant!

Any chance you can choose to write to the json database instead of the .items file? For us UI lovers out there?

1 Like

Absolutely!
Just need to know where the json database is and what’s the exact structure of the items I can modify.

Sure, you’ll find it in $OPENHAB_USERDATA/jsondb/org.eclipse.smarthome.core.items.Item.json

I’d suggest making such a dummy item in the paper UI and then seeing the resulting entry:

e.g…

{
  "DiningRoom_DesktopPower_PowerConsumption": {
    "class": "org.eclipse.smarthome.core.items.ManagedItemProvider$PersistedItem",
    "value": {
      "groupNames": [],
      "itemType": "Number",
      "tags": [],
      "label": "Power Consumption",
      "category": "Energy"
    }
  }
}

I wouldn’t know if these can be simply added and edited on the fly though.

1 Like

Userdata rather, not runtime (edited above)

No - you will need to be careful. The json files are only read when the system starts - not when the system is running. You should stop OH completely before editing them, or there’s the chance the system will overwrite your changes before they are read.

1 Like

Thanks @chris, that’s good to know. I’d guess that a generator for json type files would be an initial setup step only.

And away are all design frustrations:wink:

To be honest: I love the feature, but not the fact that it requires a completely separate software stack.
It would imho be much cooler to have it as a web-based setup wizard integrated into openHAB. The current setup page, which comes up on new installations was meant as a starting point for such things - it would be much more stream-lined and not just a separate tool for a fraction of openHAB users.

Having it done as a bundle on the runtime, it would also have direct access to the item registry and could directly create the entities that way - no need to mess around with json files (where @chris is correct that you need to be very careful as they are not meant to be edited).

7 Likes

I love the idea and agree with Kai, this would be awesome if it were part of OH proper and accessible through the web pages.

Instead of editing the JSON file directly or creating .items files, you could use REST API calls to create the Items. I’m pretty sure that is how PaperUI creates Items itself anyway and then there is no need to stop OH while this is going on.

Of course, if this had access to the runtime it can access all the item registry directly so this might be a moot point.

1 Like

My point is that I don’t necessarily want to use REST API for a task like this and prefer textual config over UI. This is why I created this tool.

Well, it’s just JavaScript.

I’m sure there’s more than a “fraction” of us that use textual config. Also, openHABian users have Node.js installed already. Which is why I thought it’ll be a valuable addition to it.
Can I at least mention my tool in the docs?

Absolutely! Feel free to reuse my code.
A good thing about this being implemented in JS is that it can be easily moved into a webapp.

I’ve decided I’m not going to do it and keep my tool a simple text file generator.
@chris is right and I don’t want to dive into runtime issues. Sorry @Benjy!

Cheers,
Kuba

1 Like

My understanding of how the process works is when you create an Item through the REST API it ends up in the text based JSON DB that we have been talking about. The advantage is this lets you “edit” the JSON DB without first stopping OH. If you are talking about editing the JSON DB anyway, why balk at doing so through the REST API?

What Kai means is it is not a native part of OH. It requires a separate download, a separate install, and must be run separately from OH. Kai’s proposal is to make it part of OH itself so that all new users have access to this wizard automatically without the need to download and install a bunch of other stuff.

It isn’t the fraction of users who still use text based configs. Kai is referring to the fraction of users who will bother downloading and running a separate tool to do what this tool does.

1 Like

My point is that I don’t necessarily want to use REST API for a task like this

It does not have to use the REST API. If implemented as a bundle within the runtime, it can potentially generated item files locally or - much better - use the Java API to create everything, which will result in JSON files and provide the user a chance to edit it through the Paper UI.

I’m sure there’s more than a “fraction” of us that use textual config.

Well, the fraction is the dissection of openHABian users and the ones using text files. So clearly just a subset of users and everyone else would be out of the game.

Well, it’s just JavaScript.

It’s not! Node.js is native C code and that is part of the required stack.

A good thing about this being implemented in JS is that it can be easily moved into a webapp.

If this is easily possible, let’s try to do this together! This would make the feature available to all openHAB users and as I said: The current setup page was meant to be a starting point for such stuff. And being offered this feature right after installation would be a so much better UX for the users than having to figure out that there is such an additional tool, install node.js, get it working, etc. Wouldn’t you agree?

1 Like

Exactly! When i started with openHAB a few months ago this would have been an enormous help.

But I don’t think i would have installed a different tool right from the start, without knowing the native appoach. By the time the new user figures out the potential use of that tool, many new users are already off to another solution. (A friend of mine was put off openHAB as soon as i mentioned “configuration files”, telling him to install another tool and enter command line would be funny. ;))

2 Likes

Why not make this available as a menu item in openhabian-config right now? It would be a valuable tool for initial setup of openhab and the discussions about future integration into the runtime could continue. Philosophic discussions about the “proper” home for a capability are fine, but real help goes a lot farther in making OpenHab a viable option for new users.

@gbealmer You forget that openHAB is platform independent. openhabian is linux.

I don’t forget anything. Openhabian is an installation tool that enables users to setup a system. It has a menu of tools that is an appropriate location for this type of addition. Other methods of building a system require multiple installations of required/optional items and guidance to do so. The tool could be mentioned in that guidance, as are many other items. This could be added to openhabian right now and serve a useful purpose.

Hello Glenn,
adding the generator in openHABian is already in motion. It will be available before the week ends :slight_smile:

Besides that, I have to agree with @Kai, this tool would be way more helpful as a native feature as part of the initial setup on the openHAB webpage rather than as a separate command line tool. If this tool would then offer to either write to database or files, that would be an amazing addition. @kubawolanin what are your thoughts on that? Surely you’ll need to reinvent a few things but the abstract logic and snippets will stay the same.

1 Like

fantastic. Definitely going to give that a try

It’s great that you are taking steps to include this so quickly. When introducing someone to OpenHab, using openhabian as a base goes a long way in convincing them that it’s not too complicated for them. The addition of this tool will enhance that impression.
I never disagreed with concept of it being included as a native feature. My concern was the delay in availability. Experienced users aren’t really the target audience for this capability and novices are likely to begin with the stable release.