Lambda Error

Hi,

what’s wrong with it?

import org.openhab.core.library.types.*
import org.openhab.core.types.*

// 2017-02-09 22:12:27.872 [ERROR] [o.o.c.s.ScriptExecutionThread ] - 
// Error during the execution of rule 'rule_ardu02_out_20_13_P_06_07_receive_update_UP': 
// The name '<XFeatureCallImplCustom>.state' cannot be resolved to an item or type.

val org.eclipse.xtext.xbase.lib.Functions$Function1 rollo_lambda = [
    org.eclipse.smarthome.core.library.items.RollershutterItem rsi |

    	if (rsi.state == UP)			//  UP
    	{
		
			postUpdate(ardu02_inp_20_11_06_stat, "XX UP XX")

    	}
    	else if (rsi.state == DOWN)		//  DOWN
    	{
		
			postUpdate(ardu02_inp_20_11_06_stat, "XX DOWN XX")

    	}
    	else							// STOP
    	{
		
			postUpdate(ardu02_inp_20_11_06_stat, "XX STOP XX")

    	} 
]



rule "rule_ardu02_out_20_13_P_06_07_receive_update_UP"
when
    Item ardu02_out_20_13_P_06_07 received command
then
	rollo_lambda.apply(ardu02_out_20_13_P_06_07)
end

Add some logInfo to see what the state of your Item is before you call the Lambda, and inside it

The problem seems to be “rsi”, not the postUpdate.
I tried with logDebug … it worked, BUT as soon as i insert the if with rsi, the error appears.
The items are all existing, if i use it in a ‘normal’ rule, than it works.

OH2 ? You probably don’t need the full path for RollershutterItem

No, OH 1.8.3

Ah, you’ll be wanting this -
org.openhab.core.library.items.RollershutterItem

The Designer says: org.openhab.core.library.items.RollershutterItem cannot be resolved to a type.

But i do not got erros in logs.

BUT … it seemded that UP/DOWN/STOP is not working in lambda.

ardu02_out_20_13_P_06_07 received command UP
ardu02_inp_20_11_06_stat state updated to XX  XX
ardu02_inp_20_11_06_stat state updated to XX STOP XX


ardu02_out_20_13_P_06_07 received command DOWN
ardu02_inp_20_11_06_stat state updated to XX  XX
ardu02_inp_20_11_06_stat state updated to XX STOP XX


ardu02_out_20_13_P_06_07 received command STOP
ardu02_inp_20_11_06_stat state updated to XX  XX
ardu02_inp_20_11_06_stat state updated to XX STOP XX

This is the code

val Functions$Function1 rollo_lambda = [
    org.openhab.core.library.items.RollershutterItem rsi |

// RollershutterItem

		postUpdate(ardu02_inp_20_11_06_stat, "XX  XX")

    	if (rsi.state == UP)			//  UP
    	{
		
			postUpdate(ardu02_inp_20_11_06_stat, "XX UP XX")

    	}
    	else if (rsi.state == DOWN)		//  DOWN
    	{
		
			postUpdate(ardu02_inp_20_11_06_stat, "XX DOWN XX")

    	}
    	else							// STOP
    	{
		
			postUpdate(ardu02_inp_20_11_06_stat, "XX STOP XX")

    	} 

]

The .state is not what you expect - it is a number representing %
Use logInfo(“testing” , " we have " + rsi.state.toString) to see this

Perhaps you want to trigger your rule on item updated. Or, perhaps you want to pass receivedCommand to your lambda, depending what you are trying to do here.

i want to use the lambda like a function to control multiple RollerShutters.
yes i know that i actually give the lambda only one param, but in future it should be more (by changing FunctionX).
i am in testing stage :slight_smile:

This does the trick

