Use a startup lua function to return a string to Reactor Expressions/Variables

Hey Patrick,
That long winded title says most of what I’m trying to do. I have a function in my startup lua that returns a concatenated string of device names of faulted zones on my unarmed alarm panel. I’d like to store the string to a variable in reactor so that, when the sensor is triggered, I can send the list to my tts engine (alexa).

Is there a way to do this in reactor, as when I tried to call the global function defined in my startup, reactor could not see the function.


I solved this by adding a UPNP service variable, holding faulted zone names, to my alarm panel plugin. The variable is populated and set in the plugin by a hack that monitors the stack of faults in a table, pushing and popping faults to the service variable in real time. In turn, this allows me to retrieve an accurate faulted zone list into a Reactor expression variable for use when the Reactor sensor trips. The sensor then sends the variable list of zones to my tts.

Still, I think access to startup lua functions by Reactor would be a useful extension of the plugins’ functionality…

I’m sorry, I completely missed responding to your post initially… it’s been a hectic week at Casa Rigpapa.

On Vera Luup, the startup and scene Lua run in a separate environment from the plugins, and each plugin runs in its own environment. It is therefore not possible for globals defined in one environment to be visible to another, and I don’t see that changing. It’s actually a Very Good Thing in terms of both security and system stability (and I can make the argument that it really doesn’t go far enough, but it’s a good start).

The previously recommended approach for this is to move your startup Lua code to a Lua module, and require that Lua module in your startup Lua and scene Lua as needed, so you can then call its functions as module members. Likewise, you can require the module in your ReactorSensor’s “Run Lua” actions. This gives you re-use of the code. It will not give you re-use of globals, however, this is probably a Good Thing as well, as passing data around in globals is generally considered to be a poor programming practice and to be reserved only for very limited circumstances.

Ok thanks, makes sense.

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules