LUA code as scene trigger

Good afternoon!

I have developed a script in lua that retrieves information from an API. Now I want Vera Edge to check the output (pool?) of this program so when a new event is received from the API, it triggers a scene. I am stuck with this, could you please give me a small advice/guidance about what would be the next step?

(I have read that you can make vera check the status of a variable, but I am lost about how to set the output of my program as the value of a variable of a device. Should I create a new plugin or just add my code to the implementation files of switches in vera? (I will only control that kind of device))

Thank you for your time :slight_smile:

Is your API written in LUA that is running in the LuaUPnP image ( Vera’s main program where Zwave handling and Plugins are running) ?

If so then you can use the luup.XXXX functions to read/write variables attached to a device.
Writing to a variable with a new name and/or service ID will create a new variable.Variables are uniquely identified by the deviceID, serviceID, and Name attributes.

If you are an external program you can make a web request that remotely writes a variable with a specified value.

I just call the API, I have no access to its code.

Right now what I have done is set a scene that runs every 2 seconds and I included my LUA code in it, so now every 2 seconds it executes a big piece of LUA code that include functions that do a HTTP GET and POST (using https.request ) to an endpoint, parses the recent events received from it and if this recent events match my rules it returns true , executing the actions of the scene.
For me this solution does not seem very elegant nor efficient, but it works. After this I will create a plugin to create the scenes so it adds it automatically throw the plugin interface (that is my plan, we will see how it ends).

Is Having a scene running every second bad for Vera Edge? There would be any problem with this, like worse performance or overheating?

Thank you for your help

If you create a plugin … you will not need the scenes …
The plugin get’s a function call when it starts … there you can call luup.call_delay to schedule your processing.

At the end of your processing you will call this again to schedule your processing.

See:
http://wiki.micasaverde.com/index.php/Luup_Lua_extensions

To communicate with other Plugins or code in Vera … you can write to Plugin Device variables using luup.variable_set and define triggers that can be used (The trigger (actually called events) definitions are defined in the D_XXXX.json file for the plugin XXX) by others to run scenes when your variable changes it’s Plugin Device variables.