Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Rules validator give incorrect EValidator messages or throws an error #6839

Open
justClouds opened this issue Jan 12, 2019 · 0 comments
Open

Comments

@justClouds
Copy link

I have a .rules file (in OH 2.4.0 and same issue in 2.5.0.-SNAPSHOT) with a value defined within each of the rules as shown below. It is just a string to use as label for logDebug/Info/Warning/Error() functions. Somehow the validator thinks the tag variable is not used (one or two messages, it varies...). It displays the following messages when starting OH:

2019-01-12 10:12:36.063 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'dsmr.rules', using it anyway:
The value of the local variable tag is not used
The value of the local variable tag is not used
2019-01-12 10:12:36.066 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'dsmr.rules'

and sometimes it throws an error:

2019-01-12 10:20:29.315 [ERROR] [xtext.validation.CompositeEValidator] - Error executing EValidator
java.util.ConcurrentModificationException: null
	at org.eclipse.emf.common.util.AbstractEList$EIterator.checkModCount(AbstractEList.java:758) ~[?:?]
	at org.eclipse.emf.common.util.AbstractEList$EIterator.doNext(AbstractEList.java:712) ~[?:?]
	at org.eclipse.emf.common.util.AbstractEList$EIterator.next(AbstractEList.java:692) ~[?:?]
	at org.eclipse.emf.common.util.AbstractTreeIterator.next(AbstractTreeIterator.java:133) ~[?:?]
	at org.eclipse.xtext.resource.impl.DefaultResourceDescription.computeExportedObjects(DefaultResourceDescription.java:88) ~[?:?]
	at org.eclipse.xtext.resource.DerivedStateAwareResourceDescriptionManager$1.getLookUp(DerivedStateAwareResourceDescriptionManager.java:84) ~[?:?]
	at org.eclipse.xtext.resource.impl.AbstractResourceDescription.getExportedObjects(AbstractResourceDescription.java:50) ~[?:?]
	at org.eclipse.xtext.resource.impl.AbstractCompoundSelectable$4.apply(AbstractCompoundSelectable.java:75) ~[?:?]
	at org.eclipse.xtext.resource.impl.AbstractCompoundSelectable$4.apply(AbstractCompoundSelectable.java:71) ~[?:?]
	at com.google.common.collect.Iterators$8.transform(Iterators.java:799) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.Iterators$5.hasNext(Iterators.java:548) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.TransformedIterator.hasNext(TransformedIterator.java:43) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.Iterators.addAll(Iterators.java:361) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.Iterables.addAll(Iterables.java:354) ~[22:com.google.guava:18.0.0]
	at com.google.common.collect.Sets.newLinkedHashSet(Sets.java:328) ~[22:com.google.guava:18.0.0]
	at org.eclipse.xtext.xbase.lib.IterableExtensions.toSet(IterableExtensions.java:619) ~[160:org.eclipse.xtext.xbase.lib:2.14.0.v20180522-1629]
	at org.eclipse.xtext.xbase.validation.UniqueClassNameValidator.checkUniqueInIndex(UniqueClassNameValidator.java:102) ~[?:?]
	at org.eclipse.xtext.xbase.validation.UniqueClassNameValidator.doCheckUniqueName(UniqueClassNameValidator.java:95) ~[?:?]
	at org.eclipse.xtext.xbase.validation.UniqueClassNameValidator.doCheckUniqueName(UniqueClassNameValidator.java:87) ~[?:?]
	at org.eclipse.xtext.xbase.validation.UniqueClassNameValidator.lambda$checkUniqueName$0(UniqueClassNameValidator.java:74) ~[?:?]
	at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
	at org.eclipse.xtext.xbase.validation.UniqueClassNameValidator.checkUniqueName(UniqueClassNameValidator.java:76) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator$MethodWrapper.invoke(AbstractDeclarativeValidator.java:118) ~[154:org.eclipse.xtext:2.14.0.v20180522-1821]
	at org.eclipse.xtext.validation.AbstractDeclarativeValidator.internalValidate(AbstractDeclarativeValidator.java:312) ~[154:org.eclipse.xtext:2.14.0.v20180522-1821]
	at org.eclipse.xtext.validation.AbstractInjectableValidator.validate(AbstractInjectableValidator.java:71) ~[154:org.eclipse.xtext:2.14.0.v20180522-1821]
	at org.eclipse.xtext.validation.CompositeEValidator.validate(CompositeEValidator.java:151) [154:org.eclipse.xtext:2.14.0.v20180522-1821]
	at org.eclipse.emf.ecore.util.Diagnostician.doValidate(Diagnostician.java:171) [66:org.eclipse.emf.ecore:2.12.0.v20160420-0247]
	at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:158) [66:org.eclipse.emf.ecore:2.12.0.v20160420-0247]
	at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:137) [66:org.eclipse.emf.ecore:2.12.0.v20160420-0247]
	at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:108) [66:org.eclipse.emf.ecore:2.12.0.v20160420-0247]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.validateModel(ModelRepositoryImpl.java:282) [128:org.eclipse.smarthome.model.core:0.11.0.201901111358]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:95) [128:org.eclipse.smarthome.model.core:0.11.0.201901111358]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:239) [128:org.eclipse.smarthome.model.core:0.11.0.201901111358]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processIgnoredFiles(FolderObserver.java:149) [128:org.eclipse.smarthome.model.core:0.11.0.201901111358]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.addModelParser(FolderObserver.java:95) [128:org.eclipse.smarthome.model.core:0.11.0.201901111358]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.apache.felix.scr.impl.inject.methods.BaseMethod.invokeMethod(BaseMethod.java:228) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.inject.methods.BaseMethod.access$500(BaseMethod.java:41) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.inject.methods.BaseMethod$Resolved.invoke(BaseMethod.java:664) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.inject.methods.BaseMethod.invoke(BaseMethod.java:510) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.inject.methods.BindMethod.invoke(BindMethod.java:42) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:1813) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.java:1788) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.SingleComponentManager.invokeBindMethod(SingleComponentManager.java:436) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:333) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:302) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1216) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1137) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:944) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:880) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1168) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:125) [39:org.apache.felix.scr:2.1.14]
	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109) [?:?]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920) [?:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [?:?]
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225) [?:?]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469) [?:?]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:906) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:892) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:128) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:959) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:732) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:1053) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:1007) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1216) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1137) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:944) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:880) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1168) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:125) [39:org.apache.felix.scr:2.1.14]
	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109) [?:?]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920) [?:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [?:?]
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127) [?:?]
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225) [?:?]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469) [?:?]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:906) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:892) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:128) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:959) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:732) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:666) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:432) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:665) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:339) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:381) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.Activator.access$200(Activator.java:49) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:263) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.AbstractExtender.createExtension(AbstractExtender.java:196) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:169) [39:org.apache.felix.scr:2.1.14]
	at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:49) [39:org.apache.felix.scr:2.1.14]
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482) [?:?]
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415) [?:?]
	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [?:?]
	at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444) [?:?]
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908) [?:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [?:?]
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [?:?]
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213) [?:?]
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120) [?:?]
	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112) [?:?]
	at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168) [?:?]
	at org.eclipse.osgi.container.Module.publishEvent(Module.java:476) [?:?]
	at org.eclipse.osgi.container.Module.start(Module.java:467) [?:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1634) [?:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1614) [?:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1585) [?:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1528) [?:?]
	at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1) [?:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [?:?]
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340) [?:?]
2019-01-12 10:20:33.940 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'dsmr.rules', using it anyway:
Error executing EValidator
The value of the local variable tag is not used
2019-01-12 10:20:33.944 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'dsmr.rules'

