Code Cleanup HELP! ;)

So here’s a question, I added your updated code right under my imports and when i do it stopped all my rules from working. When i remove it the other rules work fine. Is their a typo in it or am i putting it in the wrong place?

That’s where i had the previous 3 vals we replaced and they all worked fine…

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.core.library.types.*
import org.joda.time.DateTime
import org.openhab.core.items.*
import org.eclipse.xtext.xbase.lib.*
import org.openhab.model.script.actions.Timer
var Timer timer = null
val Functions@Function2 alert = [GroupItem g, String type |
    val latest = g.members.sortBy[lastUpdate].last
    val name = latest.name.split("_")
    Notification_Proxy.postUpdate(name.get(1) + " " + name.get(2) + " " + name.get(3) + " " + type + " Alert!, " + latest.state.toString)
]


What do your logs say?

Open it in Designer and see if it is highlighting something as being an error.

A lambda is a global variable so it is in the right place.

I don’t use designer and all that. I use the cli for everything.

Logs don’t say anything in debug, items and sitemaps still work just the entire rules file locks up and nothing in it works. If I comment out that val then were back to normal.

found it! changed the @ sign to $ like the other var’s were and all is good!

You are doing a disservice to yourself by not using Designer. The poorly described errors that OH generates coupled with the uneven coverage of the documentation makes Designer a must have tool for rules development. You can solve errors like these in seconds or even better, before you even save the file. You can also explore and discover the language through the <ctrl><space> shortcut which will give you the valid completions for the current line which comes in handy when trying to remember or figure out what methods a Class has.

As a case in point, OH throws a Null exception. That exception could be caused by:

  • typo in the Item name in your rule
  • the Item’s state is undefined
  • you are trying to postUpdate or sendCommand with data the Item cannot convert to its internally supported state
  • you need to cast the state to DecimalType or the like in order to use it like you want to

I’m sure there are more. One exception, at least four potential causes. But if you use Designer it will tell you immediately, as you type, if you have most of these errors before you even save the file.

Using Designer will save you many hours of time. And there are tons of ways you can set it up on a desktop to edit or share the configs with a headless server.

  • Samba share the configurations folder
  • check the config folder into git and push and pull the changes
  • rsync

Yea i hear ya. Makes sense. Once I migrate over to my new host device ill just share the config folders and edit them with designer on windows and check it out.

Thanks a lot for all your help. I really do appreciate it!! :wink: I’ll stop bothering ya for awhile haha :wink:

very intresting topic as i’m looking forward to do the same.
would you be so kind to share your complete setup for this ?
i would like to take a look at the rules and the item files.
Currently i allrady have an alarm setup with openhab but i would like to improve the detection as to know what triggerd the alarm.
Inspecting your code this seems possible.