We have moved at community.getvera.com

Author Topic: Virtual switch and luup code activating scenes based on available power  (Read 1284 times)

Offline turby

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
Can someone please help me with the code required?  ???

« Last Edit: April 01, 2015, 03:24:11 pm by turby »

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-13
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:
  • Setting up a ten-second cycle using luup.call_delay(...)
  • Reading the remote data using luup.inet.wget(...)
  • Reacting to a failed read
  • Parsing the returned string to extract the data using string.match(...)
  • Managing tables of values with push-down of latest values
  • Calculating averages of table values
  • Reading state of the virtual switch with luup.variable_get(...)
  • Calculating required scene number based on averages and states
  • Running required scene using luup.call_action(...)

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.