The rules are quite simple and I'm sure they all reference the tag value:

// Set default Grafana display switches on system start.
// Note: It will also be triggered on any configuration file update.
//----------------------------------------------------------------------------------------
rule "Initialize Power Panel values"
when
	System started
then
    val tag = "DSMR.Startup"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "System start, set DSMR view paramaters to default values")
    Pwr_Panel1.postUpdate("PWR_USE")
    Pwr_Period1.postUpdate("DAY")
    Pwr_Panel2.postUpdate("HIST_USE")
    Pwr_Period2.postUpdate("WEEK")
    Pwr_Interval2.postUpdate("1d")
    Pwr_Period3.postUpdate("DAY")
    Pwr_Interval3.postUpdate("1d")
    Gas_Panel4.postUpdate("GAS_USE")
    logDebug(tag, "<<< Exit rule")
end

// Reset day total counters at midnight
//----------------------------------------------------------------------------------------
rule "Midnight DSMR day counters reset"
when
	Time is midnight
then
    val tag = "DSMR.Reset.Counters" 
    logDebug(tag, ">>> Enter rule")

    logInfo(tag, "Reset DSMR day counters at midnight")
    // Save current day total counters
    if (Pwr_UseDay.state instanceof Number)
        Pwr_UseDayTot.postUpdate(Pwr_UseDay.state as Number)
    if (Pwr_UseDayT1.state instanceof Number)
        Pwr_UseDayTotT1.postUpdate(Pwr_UseDayT1.state as Number)
    if (Pwr_UseDayT2.state instanceof Number)
        Pwr_UseDayTotT2.postUpdate(Pwr_UseDayT2.state as Number)
    if (Pwr_RetDay.state instanceof Number)
        Pwr_RetDayTot.postUpdate(Pwr_RetDay.state as Number)
    if (Pwr_RetDayT1.state instanceof Number)
        Pwr_RetDayTotT1.postUpdate(Pwr_RetDayT1.state as Number)
    if (Pwr_RetDayT2.state instanceof Number)
        Pwr_RetDayTotT2.postUpdate(Pwr_RetDayT2.state as Number)
    // Set base counters to midnight values
    if (Pwr_UseTot.state instanceof Number) {
    	Pwr_UseLast.postUpdate(Pwr_UseTot.state as Number)
        logDebug(tag, "Reset Pwr_UseLast to " + Pwr_UseTot)
    }
    if (Pwr_UseTotT1.state instanceof Number) {
        Pwr_UseLastT1.postUpdate(Pwr_UseTotT1.state as Number)
        logDebug(tag, "Reset UseLastT1 to " + Pwr_UseTotT1)
    }
    if (Pwr_UseTotT2.state instanceof Number) {
        Pwr_UseLastT2.postUpdate(Pwr_UseTotT2.state as Number)
        logDebug(tag, "Reset Pwr_UseLastT2 to " + Pwr_UseTotT2)
    }
    if (Gas_UseTot.state instanceof Number) {
        Gas_UseLast.postUpdate(Gas_UseTot.state as Number)
        logDebug(tag, "Reset Gas_UseLast to " + Gas_UseTot)
    }
    if (Pwr_RetTot.state instanceof Number) {
        Pwr_RetLast.postUpdate(Pwr_RetTot.state as Number)
        logDebug(tag, "Reset Pwr_RetLast to " + Pwr_RetTot)
    }
    if (Pwr_RetTotT1.state instanceof Number) {
        Pwr_RetLastT1.postUpdate(Pwr_RetTotT1.state as Number)
        logDebug(tag, "Reset Pwr_RetLastT1 to " + Pwr_RetTotT1)
    }
    if (Pwr_RetTotT2.state instanceof Number) {
        Pwr_RetLastT2.postUpdate(Pwr_RetTotT2.state as Number)
        logDebug(tag, "Reset Pwr_RetLastT2 to " + Pwr_RetTotT2)
    }
    // Reset day sum counters
    Pwr_UseDay.postUpdate(0)
    Pwr_UseDayT1.postUpdate(0)
    Pwr_UseDayT2.postUpdate(0)
    Pwr_RetDay.postUpdate(0)
    Pwr_RetDayT1.postUpdate(0)
    Pwr_RetDayT2.postUpdate(0)
    Gas_UseDay.postUpdate(0)
    logDebug(tag, "<<< Exit rule")
