Rule logic not performed properly?

Now i’m in “production” with two out of three appartments, but while the first (seems) to run without a hazzle, the second is not.

The task is a very simple heating control: when the set-temperature or act-temperature is changed, both are handled, together with the associated valve switch, in a functor. Problem is: while manual inspection of the values implies the valve should be switched on (its normally open), there is never any command sent to the valve after initialization.

The log exerpt:

2015-11-01 15:22:03.958 [INFO ] [runtime.busevents   ] - wbf3_bath_therm0_tempSet state updated to 21.00
2015-11-01 15:22:03.960 [INFO ] [runtime.busevents   ] - wbf3_bath_therm0_tempAct state updated to 21.30
2015-11-01 15:22:03.963 [DEBUG] [al.engine.RuleEngine] - Executing rule 'wbf3_bath_therm0'
2015-11-01 15:22:05.113 [INFO ] [runtime.busevents   ] - wbf3_bath_valve_state state updated to OFF
2015-11-01 15:22:51.849 [INFO ] [runtime.busevents   ] - wbf3_bath_therm0_tempSet state updated to 21.00
2015-11-01 15:23:11.883 [INFO ] [runtime.busevents   ] - wbf3_bath_therm0_tempAct state updated to 21.40
2015-11-01 15:23:11.892 [DEBUG] [al.engine.RuleEngine] - Executing rule 'wbf3_bath_therm0'
2015-11-01 15:25:50.115 [INFO ] [runtime.busevents   ] - wbf3_bath_therm0_tempSet state updated to 21.00
2015-11-01 15:26:10.115 [INFO ] [runtime.busevents   ] - wbf3_bath_therm0_tempAct state updated to 21.60
2015-11-01 15:26:10.118 [DEBUG] [al.engine.RuleEngine] - Executing rule 'wbf3_bath_therm0'

The relevant part from the rules

/*
Functor for handling heating valves 
*/
val org.eclipse.xtext.xbase.lib.Functions$Function3 tempControl = [
	org.openhab.core.library.items.NumberItem set,
	org.openhab.core.library.items.NumberItem act,
	org.openhab.core.library.items.SwitchItem valve  | 

	if (set.state == Uninitialized || act.state == Uninitialized) {
		logDebug("wbfRule", "temperature undefined, exit")
		return false
	}
	
	var Number setValue = set.state as DecimalType
	var Number actValue = act.state as DecimalType
	
	// globals not accessible from lambda
	if (setValue < actValue - 0.1) {
		// valve is normally open: ON -> close valve
		sendCommand(valve, ON);
	} else if (setValue > actValue) {
		// valve is normally open: OFF -> open valve
		sendCommand(valve, OFF);
	}
]

/***************************************************************************

heating

*/

rule "wbf3_bath_therm0"
when 
	Item wbf3_bath_therm0_tempSet changed
	or
	Item wbf3_bath_therm0_tempAct changed
then
	tempControl.apply(wbf3_bath_therm0_tempSet, wbf3_bath_therm0_tempAct, wbf3_bath_valve_state)
end

The “update to OFF” seems to stem from the openHAB initialization sequence. After this, even when the rule logic implies it should be triggered, the valve is NEVER set to ON. Is there something obvious i’m missing???

The items are configured correctly (i can switch the valves by hand via the sitemap).

Problem is: i need ANY workaround as this is the automation for a rented appartment (that should get warm in winter…).

Remove the semicolons in the code; I thought I saw an example of it fixing a rule problem.

damn java habits… thx, i wil do this.

But there’s surely something else to do: the nearly identical item/rule combination SEEM to work in another site.

Also, try adding .floatValue to uses of setValue and actValue when doing comparisons.

1 Like

Fine, i’ll try this. But this raises the question: what is the default conversion applied when two Numbers are used?

Thinking about your suggestion this makes more and more sense: I set up the default for the set-temp to 21 (as integer), setValue is first in the predicate - so when this is the conversion target type in the comparision the values will always be the same.

… seems to make perfect sense. You saved my night!

My thinking exactly. Did it work?

will tell you tomorrow. I am offsite now and have no remote access (yet).

Good luck! Let me know how it goes.

Well - i planned a fast fix session with all your suggestions at the appartment site this morning and: it did not work.

After some hours i came up with this information:

The rules are triggered, but not correctly executed. After some experimentation with log statements i found that changing

var Number setValue = set.state as DecimalType
var Number actValue = act.state as DecimalType

to

var Number setValue = set.state as Number
var Number actValue = act.state as Number

did the job. Casting / converting the number item seemed to fail without any notice in the log, following statements are simply not executed. I don’t dare to think about how to fix / debug a real problem.

An additional problem that got visible after this fix seems to be related to the well known bug (imho) that there’s no valid “availability/startup” semantics when starting openHAB. The respective rules are not properly executed when the initial values are loaded - the GPIO subsystem seems not to be available when the values for the thermostat are established. As there’s no change afterwards, the rules are never executed correctly. There are workarounds using timers, i know, - but this is not really production ready.

I have high hopes for the new rule engine in openHAB2/ESH – complete documentation, ease of debugging, etc.