Am trying to pass a state of ON, OFF to a lambda. However, its not working as desired.
val smallroom_growlights_lambda_stateChange = [ state newState |
logInfo("lamdba", "executing lambda to change Growlights state to ", newState)
if ( newState == ON)
{
coldRoom_Small_RightGrowLight.sendCommand(ON)
}
else
{
coldRoom_Small_RightGrowLight.sendCommand(OFF)
}
]
Calling code
val ss = smallroom_growlights_lambda_stateChange.apply(OFF)
error
[ERROR] [enhab.core.automation.module.script.internal.handler.AbstractScriptModuleHandler] - Script execution of rule with UID āColdRoom-GrowLights-1ā failed: Unknown variable or command ā==ā; line 10, column 7, length 14 in ColdRoom-GrowLights
state isnāt a type. For one, all types in Rules DSL start with a capital letter. Iām surprised that itās not completely barfing on this when the code is loaded because itās not syntactically correct since state isnāt anything as far as Rules DSL is concerned. But thatās Rules DSL for youā¦
Since you are only passing ON or OFF to this lambda you may as well be as specific as possible.
val smallroom_growlights_lambda_stateChange = [ OnOffType cmd |
Also avoid using the same name as the implicit variables. newState might already exist as a variable and by redefining you you might be covering that up.
Finally, I assume this is just an experiment or something that will be expanded later. As written all this procedure is a whole lot of complication adding not benfit. Even if you kept it in the procedure it could be reduced to
val smallroom_growlights_lambda_stateChange = [ OnOffType cmd |
logInfo("lamdba", "executing lambda to change Growlights state to ", cmd)
coldRoom_Small_RightGrowLight.sendCommand(cmd)
]
If you are using a procedure because you send the same command to lots of lights, itās better to use a Group. Commands sent to Groups are forwarded to all members of the Group.
Finally, if you are looking at trying to code in this way, you will be far happier with any of the other rules languages options over Rules DSL.
val smallroom_growlights_lambda_stateChange = [ OnOffType cmd |
logInfo("lamdba", "executing lambda to change Growlights state to ", cmd) <===
coldRoom_Small_RightGrowLight.sendCommand(cmd)
]
Anything but Rules DSL. Jython and Python should probably be treated as experimental. But the rest have complete access to the full OH API.
JS probably has the most users. Blocky is got if you are not a programmer already. jRuby is terse and able to do a lot with very little code.
If you mean have some complete rules written in Rules DSL and other complete rules written in something else, yes. If you mean something like accessing JS features from a DSL rule or vise versa, no.