end

// Calculate the day total of Gas consumed
//----------------------------------------------------------------------------------------
rule "Gas usage day total"
when
    Item Gas_UseTot changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Calculate Gas_UseDay")
    if (!(Gas_UseLast.state instanceof Number))
        logWarn(tag, "Gas_UseLast not yet initialized, skip calculation of Gas_UseDay")
    else {
        if (Gas_UseTot.state instanceof Number)
            Gas_UseDay.postUpdate(Gas_UseTot.state as Number - Gas_UseLast.state as Number)
        else
            logWarn(tag, "Gas_UseTot not yet initialized, skip calculation of Gas_UseDay")
    }
    logDebug(tag, "<<< Exit rule")
end

// Calculate the sum of the DSMR counters for Low tariff Power consumption
//----------------------------------------------------------------------------------------
rule "Power usage T1 day total"
when
    Item Pwr_UseTotT1 changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Calculate Pwr_UseDayT1")
    if (!(Pwr_UseLastT1.state instanceof Number))
        logWarn(tag, "Pwr_UseLastT1 not initialized")
    else
        if (Pwr_UseTotT1.state instanceof Number) {
            logInfo(tag, "Pwr_UseDayT1 is being updated")
            Pwr_UseDayT1.postUpdate(Pwr_UseTotT1.state as Number - Pwr_UseLastT1.state as Number)
        }
        else
            logWarn(tag, "Item {} not yet initialized, skip calculation of Pwr_UseDayT1", triggeringItem)
    logInfo(tag, "Calculate Pwr_UseTot")
    if (Pwr_UseTotT1.state instanceof Number) {
        if (Pwr_UseTotT2.state instanceof Number)
            Pwr_UseTot.postUpdate(Pwr_UseTotT1.state as Number + Pwr_UseTotT2.state as Number)
        else
            logWarn(tag, "Pwr_UseTotT2 not initialized, skip calculation of Pwr_UseTot")
    }
    else
        logWarn(tag, "Pwr_UseTotT1 not initialized, skip calculation of Pwr_UseTot")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the sum of the DSMR counters for Normal tariff Power consumption
