Help with scene Luup code

I have some code I found on the internet a few years ago (thanks to whoever wrote it). I now want to modify it slightly but, not being a programmer by trade, I find I do not understand the last two “return” statements. My understanding is that between 10:00 and 14:00 it should return TRUE (and run the scene) and outside that time frame it should return FALSE. Can anyone help me here?

local pStart = "10:00"   -- Start of time period
local pEnd = "14:00"     -- End of time period
local allow = true       -- true runs scene during period, false blocks it
local hS, mS = string.match(pStart,"(%d+)%:(%d+)")
local mStart = (hS * 60) + mS
local hE, mE = string.match(pEnd,"(%d+)%:(%d+)")
local mEnd = (hE * 60) + mE
local tNow = os.date("*t")
local mNow = (tNow.hour * 60) + tNow.min
if mEnd >= mStart then
     return (((mNow >= mStart) and (mNow <= mEnd)) == allow)
else 
     return (((mNow >= mStart) or (mNow <= mEnd)) == allow)
end

Thanks.

I have changed the formatting of the code in your post so it displays correctly.

To answer your question, you should look here

I’m sure that @rigpapa would be happy to answer any questions you may have on this particular topic.

Bingo! Now I understand. Thanks akboor. Thanks also to rigpapa for the detailed explanation.

Hi,

You are not saying the firmware you are doing this on, but UI7 has this type of time ranges build in for scenes.

Cheers Rene

Hi,

Yes it’s UI7 on a VeraPlus.

The intention of the code is to only run the scene, when triggered, between the two times pStart and pEnd. If triggered at any other time the scene should not run. I cannot see how I can do this using the scene editor alone. Or maybe I am just missing something?

Cheers.

Hi @kennedyj,

When configuring the Scene trigger, click the clock icon. Then tick the Restrict the trigger to certain times checkbox and you will get the restrictions on time and days of the week pop up. This should do the trick in most scenarios.

Cheers Rene

1 Like

Thanks Rene!

My only excuse for not seeing this earlier is the fact that I can never find any vera documentation that is relevant to what I am looking for or is years (yes, I mean years) out of date and totally useless. Another case in fact is the “My Modes” in UI7 - this confuses me and I cannot find any documentation that states in simple terms what it does and how I configure it.

I am bitterly disappointed with the VeraPlus I have recently been migrating to. The exact same configuration worked flawlessly for several years on my old vera 3 (after lots of frigging around). Since going to the VeraPlus I have had problem after problem. Support never seem to help so I have given up on them. Documentation is scattered around the web and is mostly out-of-date. UI7 is a nightmare with so much white space I am constantly scrolling up and down. If I click on “Poll now” or “Stress test” where is the feedback as to what is going on? I am having to buy two replacement switches which worked perfectly on vera3/UI5 but constantly drop off line on the VeraPlus/UI7 - I could go on… How vera expect to sell this stuff to Joe Public defies belief - you have to become an “expert” to get it working properly a lot of the time.

Anyway, sorry for the rant but I feel better now :smile:

1 Like