Pass parameters to functions from actions...I'm missing something

I’m working on a virtual dimmer that controls one rail of a Hunter Douglas TDBU shade. A dimmer seems like the way to go for these, as you can actually get the current state of a shade through the HD gateway (via RS232 or TCP…I am doing the latter).

I have it working. But had coded up the code to write the required commands to the gateway as a function, and when I called that function passing the newLoadlevelTarget as a parameter from the SetLoadLevelTarget action, the Lua engine would complain about trying to do math on a nil object (or something akin to that). When I instead had the action set a plug-in local variable before calling the function with no parameter, and had the function use that variable as its input, I got different errors about trying to do math on an uplevel object…again, roughly.

In the interest of doing something else this weekend (need to bring the irrigation up), I sucked the 16 lines of code required to do the work into the action inline, and that works fine. But the software engineer in me is puzzled how one is supposed to pass parameters into functions from actions in some way that works.

–Richard

When your action code is entered, the arguments are provided as members of the table lul_settings. So if you have an argument newLoadlevelTarget, it will be at lul_settings.newLoadlevelTarget.

It is a good idea to check for nil values in passed arguments:

local newLLT = lul_settings.newLoadlevelTarget or ""

Please look at the code for my Hunter Douglas Platinum Bridge app. It actually implements the Shade Control device which not only has Up/Down/(intermediate)Stop controls but also allows absolute positioning. The app tries to do all of the right things with both the Hunter Douglas protocol as well as the Vera APIs. In particular, when you change a shade, this sets a “load level target” and sends a message to the Platinum Bridge (unless it is busy doing something else, in which case the command goes into the queue until the bridge sends an “all clear” message.) When the bridge sends a “current shade position” message, the plug-in sets that shade’s status, which may take a few seconds.

Gengen