diff --git a/smartline/commands.lua b/smartline/commands.lua index e3dc884..78ca333 100644 --- a/smartline/commands.lua +++ b/smartline/commands.lua @@ -687,3 +687,28 @@ smartline.register_condition("action", { end, }) + +local function daytime() + local t = minetest.get_timeofday() + return string.format("%02d:%02d", math.floor(t*24) % 24, math.floor(t*1440) % 60) +end + +smartline.register_condition("rtc", { + title = "Read RTC", + formspec = { + { + type = "label", + name = "lbl", + label = "Hint: The condition is always false.\nThe time is available as state\n(see Display actions).", + }, + }, + + on_execute = function(data, environ) + environ.state = daytime() + return false + end, + button_label = function(data) + return "RTC" + end, +}) + diff --git a/smartline/controller.lua b/smartline/controller.lua index f2cab0e..81603ac 100644 --- a/smartline/controller.lua +++ b/smartline/controller.lua @@ -265,12 +265,8 @@ local function decrement_timers(timers) end end -local function toggle_flag(environ) - if environ.toggle == true then - environ.toggle = false - else - environ.toggle = true - end +local function toggle_flag(meta, environ) + environ.toggle = (meta:get_int("runtime") or 0) % 4 >= 2 end @@ -564,7 +560,7 @@ local function execute(meta, number, debug) if rt_rules and environ and act_gate and conds then environ.actions = {} decrement_timers(environ.timers) - toggle_flag(environ) + toggle_flag(meta, environ) for i,item in ipairs(rt_rules) do local c1 = eval_cond(item.cond1, environ) local c2 = eval_cond(item.cond2, environ)