//----------------------------------------------------------------------------------------
rule "Power usage T2 day total"
when
    Item Pwr_UseTotT2 changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Calculate Pwr_UseDayT2")
    if (!(Pwr_UseLastT2.state instanceof Number))
        logWarn(tag, "Day start usage counter T2 not initialized, skip calculation")
    else
        if (triggeringItem.state instanceof Number) {
            Pwr_UseDayT2.postUpdate(triggeringItem.state as Number - Pwr_UseLastT2.state as Number)
            logDebug(tag, "Item Pwr_UseDayT2 is being updated")
        }
        else
            logWarn(tag, "Item {} not yet initialized, skip calculation of Pwr_UseDayT2", triggeringItem.name)
    logInfo(tag, "Calculate Pwr_UseTot")
    if (Pwr_UseTotT1.state instanceof Number) {
        if (Pwr_UseTotT2.state instanceof Number)
            Pwr_UseTot.postUpdate(Pwr_UseTotT1.state as Number + Pwr_UseTotT2.state as Number)
        else
            logWarn(tag, "Pwr_UseTotT2 not initialized, skip calculation of Pwr_UseTot")
    }
    else
        logWarn(tag, "Pwr_UseTotT1 not initialized, skip calculation of Pwr_UseTot")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the day total of the DSMR counters for Low & High tariff Power consumption
//----------------------------------------------------------------------------------------
rule "Power usage total today"
when
    Item Pwr_UseTot changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Calculating updated Pwr_UseDay")
    if (!(Pwr_UseTot.state instanceof Number))
        logInfo(tag, "Item {} not yet initialized, skip calculation of Pwr_UseDay", triggeringItem.name)
    else if (Pwr_UseTot.state instanceof Number && Pwr_UseLast.state instanceof Number) {
        Pwr_UseDay.postUpdate(Pwr_UseTot.state as Number - Pwr_UseLast.state as Number)
        logDebug(tag, "Calculate Pwr_UseDay from Pwr_UseLast = " + Pwr_UseLast.state.toString + ", and Pwr_UseTot = " + Pwr_UseTot.state.toString + ", old = " + Pwr_UseDay.state.toString)
    }
    else
        logWarn(tag, "Pwr_UseLast not initialized, skip calculation of Pwr_UseDay")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the sum of the DSMR meter counters for Low tariff Power return
