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.