import java.util.regex.Pattern import java.util.regex.Matcher val org.eclipse.xtext.xbase.lib.Functions$Function4 UPS_GetNumValue = [ StringItem logITem, NumberItem upsITem, String sExpr, String logline | var String ups_log ups_log = logITem.state.toString var Pattern ups_pattern ups_pattern = Pattern::compile(sExpr) var Matcher ups_matcher ups_matcher = ups_pattern.matcher(ups_log) ups_matcher.find() var String ups_result ups_result = ups_matcher.group(1) upsITem.postUpdate(ups_result) ] val org.eclipse.xtext.xbase.lib.Functions$Function4 UPS_GetStrValue = [ StringItem logITem, StringItem upsITem, String sExpr, String logline | var String ups_log ups_log = logITem.state.toString var Pattern ups_pattern ups_pattern = Pattern::compile(sExpr) var Matcher ups_matcher ups_matcher = ups_pattern.matcher(ups_log) ups_matcher.find() var String ups_result ups_result = ups_matcher.group(1) upsITem.postUpdate(ups_result) ] rule "USV Handling" when Item USV_Log received update then UPS_GetStrValue.apply(USV_Log,USV_Status,"(?<=STATUS : )(.*?)(?= )","LogLine") UPS_GetNumValue.apply(USV_Log,USV_LineV,"LINEV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine") UPS_GetNumValue.apply(USV_Log,USV_OutputV,"OUTPUTV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine") UPS_GetNumValue.apply(USV_Log,USV_Load,"LOADPCT \\: ([-+]?[0-9]*\\.?[0-9]) Percent","LogLine") UPS_GetNumValue.apply(USV_Log,USV_BattCharge,"BCHARGE \\: ([-+]?[0-9]*\\.?[0-9]) Percent","LogLine") UPS_GetNumValue.apply(USV_Log,USV_TimeLeft,"TIMELEFT \\: ([-+]?[0-9]*\\.?[0-9]) Minutes","LogLine") UPS_GetNumValue.apply(USV_Log,USV_ITemp,"ITEMP \\: ([-+]?[0-9]*\\.?[0-9]) C","LogLine") UPS_GetNumValue.apply(USV_Log,USV_BattVoltage," BATTV \\: ([-+]?[0-9]*\\.?[0-9]) Volts","LogLine") UPS_GetStrValue.apply(USV_Log,USV_BattDate,"(?<=BATTDATE : )(.*?)(?= )","LogLine") end rule "USV off battery" when Item USV_Status changed to "ONLINE" then if(SystemStarting.state == OFF) { sendXMPP("user@jabberdomain.tld", new DateTimeType() + ": USV: Stromversorgung wiederhergestellt") sendTelegram("telegrambot", new DateTimeType() + ": USV: Stromversorgung wiederhergestellt") } end rule "USV on battery" when Item USV_Status changed to ONBATT then if(SystemStarting.state == OFF) { sendXMPP("user@jabberdomain.tld", new DateTimeType() + ": USV: Stromausfall!!!") sendTelegram("telegrambot", new DateTimeType() + ": USV: Stromausfall!!!") } end rule "USV Comm lost" when Item USV_Status changed to COMMLOST then if(SystemStarting.state == OFF) { sendXMPP("user@jabberdomain.tld", new DateTimeType() + ": USV: Kommunikationsverbindung verloren") sendTelegram("telegrambot", new DateTimeType() + ": USV: Kommunikationsverbindung verloren") } end