which approach for this? (monitoring solar & switching devices on/off)

About to automate some things in LUUP for the first time - Any advice would be appreciated before I start. Note I’m asking here not about the automation logic, as I can development this, but more how to package/set this up within a Vera environment.

REQUIREMENTS (What I’m going to try to do)

  • Background - I’m already monitoring my Solar Power generation & Home Power usage, plus have some devices I can turn on/off. Have already got basic LUUP code together to prove I can do this.
    (a) Monitor home use of power and keep it (roughly) within the about of Solar power being generated, for key “optional” devices such as spa heating etc
    (b) Define modes & allow selection of which mode to be in. For example the automation: OFF, Optimized for Spa Heating, Optimized for Pool Heating etc
    (c) Regularly check (every 1 minute?) to see status & whether any further changes are required
    (d) Email notification if the automation script notes something wrong (e.g. switch not responding), or just for status updates
    (e) Want to track how long devices have been on (e.g. Pool Filter) to ensure it runs for at least a minimum
    (f) Keep a simple database/datafile of the readings/decisions the plugin makes. Separate from main Vera logfile

QUESTIONS:

[ol][li]Where should I put my code? The fact I have requirement (a) whereby I want to change the mode of the automation tool would imply I need to develop it as a plugin? Is this correct. Such that when the plugin is deployed it would create an input selection mechanism for the mode which the user can change as required?[/li]
[li]If I develop my core decision code in a test area in Vera initially, it should work when I migrate it to a plugin right? There’s nothing different/special for LUA code running as a plug?[/li]
[li]Would Vera/Zwave controller typically support a mode switch, i.e. that could have multiple values to select from, effectively would be radio buttons on a web page[/li]
[li]How would I do the 1 minute check? Do it in LUUP using a function (call_delay??), or use a Vera schedule to somehow trigger the Plugin?[/li]
[li]Can one tell straight away if a switch change request actually worked? That is, if I’m using the “call_action” function, will the return values be accurate. I thought it might take a second or two before one would be sure the switch flipped, and if so, does “call_action” effectively wait to verify this?[/li]
[li]Email notifications? Is there a plugin for this? I did see do “smtp = require(“socket.smtp”)” but didn’t see whether this was based on a plugin, or they manually downloaded some additional code to the Vera[/li]
[li]Are the LUA variables in a plugin persistent across multiple calls (each minute)? That is can I use a normal local variable to store how long device X has been on for within the day so far? For requirement (e). Or is there a better approach here? [/li]
[li]What’s the best way to implement (f)? Does logging allow me just write log statements from the plugin to a separate log file to the main Vera logfile[/li][/ol]

Hi (again),

Personally and now I’ve got to grips with it, I’d use PLEG to do this lot - many examples are available similar to those you need. It took a while to get used to the logic in PLEG, but now I cannot understand why that was.

You’re going to have to be careful though with switching on/off high ampage devices such as spa/swimming pool at random intervals if you’re linking this to your PV array. I’ve done the same and found that there were issues with the repetitive on/off/on on the devices when the sun went behind a cloud and the kWh dropped below X. In the end I store my electric back on the grid and consume from there when I need it. In the UK we get paid 5x to generate than the cost to buy so works out in my favour anyway.

Cheers

David

I’ll have a look at PLEG then before I start then thanks - but can you develop custom decisions with it? (e.g. including hysteresis, checks & balances based on time, what else is running, how long switch X has already been on during the day, ability for the user to specify what mode they want it in and then the code/decisions change based on this?) Maybe a hard question to answer without looking through PLEG in detail, but just wondering if there’s an obvious barrier with PLEG I would hit with any of these items?