Reusable Rules via Function in OpenHab 2

in Openhab 1.8,3 I use some function to simplify the rule code, using suggestion at this article:

Opening a 1.8 rule with 2.0 Designer, this kind of code have some errors:

Is there a way to use function in OpenHab 2.0 rules?

Many Thanks

What is more important than seeing what is red underlined, we need to know why. Hover your mouse over the lines to see why Designer thinks it is an error.

Also, these days I’ve found that both OH 1.8 and OH 2.0 Designer has some things that are broken such that it marks things as errors which are not errors.

Have you tried to run it?

hi @rlkoshak,
I did a quick test, and it does not work. The error shown from Designer is:

I have a lot of rules in my 1.8 that use this method to light the code, so please help me to fix.

Thanks a lot

Wait, if you are in OH 2 then the path to those classes changed. Also you no longer need to use the fully qualified name of the Item classes. Just remove the org.openhab.core.lkubrary.items part.

many thanks for help, it works.
I’m not a Java developer and I have not understood yet the OH2 secrets.
I still have a Warning:

Can I ignore it?


Hi @marcolino7
You need to substitute your item classes with the new ones used with the eclipse smarthome framework:





and so on…

I ran in to this issue myself a while ago.

I have this warning too. It is a warning, not an error so I’ve ignored it so far. I spent a few minutes trying to figure out the correct alternative way to define a function but haven’t found one that works yet. For now, just ignore the warning.

Many Thanks