Combine number and rollershutter items into a single item for use with rule?

I am working on some rules to control lighting based on zwave motion detectors. I would like the amount of time after which the lights are turned off due to no motion to be chosen by the user. The UI is the openHAB client running on a Nexus 7 so I’m using items, a sitemap and rules to control the timeout. The current setup is as follows:

Items:

Number              lighting_kitchen_PIR_timeout_minutes        "Kitchen motion lighting timeout"
Rollershutter       lighting_kitchen_PIR_timeout_proxy          "Kitchen motion lighting timeout"

Sitemap:

Text		item=lighting_kitchen_PIR_timeout_minutes	label="Motion Lighting Timeout [%.0f mins]"
Switch		item=lighting_kitchen_PIR_timeout_proxy		label="Motion Lighting Timeout"

Rule:

rule "Set kitchen PIR timeout Command Rule"
when
   	Item lighting_kitchen_PIR_timeout_proxy received command
then
	var Number current_val
	var Number new_val
	logInfo("Rules", "Kitchen Lighting PIR timeout rollershutter received update" )
	current_val = lighting_kitchen_PIR_timeout_minutes.state
	logInfo("Rules", current_val.toString )
		
	if (receivedCommand.toString == "UP" )
	{
		switch current_val
		{
			case null : new_val = 1
			case 0 : new_val = 1
			case 1 : new_val = 2
			case 2 : new_val = 5
			case 5 : new_val = 10
			case 10 : new_val = 20
			case 20 : new_val = 30
			case 30 : new_val = 30
			default : new_val = 1
		}
	}
	if (receivedCommand.toString == "DOWN" )
	{
		switch current_val
		{
			case null : new_val = 1
			case 0 : new_val = 1
			case 1 : new_val = 1
			case 2 : new_val = 1
			case 5 : new_val = 2
			case 10 : new_val = 5
			case 20 : new_val = 10
			case 30 : new_val = 20
			default : new_val = 1
		}
	}
	logInfo("Rules", new_val.toString )
	lighting_kitchen_PIR_timeout_minutes.sendCommand(new_val)
end

Is it possible to combine the two functionality of the two number and rollershutter items into a single item? Do I really need two items for this to work? If I could use a single item then I could add it to a “PIRTimeout” group and use a single rule for any timeout rollershutter item by using “Member of received command” trigger for the rule and referencing the implicit triggeringItem variable in the rule. I think.

No, they represent two completely orthogonal pieces of information, i.e. the state of the rollershutter and the amount of time to wait for your timer.

Yes.

No, even if you could use one Item this doesn’t make sense. However, Design Pattern: Associated Items may be what you are really looking for.

After some experimentation I’ve found the following solution:

Items:

Group               gLightingMotionTimeouts

Rollershutter       lighting_kitchen_PIR_timeout_minutes    "Kitchen motion lighting timeout"   (gLightingMotionTimeouts)   {autoupdate="false"}
Rollershutter       lighting_blueroom_PIR_timeout_minutes   "Blue room motion lighting timeout" (gLightingMotionTimeouts)   {autoupdate="false"}
Rollershutter       lighting_bathroom_PIR_timeout_minutes   "Bathroom motion lighting timeout"  (gLightingMotionTimeouts)   {autoupdate="false"}

Rule:

rule "Set motion lighting timeout rule"
when
   	Member of gLightingMotionTimeouts received command
then
	var Number current_val
	var Number new_val
	logInfo("Rules", "Lighting motion timeout rollershutter received command (" + receivedCommand.toString + ")."  )
	logInfo("Rules", "Triggering item name is (" + triggeringItem.name + ")."  )
	current_val = (triggeringItem.state) as Number
	logInfo("Rules", "Current timeout value is " + current_val.toString )
		
	if (receivedCommand.toString == "UP" )
	{
		switch current_val
		{
			case null : new_val = 1
			case 0 : new_val = 1
			case 1 : new_val = 2
			case 2 : new_val = 5
			case 5 : new_val = 10
			case 10 : new_val = 20
			case 20 : new_val = 30
			case 30 : new_val = 30
			default : new_val = 1
		}
	}
	if (receivedCommand.toString == "DOWN" )
	{
		switch current_val
		{
			case null : new_val = 1
			case 0 : new_val = 1
			case 1 : new_val = 1
			case 2 : new_val = 1
			case 5 : new_val = 2
			case 10 : new_val = 5
			case 20 : new_val = 10
			case 30 : new_val = 20
			default : new_val = 1
		}
	}
	logInfo("Rules", "New timeout value is " + new_val.toString )
	triggeringItem.postUpdate(new_val)
end

This solution takes advantage of the fact the rollershutter item can hold a variable between 0 and 100. Autoupdate is turned off for the rollershutter items to prevent the default behaviour of pressing on the up and down buttons in the the Android client from resetting the value to either 0 or 100.