Rules do not fire

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Rev 1.2
    • OS: Linux 4.9.80-v7+
    • openHAB version: openHAB 2.2.0-1 (Release Build)

I have a strange situation. I have a bunch of rules which worked yesterday morning. Later the day, the stopped firing. It seemed that no rules were firing at all. The log does not hint at any problems.
Part of my configuration are stored in config files. Only the Z-Wave sensors have been configured through the PaperUI.
After a reboot, rules are firing again.

Somehow, I believe it started after I configured a proxy item (through config file) which I exposed to myOpenHab.
Exposure of the item is done through /etc/services/openhabcloud.cfg :


# A comma-separated list of items to be exposed to external services like IFTTT. 
# Events of those items are pushed to the openHAB Cloud and commands received for
# these items from the openHAB Cloud service are accepted and sent to the local bus.
# Optional, default is an empty list.
expose=GF_ALEXA_TV

Proxy item in .items file:

Switch GF_ALEXA_TV                      "Fernseher [%s]" [ "Switchable" ] 
..

Strangely enough, I couldn’t expose this item through the PaperUI to the myOpenHab.

I really stuck. This is all very strange.
Any ideas?

  • what traces should I enable which could help to figure out what is happening
  • Is it possible at all to have some things and items configured through PaperUI and some through config files?

…???

events.log and openhab.log?

2 Likes

I looked again. I have in one of my rule files (coming from OH1.8), the following warnings
Apart from that, I just checked the rules which worked after a reboot this morning, do not work anymore (e.g. the rule “SleepingRoom Main Light Off” below).

018-03-18 11:45:02.729 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'automation.rules', using it anyway:
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used
Null-safe call of primitive-valued feature hasTerminated, default value false will be used

Rules file…

import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
    
var Timer timer1
 var Timer timer2
 var Number internalState1 // used in rule SleepingRoom to maintain the current state
 var Number internalState2 // used in rule SleepingRoom to maintain the current state
 
 var Lock lock = new ReentrantLock()
 
 /*
  * Sleeping room
  */
 rule "SleepingRoom Main Light Off"
    when
        Item FF_SLEEP_PLUG1_Power received update or
        Item FF_SLEEP_PLUG2_Power received update
    then
        logInfo("Sleeping Room Main Light", FF_SLEEP_LIGHT.state.toString )
        logInfo("Sleeping Room Main Light", FF_SLEEP_PLUG1_Power.state.toString )
        logInfo("Sleeping Room Main Light", FF_SLEEP_PLUG2_Power.state.toString )
        
		if ((FF_SLEEP_LIGHT.state  == ON) && ((FF_SLEEP_PLUG1_Power.state > 2.0) ||  (FF_SLEEP_PLUG2_Power.state > 2.0))) {
			FF_SLEEP_LIGHT.sendCommand(OFF)
            FF_Sleep_Sonos_PlayPlaylist.sendCommand("Sleep")
            FF_Sleep_Sonos_Volume.sendCommand(15)
            FF_Sleep_Sonos_SleepTimer.sendCommand(1800)
		}
		
end

rule "SleepingRoom - Pause Sonos on DeskLamp1"
	when 
		Item FF_SLEEP_PLUG1_Power received update
	then

        lock.lock 
 
        logInfo("Sleeping Room Main Light Off - rule fired - 1st plug", FF_SLEEP_PLUG1_Power.state.toString )

		// The Sonos player is set to pause if within 15 seconds one of the two desk lamps will be going on twice 
		if  ((FF_SLEEP_PLUG1_Power.state > 2.0) &&  ((timer1 == NULL) || (timer1?.hasTerminated))) {
			timer1 = createTimer(now.plusSeconds(20)) [|
				timer1 = NULL
			]
			internalState1 = 0;
			logInfo("SleepingRoom Main Light", "timer activated")
		} 
		else if ((internalState1 == 0) && (!timer1?.hasTerminated) && (FF_SLEEP_PLUG1_Power.state <= 5.0)) {
			logInfo("SleepingRoom Main Light", "Off within timer period")
			internalState1 = 1;	     	
		}
		else if ((internalState1 == 1) && (!timer1?.hasTerminated) && ((FF_SLEEP_PLUG1_Power.state > 5.0))) {
			logInfo("SleepingRoom Main Light", "2nd On within timer period")
			internalState1 = 2;	     	
		}
		else if ((internalState1 == 2) && (!timer1?.hasTerminated) && (FF_SLEEP_PLUG1_Power.state <= 5.0)) {
			internalState1 = 255
			timer1?.cancel
			timer1 = NULL
            FF_Sleep_Sonos_Stop.sendCommand(ON)
			logInfo("SleepingRoom Main Light", "Pause - timer canceled")
		}
		lock.unlock
