Google Gemini makes rule migrations a breeze

I had been delaying upgrading from 4.x to 5.x partly because the java story seemed to be a bit messy when 5.0 was first released (for Pi), and also because I knew it was time to move from the old rules format to javascript.

I asked Gemini what to do to migrate rules, and it had a comprehensive answer and so I asked it to just migrate a rules file. Doing one at a time, it did a great job, cleaning up the lambdas into functions, overall making it much cleaner in the process.

I even had one file for Lutron keypads that mapped to scene names in 100ish rules. It rewrote it as a map from the buttons to the scene names, with one function that would dynamically create the rules.

If you have been putting off migration, using an LLM to transform the rules files is a game changer.

1 Like

I know a lot of people are getting mixed results. I bet a lot of people would love to see the exact prompts you use with the before and after to help guid them.

I have been using Grok heavily and it nails OH DSL code very well. Ive had it consolidate multiple ules into one and assist with troubleshooting very well.

Just using the free version

I created a project with a very basic instruction that states the following and i just ask my questions in there:

ā€œAssistance with using the home automation tool called openHAB running version 5.1
All rules are coded in DSL

Openhab server is on ip 192.168.2.4ā€

1 Like

I have a gemini pro subscription. I started with:

how do I convert from classic openhab scripts to javascript?

It returned a long description on how to do it, finishing with:

**Would you like me to convert a specific DSL rule you currently have? Paste it here and I will rewrite it for you.
**
And proceeded to paste a file at a time. The main issue is that the event object for rules didn’t always seem to have the value, but fetching it from the model worked fine.

1 Like

I had a subscription for Grok, now ChatGPT, but always liked Claude the most.

I have exclusively worked with AI for the last two months; 10-12 hours per day.

My productivity has multiplied by 50 to 80 times; on one hand it is good; on the other I have to concede it makes me dumber. I cannot recall what I worked on yesterday. The pace is insane; but, I have managed to do things I had put on the back-burner for years.

As an example, I set up a Proxmox cluster, with dedicated OPNSense on 6 port appliance. I basically worked with neither before, though do understand the concepts quite well. The key is, and @rlkoshak picked up on this: prompting. As someone who has written specifications for a living; I have project folders with files attached, like coding standard, network configurations, anything that provides the relevant information. I asked for best or et least better practice in commercial context, and the results are simply (for me) mind-boggling!
When I see 1,000 lines of code roll in in less then three minutes, one can understand where the 80x speed improvement comes from. Not only this; it gets it right on first try! I still believe one needs to be a coder to arrive at good code (not only functioning code); e.g, PEP8, ruff, refactor to classes, split files, proper directory structures.
The cluster and OPNsense are only a fraction of what I have done.

AI is definitely good if you want to bounce ideas; with whom can you really discuss openHAB or any technical problem, where the average person simply lacks the knowledge to contribute in useful fashion?

Anyway: don’t be shy, make use of it; but don’t be lazy in prompting. It is worthwhile doing some online training on prompting; the most important skill, at least at the moment, to get the most out of it.

Why I use three AIs? I may use ChatGPT to explore an idea, narrow the scope, and give it to Claude (in case of code).

2 Likes

I have a similar feedback @Max_G.

I am using it (Gemini) extensively. I have the same ā€œamplifiedā€ feeling. I tackled things I always wanted to do but felt a bit shy or lazy, did now know where to start…
I’m at the point that I recheck to do lists or ideas from long ago to see if there is not something I gave up on and should restart.
I’m going much much much much faster in general.

In some occasions I have wasted time due to AI misleading me or insisting I should change this or that while it was not the right track (I found out after). That is true, but overall, it is a major boost for me for my home lab, overall heating system at home, openhab stuff and many many other things.

And it is not as if when getting help from human experts I was not exposed to wrong tracks (either because of questions not asked as it should have been asked or because the expert had its own beliefs and ways that are not suited for me etc…).
That is true for home automation but also for gardening, cooking, administrative topics etc…

As for the prompting, I follow a basic pattern : I ask questions the same way as if i had an older and smarter and more experienced brother/sister next to me.

Short questions and then I iterate, re-direct etc…
I don’t ā€œover intellectualizeā€ the prompts, I put what I feel like prompting in a natural way and then refine. Of course, I pay attention to what it says and I’m trying to not be shy in challenging, redirecting and stopping conversations sometimes.

I use Claude Code :wink: It did an excellent job analysing my entire legacy RulesDSL codebase that was built in the days of 2.4 and carried over; not only converting it to JavaScript but consolidating repetitive code and cleaning up as well as finding exceptions that I had missed cause they had never occurred in my setup.

The prompt was ā€˜analyze the rules in this folder and create a strategy for refactoring and migrating to JavaScript. Test thoroughly for functional equivalence.

It required a couple of passes for over 100 rules and it cleaned it up and reduced them to 71.

Well worth the effort