I’m working on setting up my first Lambda to use for making execution of a bunch of switch scenes easier. I’m using the HomeSeer devices which support the double/triple tap options. To make life easier, I’d like to setup a lambda to re-use for multiple different switches, rather than the messy If statements and copying code over multiple times and editing each unique aspect. For some reason, this is not running, but I’m not seeing any errors either helping to point out what I may be missing.
Any help is greatly appreciated, as I’ve never used Lambdas before and seen some difficulty folks have had here even when they’ve used them before.
// Switch scene Lambda
val Function7 hsScene = [
NumberItem sceneId,
Procedure0 singleOn,
Procedure0 singleOff,
Procedure0 doubleTapOn,
Procedure0 doubleTapOff,
Procedure0 tripleTapOn,
Procedure0 tripleTapOff |
switch(sceneId.state) {
case 1.0: {if (singleOn != null) singleOn.apply() }
case 2.0: {if (singleOff != null) singleOff.apply() }
case 1.3: {if (doubleTapOn != null) doubleTapOn.apply() }
case 2.3: {if (doubleTapOff != null) doubleTapOff.apply() }
case 1.4: {if (tripleTapOn != null) tripleTapOn.apply() }
case 2.4: {if (tripleTapOff != null) tripleTapOff.apply() }
}
]
////////////////////////* SWITCH SCENE FUNCTIONS *////////////////////////
rule "Master Bathroom Switch Automation"
when
Item master_bathroom_dimmer_scene changed
then
hsScene.apply(master_bathroom_dimmer_scene,
null, // No single tap On
[| //If 1 tap down, turn off both vanities and the master bath switch
sendCommand(left_vanity_switch, OFF)
sendCommand(right_vanity_switch, OFF)
sendCommand(master_bathroom_dimmer, 0)
logInfo("rules.automation", "Master Bathroom - All OFF rule executed (1 Tap DOWN)")],
[| //If 2 taps up, enable both vanity lights and master bath dimmer to 100%
sendCommand(left_vanity_switch, ON)
sendCommand(right_vanity_switch, ON)
sendCommand(master_bathroom_dimmer, 100)
logInfo("rules.automation", "Master Bathroom - All ON rule executed (2 Taps UP)")],
[| //If 2 taps down, then turn both vanity off and set master bath dimmer to 10%
sendCommand(left_vanity_switch, OFF)
sendCommand(right_vanity_switch, OFF)
sendCommand(master_bathroom_dimmer, 10)
logInfo("rules.automation", "Master Bathroom - Dim rule executed (2 Taps DOWN)")],
null, // No triple On
null // No triple Off
)
end