end

rule "SleepingRoom - Pause Sonos on DeskLamp2"
	when 
		Item FF_SLEEP_PLUG2_Power received update
	then

        lock.lock 
 
        logInfo("Sleeping Room Main Light Off - rule fired - 1st plug", Wall_Plug2_Power_FF_Sleep.state.toString )

		// The Sonos player is set to pause if within 15 seconds one of the two desk lamps will be going on twice 
		if  ((FF_SLEEP_PLUG2_Power.state > 4.0) &&  ((timer2 == NULL) || (timer2?.hasTerminated))) {
			timer2 = createTimer(now.plusSeconds(20)) [|
				timer2 = NULL
			]
			internalState2 = 0;
			logInfo("SleepingRoom Main Light", "timer activated")
		} 
		else if ((internalState2 == 0) && (!timer2?.hasTerminated) && (FF_SLEEP_PLUG2_Power.state <= 5.0)) {
			logInfo("SleepingRoom Main Light", "Off within timer period")
			internalState2 = 1;	    
		}
		else if ((internalState2 == 1) && (!timer2?.hasTerminated) && ((FF_SLEEP_PLUG2_Power.state > 5.0))) {
			logInfo("SleepingRoom Main Light", "2nd On within timer period")
			internalState2 = 2;	     	
		}
		else if ((internalState2 == 2) && (!timer2?.hasTerminated) && (FF_SLEEP_PLUG2_Power.state <= 5.0)) {
			internalState2 = 255
			timer2?.cancel
			timer2 = NULL
			//Sonos_FF_Sleep.sendCommand("PAUSE")			
			logInfo("SleepingRoom Main Light", "Pause - timer canceled")
		}
		lock.unlock
end

There should not be an issue with this (I have some of both too).

I suggest you install and use VS Code for editing your rules. Change NULL to null (they mean different things). This might solve the problem. There had also been an issue with rules failing after modifying item files. I think it was fixed in 2.2 though. I’m still in the habit of shutting down OH when modifying them.

Ok. Let’s see. I made the change NULL -> null and replaced the comparison with null by === , rebooted OH. Rules seem to work… I will not make any changes let’s in the next couple of hours.

Ok. It seems to stop working after the following rule has been executed

ule "SleepingRoom Main Light Off"
    when
        Item FF_SLEEP_PLUG1_Power received update or
        Item FF_SLEEP_PLUG2_Power received update
    then
        logInfo("Sleeping Room Main Light", FF_SLEEP_LIGHT.state.toString )
        logInfo("Sleeping Room Main Light", FF_SLEEP_PLUG1_Power.state.toString )
        logInfo("Sleeping Room Main Light", FF_SLEEP_PLUG2_Power.state.toString )
        
		if ((FF_SLEEP_LIGHT.state  == ON) && ((FF_SLEEP_PLUG1_Power.state > 2.0) ||  (FF_SLEEP_PLUG2_Power.state > 2.0))) {
			FF_SLEEP_LIGHT.sendCommand(OFF)
            FF_Sleep_Sonos_PlayPlaylist.sendCommand("Sleep")
            FF_Sleep_Sonos_Volume.sendCommand(15)
            FF_Sleep_Sonos_SleepTimer.sendCommand(1800)
		}
		
end

I realized that FF_SLEEP_LIGHT is the name of the thing and the name of an item. Could that be the reason?

It could well be.
Rename one of them and try again.