Hi All,
I am running OpenHab 2.1.0
I am looking for a design pattern that would fit the following need:
Outcome: Would like to have a “lock” to prevent people from changing certain switches. Ideally, when a switch it triggered (sendCommand), the command action would be canceled if the lock is not unlocked.
I have the lock portion all figured out with Habpanel and a Switch called “KP_Lock_State” which is ON or OFF.
I have 4 switches (ozw_PowerSwitch3 through ozw_PowerSwitch6) which are all defined in a group called “gSecurelyManage”.
Firstly, is a rule with a proxy set of switches the best approach? Reading online, it seems to be the only way to intercept a command to my switches.
Secondly, I am having troubles using a group for the trigger in a rule. This is my setup:
rule "Keypad: Intercept Command"
when
Item gSecurelyManage received command
then
logInfo("Keypad", "Here...")
// val trigger = triggeringItem
val trigger = gSecurelyManage.members.sortBy[lastUpdate].last as SwitchItem
logInfo("Keypad", "A managed item was changed to: " + trigger.state.toString)
logInfo("Keypad", " Name: " + trigger.name.toString)
logInfo("Keypad", " Old state: " + trigger.previousState(true, "mysql").state.toString)
// logInfo("Keypad", " Old state: " + previousState)
...
end
The persist setting is:
gSecurelyManage : strategy = everyChange
The item config is:
Group:Switch gSecurelyManage
Switch ozw_PowerSwitch3 "Entertainment 3 [%s]" <switch> (ozw_id3,gSecurelyManage) { ... }
Switch _ozw_PowerSwitch3 "Entertainment 3 [%s]" <switch> { ... }
...
I have tried using the “triggeringItem” implicit variable, but it always returns “ozw_PowerSwitch6” as the name.
I have also tried the trick “gSecurelyManage.members.sortBy[lastUpdate].last” but it also returns “ozw_PowerSwitch6” each time.
I also can’t get the previous state, also tried the implicit variable “previousState”.
If I got the logInfo() lines working, i can figure out the rest.
Thanks for your help,
Paul