//----------------------------------------------------------------------------------------
rule "Power return T1 day total"
when
    Item Pwr_RetTotT1 changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Recalculate Pwr_RetDayT1 updated total return")
    if (!(Pwr_RetLastT1.state instanceof Number))
        logWarn(tag, "Pwr_RetLastT1 not initialized, skip calculation of Pwr_RetDayT1")
    else {
        if (Pwr_RetTotT1.state instanceof Number) {
            Pwr_RetDayT1.postUpdate(Pwr_RetTotT1.state as Number - Pwr_RetLastT1.state as Number)
            logDebug(tag, "Calculate Pwr_RetDayT1 from Pwr_RetLastT1 = " + Pwr_RetLastT1.state.toString + ", and Pwr_RetTotT1 = " + Pwr_RetTotT1.state.toString + ", old = " + Pwr_RetDayT1.state.toString)
        }
        else
            logWarn(tag, "Pwr_RetTotT1 not initialized, skipping calculation")
    }
    logInfo(tag, "Calculate updated Pwr_RetTot (T1+T2)")
    if (Pwr_RetTotT1.state instanceof Number && Pwr_RetTotT2.state instanceof Number)
        Pwr_RetTot.postUpdate(Pwr_RetTotT1.state as Number + Pwr_RetTotT2.state as Number)
    else
        logWarn(tag, "Pwr_RetTotT2 not initialized, skip calculation of Pwr_RetTot")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the sum of the DSMR meter counters for High tariff Power return
//----------------------------------------------------------------------------------------
rule "Power return T2 day total"
when
    Item Pwr_RetTotT2 changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Recalculate Pwr_RetDayT2 when Pwr_RetTotT2 changed")
    if (!(Pwr_RetLastT2.state instanceof Number))
        logWarn(tag, "Pwr_RetLastT2 not yet initialized, skip calculation of Pwr_RetDayT2")
    else {
        if (Pwr_RetTotT2.state instanceof Number) {
            Pwr_RetDayT2.postUpdate(Pwr_RetTotT2.state as Number - Pwr_RetLastT2.state as Number)
            logDebug(tag, "Calculate Pwr_RetDayT2 from Pwr_RetLastT2 = " + Pwr_RetLastT2.state.toString + ", and Pwr_RetTotT2 = " + Pwr_RetTotT2.state.toString + ", old = " + Pwr_RetDayT2.state.toString)
        }
        else
            logWarn(tag, "Pwr_RetTotT2 not yet initialized, skip calculation of Pwr_RetDayT2")
    }
    logInfo(tag, "Calculate updated Pwr_RetTot (T1+T2)")
    if (Pwr_RetTotT1.state instanceof Number && Pwr_RetTotT2.state instanceof Number)
        Pwr_RetTot.postUpdate(Pwr_RetTotT1.state as Number + Pwr_RetTotT2.state as Number)
    else
        logWarn(tag, "Pwr_RetTotT1 not yet initialized, skip calculation of Pwr_RetTot")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the day total of the DSMR counters for Low & High tariff Power return
//----------------------------------------------------------------------------------------
rule "Power return today"
when
    Item Pwr_RetTot changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logInfo(tag, "Recalculate Pwr_RetDay when Pwr_RetTot changed")
    if (Pwr_RetTot.state instanceof Number && Pwr_RetLast.state instanceof Number) {
        Pwr_RetDay.postUpdate(Pwr_RetTot.state as Number - Pwr_RetLast.state as Number)
        logDebug(tag, "Calculate Pwr_RetDay from Pwr_RetLast = " + Pwr_RetLast.state.toString + ", and Pwr_RetTot = " + Pwr_RetTot.state.toString + ", old = " + Pwr_RetDay.state.toString)
    }
    else
        logWarn(tag, "Pwr_RetLast not initialized, skip calculation of Pwr_RetDay")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the delta of power consumed and power returned
//----------------------------------------------------------------------------------------
rule "Power delta total"
when
    Item Pwr_Ret changed or
    Item Pwr_Use changed
then
    val tag = "DSMR." + triggeringItem.name + ".Changed"
    logDebug(tag, ">>> Enter rule")
    logDebug(tag, "Recalculating Pwr_Delta when " + triggeringItem.name + " changed")
    if (Pwr_Ret.state instanceof Number) {
        if (Pwr_Use.state instanceof Number) {
            Pwr_Delta.postUpdate(Pwr_Use.state as Number - Pwr_Ret.state as Number)
            logDebug(tag, "Calculate Pwr_Delta from Pwr_Use = " + Pwr_Use.state.toString + ", and Pwr_Ret = " + Pwr_Ret.state.toString + ", old = " + Pwr_Delta.state.toString)
        }
        else
            logWarn(tag, "Pwr_Use not initialized, skip calculation of Pwr_Delta")
    }
    else
        logWarn(tag, "Pwr_Ret not initialized, skip calculation of Pwr_Delta")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the delta of L1 power consumed and power returned
