witam
https://manuals.fibaro.com/home-center-3-lua-scenes/
blisko konca jest to, czego szukasz
lub:
function between(timestr)
local dayMap = {["1"] = 1, ["2"] = 2, ["3"] = 3, ["4"] = 4, ["5"] = 5, ["6"] = 6, ["7"] = 7}
local smap = {
["Sunset"] = "sunsetHour",
["Sunrise"] = "sunriseHour",
["Evening"] = "sunsetHour", -- SunsetTwilight
["Morning"] = "sunriseHour"
}
local function getGlobalVariable(v)
local value = fibaro.getGlobalVariable(v)
return value
end
local function split(pString, pPattern)
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table, cap)
end
last_end = e + 1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
local function trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
local function offset(s, o, p)
if (not (o and p)) or o == "" then
return s
end
local h, m = s:match("(%d+):(%d+)")
local t = 60 * h + m + (o == "+" and p or -tonumber(p))
return string.format("%02d:%02d", math.floor(t / 60), t % 60)
end
local function sec2hmStr(hms)
local h, m, s = math.floor(hms / 3600), math.floor((hms % 3600) / 60), hms % 60
return string.format("%02d:%02d", h, m)
end
local function isnull(name, val, action)
if (val == nil) then
if (_ENV[name] ~= nil) then
local result = _ENV[name]()
if type(result) == "boolean" and result then
val = os.date("%H:%M", os.time())
elseif result then
val = result
else
val = ""
end
end
end
return val
end
local function betw(interv)
local dt, start, stop = os.date("*t"), interv:match("^([%S%a0-9%.%:]+) ?(.*)")
if not start then
return false
end
stop = stop == "" and start or stop
local d1, h1, m1 = start:match("^([%S%a%.]-)%.?(%d+):(%d+)$")
local d2, h2, m2 = stop:match("^([%S%a]-)%.?(%d+):(%d+)$")
d1 = d1 == "" and (dt.wday == 1 and 7 or dt.wday - 1) or dayMap[d1]
d2 = d2 == "" and d1 or dayMap[d2]
local d = dt.wday == 1 and 7 or dt.wday - 1
if not (d >= d1 and d <= d2) then
return false
end
m1, m2, t = h1 * 60 + m1, h2 * 60 + m2, dt.hour * 60 + dt.min
if (m1 <= m2) then
return m1 <= t and t <= m2 -- 01:00-02:00
else
return m1 <= t or t <= m2 -- 23:00-21:00
end
end
timestr =
timestr:gsub(
"$(%w+)([%+%-]?)(%d*)",
function(s, o, p)
return offset(isnull(s, smap[s] and fibaro.getValue(1, smap[s]) or getGlobalVariable(s), o, p))
end
)
for _, interv in ipairs(split(timestr, ",")) do
if betw(trim(string.gsub(interv, "%.%.", " "))) then
return true
end
end
return false
end
if between("$Sunset..$SunsetTwilight") then
end
lub
if between("19:00..06:00") then
end