val Functions$Function2 rollo_lambda = [
    org.openhab.core.library.items.RollershutterItem rsi,
    org.openhab.core.types.Command receivedCommand 

rossko57, thanks a lot so far.

now i have to explore how to split Strings on “:” and how to use json as param to lambda to use it there.

why it did not reach “we are here 3”?

val Functions$Function2 rollo_lambda = 
[
    org.openhab.core.library.items.RollershutterItem rsi,
    org.openhab.core.types.Command receivedCommand 
|
	// ardu02_out_20_13_P_06_07

	postUpdate(ardu02_inp_20_11_06_stat, "We are here 1")

	val _NameArray				= rsi.name.split("_")
	val String	_rsiNodeName	= _NameArray.get(0)
	val String	_rsiDirection	= _NameArray.get(1)
	val int		_rsiExpAddress	= _NameArray.get(2)
	val int		_rsiExpBank		= _NameArray.get(3)
	val String	_rsiPinIdent	= _NameArray.get(4) // ignore it
	val int		_rsiRelOnOff	= _NameArray.get(5)
	val int		_rsiRelDirect	= _NameArray.get(6)

postUpdate(ardu02_inp_20_11_06_stat, "We are here 2")

	val String _strPinOutRelOnOff_On	= String::format("pinout:%1$d:%2$d:%3$s:1", _rsiExpAddress, _rsiExpBank, _rsiRelOnOff) // Locale::default
	
postUpdate(ardu02_inp_20_11_06_stat, "We are here 3")

is not compatible with %s

i changed to this

	val String _strPinOutRelOnOff_On	= String::format("pinout:%1$d:%2$d:%3$d:1", _rsiExpAddress, _rsiExpBank, _rsiRelOnOff) // Locale::default

but it will not work. without any errors. “here 3” is still not reached.

now i reach 2a.

	val _NameArray				= rsi.name.split("_")
	val String	_rsiNodeName	= _NameArray.get(0)
	val String	_rsiDirection	= _NameArray.get(1)
	val int		_rsiExpAddress	= _NameArray.get(2)
	val int		_rsiExpBank		= 20 //_NameArray.get(3)
	val String	_rsiPinIdent	= _NameArray.get(4) // ignore it
	val int		_rsiRelOnOff	= _NameArray.get(5)
	val int		_rsiRelDirect	= _NameArray.get(6)

postUpdate(ardu02_inp_20_11_06_stat, "We are here 2")

	postUpdate(ardu02_inp_20_11_06_stat, String::format("%1$d", 12))

postUpdate(ardu02_inp_20_11_06_stat, "We are here 2a")

	val String _strPinOutRelOnOff_OT	= String::format("%1$d", _rsiExpAddress) // Locale::default

postUpdate(ardu02_inp_20_11_06_stat, "We are here 2b")

	val String _strPinOutRelOnOff_On	= String::format("pinout:%1$d:%2$d:%3$d:1", _rsiExpAddress, _rsiExpBank, _rsiRelOnOff) // Locale::default
	
postUpdate(ardu02_inp_20_11_06_stat, "We are here 3")

Maybe the rule language isn’t autoboxing the int values? Replace all int with Integer to see if there is any improvement.

i tried this

	val _NameArray				= rsi.name.split("_")
	val String	_rsiNodeName	= _NameArray.get(0)
	val String	_rsiDirection	= _NameArray.get(1)
	val int		_rsiExpAddress	= _NameArray.get(2)
	val int		_rsiExpBank		= _NameArray.get(3)
	val String	_rsiPinIdent	= _NameArray.get(4) // ignore it
	val int		_rsiRelOnOff	= _NameArray.get(5)
	val int		_rsiRelDirect	= _NameArray.get(6)

postUpdate(ardu02_inp_20_11_06_stat, "We are here 2")

	postUpdate(ardu02_inp_20_11_06_stat, String::format("%1$d", 12))

postUpdate(ardu02_inp_20_11_06_stat, 999)

and i got 999

now i tried with _rsiExpAddress instead of 999 and i got

Error during the execution of rule 'rule_ardu02_out_20_13_P_06_07_received_command': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null

int become red in the designer, Integer not - but String also not, too.

now i tested

	val Integer	_rsiExpAddress	= _NameArray.get(2)
postUpdate(ardu02_inp_20_11_06_stat, _rsiExpAddress)

and i get the “null”-error like above.

the String variables are working well, i tried with _rsiNodeName and i got the correct value.

so i think, the problem is the conversation from .get to int/Integer near the split command.

Log rsi.name to make sure your splitting of it is correct.

Also, every case of postUpdate(item, val) should work better as item.postUpdate(val) because this gives the opportunity to tailor the object to the accepted types of the specific item.

i did before (as i did it with 999) and it works, i took _rsiNodeName.

postUpdate(ardu02_inp_20_11_06_stat, String::format("%1$s", _rsiNodeName))

it seemed to me that val int … = …get(x) is not working as expected, i think there should be a conversation like toInt, but i can not find it.

I think you’re right. Try something like:

val int _rsiExpAddress = Integer::parseInt(_NameArray.get(2))

yes, i am right … :smiley:

just in time i found parseInt, and now, i reach Stage 3 :smiley:

cool output: ardu02_inp_20_11_06_stat state updated to pinout:20:13:6:1

is there a reason why rules are very slow at first start?

Just in time for what?