//----------------------------------------------------------------------------------------
rule "Power delta L1"
when
    Item Pwr_RetL1 changed or
    Item Pwr_UseL1 changed
then
    val tag = "DSMR." + triggeringItem.name + ".Changed"
    logDebug(tag, ">>> Enter rule")
    logDebug(tag, "Recalculate Pwr_DeltaL1 when Pwr_RetL1 or Pwr_UseL1 changed")
    if (Pwr_RetL1.state instanceof Number) {
        if (Pwr_UseL1.state instanceof Number) {
            Pwr_DeltaL1.postUpdate(Pwr_UseL1.state as Number - Pwr_RetL1.state as Number)
            logDebug(tag, "Calculate Pwr_DeltaL1 from Pwr_UseL1 = " + Pwr_UseL1.state.toString + ", and Pwr_RetL1 = " + Pwr_RetL1.state.toString + ", old = " + Pwr_DeltaL1.state.toString)
        }
        else
            logWarn(tag, "Pwr_UseL1 not initialized, skip calculation of PwrDeltaL1")
    }
    else
        logWarn(tag, "Pwr_RetL1 not initialized, skip calculation of Pwr_DeltaL1")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the delta of L2 power consumed and power returned
//----------------------------------------------------------------------------------------
rule "Power delta L2"
when
    Item Pwr_RetL2 changed or
    Item Pwr_UseL2 changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logDebug(tag, "Recalculate Pwr_DeltaL2 when Pwr_RetL2 or Pwe_UseL2 changed")
    if (Pwr_RetL2.state instanceof Number) {
        if (Pwr_UseL2.state instanceof Number) {
            Pwr_DeltaL2.postUpdate(Pwr_UseL2.state as Number - Pwr_RetL2.state as Number)
            logDebug(tag, "Calculate Pwr_DeltaL2 from Pwr_UseL2 = " + Pwr_UseL2.state.toString + ", and Pwr_RetL2 = " + Pwr_RetL2.state.toString + ", old = " + Pwr_DeltaL2.state.toString)
        }
        else
            logWarn(tag, "Pwr_UseL2 not initialized, skip calculation of Pwr_DeltaL2")
    }
    else
        logWarn(tag, "Pwr_RetL2 not initialized, skip calculation of Pwr_DeltaL2")
    logDebug(tag, "<<< Exit rule")
end

// Calculate the delta of L3 power consumed and power returned
//----------------------------------------------------------------------------------------
rule "Power delta L3"
when
    Item Pwr_RetL3 changed or
    Item Pwr_UseL3 changed
then
    val tag = "DSMR."+triggeringItem.name+".Changed"
    logDebug(tag, ">>> Enter rule")
    logDebug(tag, "Recalculate Pwr_DeltaL3 when Pwr_RetL3 or PwrUseL3 changed")
    if (Pwr_RetL3.state instanceof Number) {
        if (Pwr_UseL3.state instanceof Number) {
            Pwr_DeltaL3.postUpdate(Pwr_UseL3.state as Number - Pwr_RetL3.state as Number)
            logDebug(tag, "Calculate Pwr_DeltaL3 from Pwr_UseL3 = " + Pwr_UseL3.state.toString + ", and Pwr_RetL3 = " + Pwr_RetL3.state.toString + ", old = " + Pwr_DeltaL3.state.toString)
        }
        else
            logWarn(tag, "Pwr_UseL3 not initialized, skip calculation of Pwr_Delta_L3")
    }
    else
        logWarn(tag, "Pwr_RetL3 not initialized, skip calculation of Pwr_Delta_L3")
    logDebug(tag, "<<< Exit rule")
end

The rules are working now, so I could remove the logging. But experience shows that a new OH or ESH version can give new issues, so I would rather leave them in. And anyway, I think it is an error with the validation engine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant