Termite Season

I have set up some basic scenes to turn on exterior lights at sunset and off later at night. Termites will swarm in our area (coastal SC) from sunset to midnight when warm and humid. Keeping lights off is recommended.

Vera’s basic scene editor does not provide a way to prevent my light scenes during a calendar date (irrespective of year) (e.g. May 5 to June 20) (seems like this or an app would exist)

Searching on these forums, there seems to be a few ways of doing this:

  1. trigger off of an event in a google calendar via Google Calendar 3. This requires setting up a google calendar which is not hard, but now I have something outside Vera I have to configure and maintain.
  2. trigger off of an outside temperature and humidity via MiOS Virtual Outdoor or DarkSky. there are threads about Wunderground but I do not see that in the Vera Apps store. Which weather service do you use or prefer (easiest to use, best localization, accuracy, etc.)?
    I don’t have specific temperature and humidity trigger points but can contact the local extension service.

Also, which of the above can be implemented reliably in the basic Vera scene system. I can go with Lua, Pleg, or other but would rather keep it as simple as possible.

Thanks!

Take a look at Reactor. I think it will do all you want. There are videos here.

Yep, Reactor.

C

That’s very easy to do. Look at this thread for more examples

I will look at Reactor, but will work with the conditional scene execution with a date range.

For the Generic date range method, instead of
local allow = true – true runs scene during period, false blocks it
to prevent the scene from running, I would have in my code
local allow = false
Correct?
I assume ‘local allow =’ is creating and assigning a constant.
I could also put ‘local block = false’ and use the word ‘block’ in the return statements (2 locations) to make my code more readable - the code blocks operation during a date range. is this understanding correct?

when I paste the code into Vera’s Luup tab, there is no formatting. It is all run together - as it is in the forum thread where I copied. I reformatted in a text editor to help understand.
Is the formatting an issue?

I usually have a very simple code like this in my startup LUA (formatted for better understanding):

function isDateInRange(mdStart, mdEnd)
    local smS, sdS = string.match(mdStart, "(%d+)%/(%d+)")
    local smE, sdE = string.match(mdEnd, "(%d+)%/(%d+)")
    local mS = tonumber(smS)
    local dS = tonumber(sdS)
    local mE = tonumber(smE)
    local dE = tonumber(sdE)
    local tNow = os.date("*t")
    local mN = tNow.month
    local dN = tNow.day
    if(mE > mS) or((mE == mS) and(dE >= dS)) then
        return(((mN > mS) or((mN == mS) and(dN >= dS))) and((mN < mE) or((mN == mE) and(dN <= dE))))
    else 
        return(((mN > mS) or((mN == mS) and(dN >= dS))) or((mN < mE) or((mN == mE) and(dN <= dE))))
    end
end

And then I simply have this code in date-based scenes:
return isDateInRange("10/01", "06/01")

I use it for a very similar reason (to prevent bugs from staying around the house), so during winter time I turn on lights near the house, while on summer time I use lights far from the doors/windows, for mosquitoes and such.

did you mean “date-based scenes”? not data?

Any tutorials or videos on using a start-up lua? I find threads but they are all troubleshooting, not how to get started.

Yep, auto correction at work.

I’m not sure what kind of tutorial you’re searching for, it’s basically under apps, develop apps, then Edit Startup Lua. Just past this code and it will be merged with all the code in your scenes - so you’re basically reusing code from a central point. You can also past it directly in the scene code, but this will void the advantage of having it in a central place.

That’s a useful function to have around … added it to one of my lua packages. Thanks!

Follow up question: is it ok to have formatting in the vera lua container? or does it have to be all run together as shown in the source thread?

You can and should format. What’s shown in that thread won’t work because of the (broken) formatting.

Also please read this: The "allow" meme in scene scripts must die! - Scene Scripting - Ezlo Community

@rigpapa
Thanks!

All:
Is there a set of formatting rules for Lua? e.g. in yaml, indents are critical.
If find some link such as these, and assume this applies to the Lua in Vera. I think it says formatting is recommended for readability (very much agree!)
Ref manual
style guide

Other than what’s enforced by the syntax of the language, there’s no real standard that I’m aware of. You need to develop a style that works for you. The biggest error in the other post you referenced is that there are no line breaks at the ends of the lines, which results in unreadable code and, worse, the first comment consumes the entire block of text (it’s all part of the comment because there’s no break), so almost none of the code is actually executable.

Just make your code readable. You might use a tool like luacheck also, which is a lint for Lua (a code checker that will draw your attention to bad habits and errors).

Once you have decided on your syntax, may I suggest @rigpapa’s LuaView plug-in? This will display ALL the LUA codes in your system and where they’re used. This makes debugging much easier since you can see all your LUA in one display.