Virtual switch and luup code activating scenes based on available power

Can someone please help me with the code required? ???

This level of polling and processing really needs to be done in a plugin rather than a scene. At the very least the code could be placed in Startup Lua so it starts automatically following a Vera/Luup restart.

Have you already done any Lua coding on Vera? This should not require very advanced code but it will involve these parts:

[ul][li]Setting up a ten-second cycle using luup.call_delay(…)[/li]
[li]Reading the remote data using luup.inet.wget(…)[/li]
[li]Reacting to a failed read[/li]
[li]Parsing the returned string to extract the data using string.match(…)[/li]
[li]Managing tables of values with push-down of latest values[/li]
[li]Calculating averages of table values[/li]
[li]Reading state of the virtual switch with luup.variable_get(…)[/li]
[li]Calculating required scene number based on averages and states[/li]
[li]Running required scene using luup.call_action(…)[/li][/ul]

I would break it down and get each part running before attempting the next stage. I would strongly recommend using ZeroBrane Studio for Vera as a development tool. There is a one-time licence fee but it could save you many hours of trial-and-error debugging.

This is an adventurous project if you haven’t written any Lua for Vera but I don’t see any insurmountable issues.